From 7980d2624af10142410bc48d1c434295125b3958 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Tue, 20 Jun 2023 00:07:21 +0800 Subject: [PATCH] [go] update @shopify/react-native-skia to 0.1.193 (#22900) # Why update @shopify/react-native-skia vendoring module for sdk 49 # How - [tools] update patch - `et uvm -m @shopify/react-native-skia -c 0.1.193` - backport skia chrome/m114 to sdk47 and sdk48 code. reference changes from https://github.com/Shopify/react-native-skia/pull/1604 # Test Plan - versioned expo go + unversioned ncl skia - versioned expo go + sdk 48 ncl skia --- .../react-native-skia/cpp/api/JsiSkImage.h | 29 +- .../cpp/api/JsiSkImageFactory.h | 4 +- .../react-native-skia/cpp/api/JsiSkPath.h | 12 +- .../react-native-skia/cpp/api/JsiSkImage.h | 29 +- .../cpp/api/JsiSkImageFactory.h | 4 +- .../react-native-skia/cpp/api/JsiSkPath.h | 12 +- .../cpp/rnskia/dom/nodes/JsiBlurMaskNode.h | 1 + .../cpp/rnskia/dom/nodes/JsiPathNode.h | 4 +- .../cpp/rnskia/dom/props/BoxShadowProps.h | 2 + .../react-native-skia/android/CMakeLists.txt | 13 +- .../react-native-skia/android/build.gradle | 59 +- .../android/cpp/jni/JniPlatformContext.cpp | 95 +- .../cpp/jni/include/JniPlatformContext.h | 4 + .../RNSkAndroidPlatformContext.h | 13 + .../cpp/rnskia-android/SkiaOpenGLRenderer.cpp | 111 +- .../cpp/rnskia-android/SkiaOpenGLRenderer.h | 4 +- .../reactnative/skia/PlatformContext.java | 18 +- .../reactnative/skia/RNSkiaModule.java | 2 +- .../skia/ViewScreenshotService.java | 180 +++ .../cpp/api/JsiSkColorFilter.h | 19 +- .../cpp/api/JsiSkContourMeasure.h | 20 +- .../cpp/api/JsiSkContourMeasureIter.h | 21 +- .../react-native-skia/cpp/api/JsiSkData.h | 14 +- .../react-native-skia/cpp/api/JsiSkFont.h | 20 +- .../cpp/api/JsiSkHostObjects.h | 97 +- .../react-native-skia/cpp/api/JsiSkImage.h | 51 +- .../cpp/api/JsiSkImageFactory.h | 33 +- .../cpp/api/JsiSkImageFilter.h | 18 +- .../cpp/api/JsiSkMaskFilter.h | 18 +- .../react-native-skia/cpp/api/JsiSkMatrix.h | 21 +- .../react-native-skia/cpp/api/JsiSkPaint.h | 32 +- .../react-native-skia/cpp/api/JsiSkPath.h | 31 +- .../cpp/api/JsiSkPathEffect.h | 19 +- .../cpp/api/JsiSkPathFactory.h | 2 +- .../react-native-skia/cpp/api/JsiSkPicture.h | 26 +- .../cpp/api/JsiSkPictureRecorder.h | 5 +- .../react-native-skia/cpp/api/JsiSkPoint.h | 7 +- .../react-native-skia/cpp/api/JsiSkRRect.h | 7 +- .../react-native-skia/cpp/api/JsiSkRSXform.h | 10 +- .../react-native-skia/cpp/api/JsiSkRect.h | 8 +- .../cpp/api/JsiSkRuntimeEffect.h | 17 +- .../cpp/api/JsiSkRuntimeShaderBuilder.h | 12 +- .../react-native-skia/cpp/api/JsiSkSVG.h | 16 +- .../react-native-skia/cpp/api/JsiSkShader.h | 20 +- .../react-native-skia/cpp/api/JsiSkSurface.h | 31 +- .../cpp/api/JsiSkSurfaceFactory.h | 19 +- .../react-native-skia/cpp/api/JsiSkTextBlob.h | 20 +- .../react-native-skia/cpp/api/JsiSkTypeface.h | 20 +- .../react-native-skia/cpp/api/JsiSkVertices.h | 20 +- .../cpp/jsi/JsiHostObject.cpp | 20 +- .../react-native-skia/cpp/jsi/JsiHostObject.h | 4 +- .../cpp/jsi/RuntimeAwareCache.cpp | 7 + .../cpp/jsi/RuntimeAwareCache.h | 101 ++ .../cpp/jsi/RuntimeLifecycleMonitor.cpp | 57 + .../cpp/jsi/RuntimeLifecycleMonitor.h | 32 + .../cpp/rnskia/RNSkAnimation.h | 6 +- .../cpp/rnskia/RNSkDomView.cpp | 10 +- .../cpp/rnskia/RNSkDomView.h | 18 +- .../cpp/rnskia/RNSkInfoParameter.h | 4 +- .../cpp/rnskia/RNSkJsView.cpp | 5 +- .../react-native-skia/cpp/rnskia/RNSkJsView.h | 16 +- .../cpp/rnskia/RNSkJsiViewApi.h | 10 +- .../cpp/rnskia/RNSkManager.cpp | 4 + .../cpp/rnskia/RNSkPictureView.h | 17 +- .../cpp/rnskia/RNSkPlatformContext.h | 40 +- .../cpp/rnskia/RNSkValueApi.h | 10 +- .../react-native-skia/cpp/rnskia/RNSkView.h | 26 +- .../cpp/rnskia/dom/JsiDomApi.h | 1 + .../cpp/rnskia/dom/base/ConcatablePaint.cpp | 117 ++ .../cpp/rnskia/dom/base/ConcatablePaint.h | 49 + .../cpp/rnskia/dom/base/Declaration.h | 86 ++ .../cpp/rnskia/dom/base/DeclarationContext.h | 79 ++ .../cpp/rnskia/dom/base/DerivedNodeProp.h | 34 +- .../cpp/rnskia/dom/base/DrawingContext.cpp | 218 +--- .../cpp/rnskia/dom/base/DrawingContext.h | 113 +- .../rnskia/dom/base/JsiDependencyManager.h | 110 +- .../rnskia/dom/base/JsiDomDeclarationNode.h | 141 +-- .../cpp/rnskia/dom/base/JsiDomDrawingNode.h | 37 +- .../cpp/rnskia/dom/base/JsiDomNode.h | 281 +++-- .../cpp/rnskia/dom/base/JsiDomRenderNode.h | 158 ++- .../cpp/rnskia/dom/base/NodeProp.h | 24 +- .../cpp/rnskia/dom/base/NodePropsContainer.h | 73 +- .../rnskia/dom/nodes/JsiBackdropFilterNode.h | 33 +- .../cpp/rnskia/dom/nodes/JsiBlendNode.h | 102 +- .../cpp/rnskia/dom/nodes/JsiBlurMaskNode.h | 36 +- .../cpp/rnskia/dom/nodes/JsiBoxShadowNode.h | 11 +- .../rnskia/dom/nodes/JsiColorFilterNodes.h | 116 +- .../cpp/rnskia/dom/nodes/JsiGlyphsNode.h | 15 +- .../cpp/rnskia/dom/nodes/JsiGroupNode.h | 2 +- .../rnskia/dom/nodes/JsiImageFilterNodes.h | 282 ++--- .../cpp/rnskia/dom/nodes/JsiImageNode.h | 8 +- .../cpp/rnskia/dom/nodes/JsiImageSvgNode.h | 39 +- .../cpp/rnskia/dom/nodes/JsiLayerNode.h | 46 +- .../cpp/rnskia/dom/nodes/JsiPaintNode.h | 127 +- .../cpp/rnskia/dom/nodes/JsiPathEffectNodes.h | 171 +-- .../cpp/rnskia/dom/nodes/JsiPathNode.h | 33 +- .../cpp/rnskia/dom/nodes/JsiPointsNode.h | 2 +- .../cpp/rnskia/dom/nodes/JsiShaderNodes.h | 363 +++--- .../cpp/rnskia/dom/nodes/JsiTextNode.h | 9 +- .../cpp/rnskia/dom/nodes/JsiTextPathNode.h | 4 +- .../cpp/rnskia/dom/props/BezierProps.h | 6 +- .../cpp/rnskia/dom/props/BlendModeProp.h | 8 +- .../cpp/rnskia/dom/props/BoxShadowProps.h | 20 +- .../cpp/rnskia/dom/props/CircleProp.h | 13 +- .../cpp/rnskia/dom/props/ClipProp.h | 39 +- .../cpp/rnskia/dom/props/ColorProp.h | 19 +- .../cpp/rnskia/dom/props/DrawingProp.h | 8 +- .../cpp/rnskia/dom/props/FontProp.h | 31 +- .../cpp/rnskia/dom/props/GlyphsProp.h | 6 +- .../cpp/rnskia/dom/props/ImageProps.h | 61 +- .../cpp/rnskia/dom/props/LayerProp.h | 10 +- .../cpp/rnskia/dom/props/MatrixProp.h | 6 +- .../cpp/rnskia/dom/props/NumbersProp.h | 12 +- .../cpp/rnskia/dom/props/PaintProps.h | 149 +-- .../cpp/rnskia/dom/props/PathProp.h | 38 +- .../cpp/rnskia/dom/props/PictureProp.h | 6 +- .../cpp/rnskia/dom/props/PointProp.h | 10 +- .../cpp/rnskia/dom/props/PointsProp.h | 14 +- .../cpp/rnskia/dom/props/RRectProp.h | 143 +-- .../cpp/rnskia/dom/props/RadiusProp.h | 8 +- .../cpp/rnskia/dom/props/RectProp.h | 84 +- .../cpp/rnskia/dom/props/StrokeProps.h | 14 +- .../cpp/rnskia/dom/props/SvgProp.h | 36 +- .../cpp/rnskia/dom/props/TextBlobProp.h | 137 +- .../cpp/rnskia/dom/props/TileModeProp.h | 8 +- .../cpp/rnskia/dom/props/TransformProp.h | 6 +- .../cpp/rnskia/dom/props/TransformsProps.h | 12 +- .../cpp/rnskia/dom/props/UniformsProp.h | 8 +- .../cpp/rnskia/dom/props/VertexModeProp.h | 8 +- .../cpp/rnskia/dom/props/VerticesProps.h | 20 +- .../cpp/rnskia/values/RNSkClockValue.h | 4 +- .../cpp/rnskia/values/RNSkComputedValue.h | 2 +- .../cpp/rnskia/values/RNSkReadonlyValue.h | 10 +- .../cpp/rnskia/values/RNSkValue.h | 10 +- .../include/android/SkAndroidFrameworkUtils.h | 10 +- .../cpp/skia/include/android/SkImageAndroid.h | 101 ++ .../cpp/skia/include/codec/SkAndroidCodec.h | 34 +- .../cpp/skia/include/codec/SkCodec.h | 48 +- .../skia/include/codec/SkEncodedImageFormat.h | 36 + .../cpp/skia/include/codec/SkPixmapUtils.h | 31 + .../{core => codec}/SkPngChunkReader.h | 0 .../cpp/skia/include/config/SkUserConfig.h | 90 +- .../cpp/skia/include/core/SkBitmap.h | 50 +- .../cpp/skia/include/core/SkBlurTypes.h | 2 - .../cpp/skia/include/core/SkCanvas.h | 47 +- .../cpp/skia/include/core/SkCapabilities.h | 4 +- .../cpp/skia/include/core/SkColor.h | 2 + .../cpp/skia/include/core/SkColorPriv.h | 23 +- .../cpp/skia/include/core/SkColorSpace.h | 31 +- .../cpp/skia/include/core/SkColorType.h | 1 + .../cpp/skia/include/core/SkContourMeasure.h | 2 +- .../cpp/skia/include/core/SkCoverageMode.h | 2 - .../cpp/skia/include/core/SkCubicMap.h | 2 + .../cpp/skia/include/core/SkData.h | 7 +- .../cpp/skia/include/core/SkDataTable.h | 8 +- .../skia/include/core/SkDeferredDisplayList.h | 21 +- .../core/SkDeferredDisplayListRecorder.h | 17 +- .../cpp/skia/include/core/SkDrawable.h | 12 +- .../skia/include/core/SkEncodedImageFormat.h | 33 +- .../cpp/skia/include/core/SkFlattenable.h | 6 +- .../cpp/skia/include/core/SkFont.h | 1 + .../cpp/skia/include/core/SkFontMetrics.h | 1 + .../cpp/skia/include/core/SkFontMgr.h | 49 +- .../cpp/skia/include/core/SkFontStyle.h | 5 +- .../cpp/skia/include/core/SkGraphics.h | 39 +- .../cpp/skia/include/core/SkICC.h | 16 +- .../cpp/skia/include/core/SkImage.h | 1112 ++++++----------- .../cpp/skia/include/core/SkImageEncoder.h | 71 -- .../cpp/skia/include/core/SkImageGenerator.h | 93 +- .../cpp/skia/include/core/SkImageInfo.h | 12 +- .../cpp/skia/include/core/SkM44.h | 11 + .../cpp/skia/include/core/SkMaskFilter.h | 9 +- .../cpp/skia/include/core/SkMatrix.h | 18 +- .../cpp/skia/include/core/SkMesh.h | 70 +- .../cpp/skia/include/core/SkMilestone.h | 2 +- .../cpp/skia/include/core/SkPaint.h | 45 +- .../cpp/skia/include/core/SkPath.h | 27 +- .../cpp/skia/include/core/SkPathBuilder.h | 18 +- .../cpp/skia/include/core/SkPathMeasure.h | 2 +- .../cpp/skia/include/core/SkPathTypes.h | 2 - .../cpp/skia/include/core/SkPathUtils.h | 42 + .../cpp/skia/include/core/SkPicture.h | 5 +- .../cpp/skia/include/core/SkPictureRecorder.h | 2 + .../cpp/skia/include/core/SkPixelRef.h | 12 +- .../cpp/skia/include/core/SkPixmap.h | 32 +- .../cpp/skia/include/core/SkPoint.h | 6 +- .../skia/include/core/SkPromiseImageTexture.h | 4 +- .../cpp/skia/include/core/SkRRect.h | 6 +- .../cpp/skia/include/core/SkRect.h | 9 +- .../cpp/skia/include/core/SkRefCnt.h | 23 +- .../cpp/skia/include/core/SkRegion.h | 2 +- .../cpp/skia/include/core/SkScalar.h | 6 +- .../cpp/skia/include/core/SkSerialProcs.h | 28 +- .../cpp/skia/include/core/SkShader.h | 65 +- .../cpp/skia/include/core/SkSize.h | 2 + .../cpp/skia/include/core/SkSpan.h | 116 +- .../cpp/skia/include/core/SkStream.h | 23 +- .../cpp/skia/include/core/SkString.h | 34 +- .../cpp/skia/include/core/SkStrokeRec.h | 2 +- .../cpp/skia/include/core/SkSurface.h | 144 ++- .../include/core/SkSurfaceCharacterization.h | 6 +- .../cpp/skia/include/core/SkSurfaceProps.h | 10 +- .../cpp/skia/include/core/SkTextBlob.h | 4 +- .../include/core/SkTextureCompressionType.h | 30 + .../cpp/skia/include/core/SkTime.h | 2 +- .../cpp/skia/include/core/SkTypeface.h | 11 +- .../cpp/skia/include/core/SkTypes.h | 503 +------- .../cpp/skia/include/core/SkVertices.h | 2 + .../cpp/skia/include/core/SkYUVAInfo.h | 4 + .../cpp/skia/include/core/SkYUVAPixmaps.h | 8 +- .../cpp/skia/include/docs/SkPDFDocument.h | 13 +- .../cpp/skia/include/effects/SkColorMatrix.h | 3 +- .../skia/include/effects/SkGradientShader.h | 79 +- .../cpp/skia/include/effects/SkImageFilters.h | 11 - .../skia/include/effects/SkRuntimeEffect.h | 52 +- .../cpp/skia/include/encode/SkEncoder.h | 10 +- .../cpp/skia/include/encode/SkICC.h | 36 + .../cpp/skia/include/encode/SkJpegEncoder.h | 173 +-- .../cpp/skia/include/encode/SkPngEncoder.h | 160 +-- .../cpp/skia/include/encode/SkWebpEncoder.h | 103 +- .../cpp/skia/include/gpu/GpuTypes.h | 24 +- .../cpp/skia/include/gpu/GrBackendSurface.h | 16 +- .../cpp/skia/include/gpu/GrConfig.h | 53 - .../cpp/skia/include/gpu/GrContextOptions.h | 37 +- .../include/gpu/GrContextThreadSafeProxy.h | 10 +- .../cpp/skia/include/gpu/GrDirectContext.h | 147 ++- .../skia/include/gpu/GrDriverBugWorkarounds.h | 3 +- .../cpp/skia/include/gpu/GrRecordingContext.h | 14 +- .../cpp/skia/include/gpu/GrTypes.h | 36 +- .../cpp/skia/include/gpu/d3d/GrD3DTypes.h | 8 +- .../cpp/skia/include/gpu/dawn/GrDawnTypes.h | 6 +- .../include/gpu/ganesh/GrTextureGenerator.h | 77 ++ .../skia/include/gpu/ganesh/SkImageGanesh.h | 385 ++++++ .../cpp/skia/include/gpu/gl/GrGLExtensions.h | 6 +- .../cpp/skia/include/gpu/gl/GrGLFunctions.h | 2 +- .../cpp/skia/include/gpu/gl/GrGLInterface.h | 3 - .../cpp/skia/include/gpu/gl/GrGLTypes.h | 3 +- .../include/gpu/graphite/BackendTexture.h | 75 +- .../include/gpu/graphite/CombinationBuilder.h | 195 --- .../cpp/skia/include/gpu/graphite/Context.h | 117 +- .../include/gpu/graphite/ContextOptions.h | 26 +- .../skia/include/gpu/graphite/GraphiteTypes.h | 60 +- .../skia/include/gpu/graphite/ImageProvider.h | 10 +- .../cpp/skia/include/gpu/graphite/Recorder.h | 52 +- .../cpp/skia/include/gpu/graphite/Recording.h | 53 +- .../skia/include/gpu/graphite/TextureInfo.h | 55 +- .../gpu/graphite/YUVABackendTextures.h | 139 +++ .../include/gpu/graphite/dawn/DawnTypes.h | 40 + .../include/gpu/graphite/dawn/DawnUtils.h | 28 + .../gpu/graphite/mtl/MtlBackendContext.h | 2 +- .../gpu/graphite/mtl/MtlGraphiteTypes.h | 13 +- .../gpu/graphite/mtl/MtlGraphiteUtils.h | 27 + .../gpu/graphite/vk/VulkanGraphiteTypes.h | 13 +- .../gpu/graphite/vk/VulkanGraphiteUtils.h | 28 + .../cpp/skia/include/gpu/mock/GrMockTypes.h | 30 +- .../cpp/skia/include/gpu/mtl/GrMtlTypes.h | 4 +- .../skia/include/gpu/vk/GrVkBackendContext.h | 2 +- .../cpp/skia/include/gpu/vk/GrVkTypes.h | 6 +- .../skia/include/gpu/vk/VulkanExtensions.h | 6 +- .../include/gpu/vk/VulkanMemoryAllocator.h | 12 +- .../cpp/skia/include/pathops/SkPathOps.h | 6 +- .../cpp/skia/include/ports/SkFontMgr_data.h | 22 + .../skia/include/ports/SkFontMgr_indirect.h | 28 +- .../skia/include/ports/SkRemotableFontMgr.h | 4 +- .../cpp/skia/include/ports/SkTypeface_win.h | 3 +- .../cpp/skia/include/private/SkChecksum.h | 39 +- .../cpp/skia/include/private/SkColorData.h | 27 +- .../cpp/skia/include/private/SkGainmapInfo.h | 97 ++ .../skia/include/private/SkGainmapShader.h | 53 + .../cpp/skia/include/private/SkHalf.h | 38 - .../skia/include/private/SkIDChangeListener.h | 7 +- .../skia/include/private/SkImageInfoPriv.h | 199 --- .../include/private/SkJpegGainmapEncoder.h | 71 ++ .../include/private/SkJpegMetadataDecoder.h | 61 + .../cpp/skia/include/private/SkOpts_spi.h | 4 +- .../cpp/skia/include/private/SkPathRef.h | 111 +- .../cpp/skia/include/private/SkSLDefines.h | 10 +- .../cpp/skia/include/private/SkSLIRNode.h | 64 - .../cpp/skia/include/private/SkSLLayout.h | 144 --- .../cpp/skia/include/private/SkSLModifiers.h | 178 --- .../skia/include/private/SkSLProgramElement.h | 77 -- .../skia/include/private/SkSLProgramKind.h | 35 - .../skia/include/private/SkSLSampleUsage.h | 4 - .../cpp/skia/include/private/SkSLStatement.h | 86 -- .../cpp/skia/include/private/SkSLString.h | 41 - .../cpp/skia/include/private/SkSLSymbol.h | 94 -- .../cpp/skia/include/private/SkSafe_math.h | 52 - .../cpp/skia/include/private/SkSpinlock.h | 2 +- .../cpp/skia/include/private/SkStringView.h | 51 - .../cpp/skia/include/private/SkTArray.h | 655 ---------- .../include/private/SkUniquePaintParamsID.h | 35 - .../cpp/skia/include/private/SkVx.h | 1026 --------------- .../cpp/skia/include/private/SkWeakRefCnt.h | 3 + .../include/private/{ => base}/SingleOwner.h | 13 +- .../cpp/skia/include/private/base/SkAPI.h | 52 + .../cpp/skia/include/private/base/SkAlign.h | 39 + .../include/private/base/SkAlignedStorage.h | 32 + .../cpp/skia/include/private/base/SkAssert.h | 92 ++ .../skia/include/private/base/SkAttributes.h | 102 ++ .../skia/include/private/base/SkCPUTypes.h | 25 + .../skia/include/private/base/SkContainers.h | 46 + .../cpp/skia/include/private/base/SkDebug.h | 27 + .../skia/include/private/{ => base}/SkDeque.h | 4 +- .../skia/include/private/base/SkFeatures.h | 151 +++ .../cpp/skia/include/private/base}/SkFixed.h | 16 +- .../include/private/{ => base}/SkFloatBits.h | 5 +- .../include/private/base}/SkFloatingPoint.h | 27 +- .../include/private/base/SkLoadUserConfig.h | 63 + .../include/private/{ => base}/SkMacros.h | 19 +- .../cpp/skia/include/private/base}/SkMalloc.h | 11 +- .../cpp/skia/include/private/base}/SkMath.h | 27 +- .../cpp/skia/include/private/base}/SkMutex.h | 10 +- .../include/private/base}/SkNoncopyable.h | 4 +- .../skia/include/private/{ => base}/SkOnce.h | 4 +- .../skia/include/private/base/SkPathEnums.h | 25 + .../cpp/skia/include/private/base}/SkSafe32.h | 17 +- .../skia/include/private/base}/SkSemaphore.h | 7 +- .../skia/include/private/base/SkSpan_impl.h | 129 ++ .../cpp/skia/include/private/base/SkTArray.h | 694 ++++++++++ .../skia/include/private/base}/SkTDArray.h | 71 +- .../skia/include/private/base}/SkTFitsIn.h | 22 +- .../cpp/skia/include/private/base}/SkTLogic.h | 2 +- .../skia/include/private/{ => base}/SkTPin.h | 0 .../include/private/{ => base}/SkTemplates.h | 151 +-- .../private/{ => base}/SkThreadAnnotations.h | 0 .../skia/include/private/base}/SkThreadID.h | 7 +- .../cpp/skia/include/private/base}/SkTo.h | 15 +- .../skia/include/private/base/SkTypeTraits.h | 33 + .../chromium/GrVkSecondaryCBDrawContext.h | 130 ++ .../chromium/SkChromeRemoteGlyphCache.h | 14 +- .../private/chromium/SkDiscardableMemory.h | 70 ++ .../cpp/skia/include/private/chromium/Slug.h | 9 - .../private/gpu/ganesh/GrContext_Base.h | 3 +- .../private/gpu/ganesh/GrD3DTypesMinimal.h | 2 +- .../private/gpu/ganesh/GrDawnTypesPriv.h | 2 +- .../private/gpu/ganesh/GrGLTypesPriv.h | 2 +- .../private/gpu/ganesh/GrImageContext.h | 2 +- .../private/gpu/ganesh/GrMockTypesPriv.h | 5 +- .../private/gpu/ganesh/GrMtlTypesPriv.h | 2 +- .../include/private/gpu/ganesh/GrTypesPriv.h | 40 +- .../private/gpu/ganesh/GrVkTypesPriv.h | 4 +- .../private/gpu/graphite/DawnTypesPriv.h | 38 + .../gpu/graphite/MtlGraphiteTypesPriv.h | 10 +- .../gpu/graphite/VulkanGraphiteTypesPriv.h | 10 +- .../skia/include/private/gpu/vk/SkiaVulkan.h | 4 + .../cpp/skia/include/sksl/DSL.h | 37 - .../cpp/skia/include/sksl/DSLBlock.h | 58 - .../cpp/skia/include/sksl/DSLCase.h | 62 - .../cpp/skia/include/sksl/DSLCore.h | 492 -------- .../cpp/skia/include/sksl/DSLExpression.h | 241 ---- .../cpp/skia/include/sksl/DSLFunction.h | 113 -- .../cpp/skia/include/sksl/DSLLayout.h | 92 -- .../cpp/skia/include/sksl/DSLModifiers.h | 69 - .../cpp/skia/include/sksl/DSLStatement.h | 82 -- .../cpp/skia/include/sksl/DSLSymbols.h | 61 - .../cpp/skia/include/sksl/DSLType.h | 271 ---- .../cpp/skia/include/sksl/DSLVar.h | 231 ---- .../cpp/skia/include/sksl/SkSLErrorReporter.h | 65 - .../cpp/skia/include/sksl/SkSLOperator.h | 154 --- .../cpp/skia/include/sksl/SkSLPosition.h | 104 -- .../cpp/skia/include/utils/SkCamera.h | 2 +- .../cpp/skia/include/utils/SkCustomTypeface.h | 8 +- .../cpp/skia/include/utils/SkNWayCanvas.h | 12 +- .../cpp/skia/include/utils/SkOrderedFontMgr.h | 13 +- .../skia/include/utils/SkPaintFilterCanvas.h | 4 +- .../cpp/skia/include/utils/SkParsePath.h | 2 +- .../cpp/skia/include/utils/SkRandom.h | 169 --- .../cpp/skia/modules/skcms/skcms.h | 14 + .../skia/modules/skcms/src/Transform_inl.h | 19 + .../skparagraph/include/FontCollection.h | 4 +- .../modules/skparagraph/include/Paragraph.h | 74 +- .../skparagraph/include/ParagraphCache.h | 12 +- .../skparagraph/include/ParagraphPainter.h | 63 + .../modules/skparagraph/include/TextStyle.h | 31 +- .../include/TypefaceFontProvider.h | 26 +- .../modules/skresources/include/SkResources.h | 22 +- .../skia/modules/svg/include/SkSVGAttribute.h | 2 +- .../svg/include/SkSVGAttributeParser.h | 4 +- .../skia/modules/svg/include/SkSVGContainer.h | 4 +- .../cpp/skia/modules/svg/include/SkSVGDOM.h | 2 +- .../modules/svg/include/SkSVGFilterContext.h | 4 +- .../skia/modules/svg/include/SkSVGGradient.h | 4 +- .../skia/modules/svg/include/SkSVGIDMapper.h | 4 +- .../modules/svg/include/SkSVGRenderContext.h | 6 +- .../cpp/skia/modules/svg/include/SkSVGSVG.h | 2 +- .../cpp/skia/modules/svg/include/SkSVGTypes.h | 43 +- .../cpp/skia/modules/svg/include/SkSVGValue.h | 2 +- .../cpp/skia/src/core/SkLRUCache.h | 126 -- .../cpp/skia/src/core}/SkTHash.h | 78 +- .../cpp/skia/src/core/SkTInternalLList.h | 302 ----- .../cpp/utils/RNSkMeasureTime.h | 2 +- .../cpp/utils/RNSkTimingInfo.h | 2 +- apps/native-component-list/package.json | 2 +- ios/Podfile.lock | 33 +- .../ABI47_0_0react-native-skia.podspec.json | 4 +- .../react-native-skia/cpp/api/JsiSkImage.h | 30 +- .../cpp/api/JsiSkImageFactory.h | 4 +- .../react-native-skia/cpp/api/JsiSkPath.h | 12 +- .../include/android/SkAndroidFrameworkUtils.h | 10 +- .../cpp/skia/include/android/SkImageAndroid.h | 101 ++ .../cpp/skia/include/codec/SkAndroidCodec.h | 34 +- .../cpp/skia/include/codec/SkCodec.h | 48 +- .../skia/include/codec/SkEncodedImageFormat.h | 36 + .../cpp/skia/include/codec/SkPixmapUtils.h | 31 + .../{core => codec}/SkPngChunkReader.h | 0 .../cpp/skia/include/config/SkUserConfig.h | 90 +- .../cpp/skia/include/core/SkBitmap.h | 50 +- .../cpp/skia/include/core/SkBlurTypes.h | 2 - .../cpp/skia/include/core/SkCanvas.h | 47 +- .../cpp/skia/include/core/SkCapabilities.h | 4 +- .../cpp/skia/include/core/SkColor.h | 2 + .../cpp/skia/include/core/SkColorPriv.h | 23 +- .../cpp/skia/include/core/SkColorSpace.h | 31 +- .../cpp/skia/include/core/SkColorType.h | 1 + .../cpp/skia/include/core/SkContourMeasure.h | 2 +- .../cpp/skia/include/core/SkCoverageMode.h | 2 - .../cpp/skia/include/core/SkCubicMap.h | 2 + .../cpp/skia/include/core/SkData.h | 7 +- .../cpp/skia/include/core/SkDataTable.h | 8 +- .../skia/include/core/SkDeferredDisplayList.h | 21 +- .../core/SkDeferredDisplayListRecorder.h | 17 +- .../cpp/skia/include/core/SkDrawable.h | 12 +- .../skia/include/core/SkEncodedImageFormat.h | 33 +- .../cpp/skia/include/core/SkFlattenable.h | 6 +- .../cpp/skia/include/core/SkFont.h | 1 + .../cpp/skia/include/core/SkFontMetrics.h | 1 + .../cpp/skia/include/core/SkFontMgr.h | 49 +- .../cpp/skia/include/core/SkFontStyle.h | 5 +- .../cpp/skia/include/core/SkGraphics.h | 39 +- .../cpp/skia/include/core/SkICC.h | 16 +- .../cpp/skia/include/core/SkImage.h | 1112 ++++++----------- .../cpp/skia/include/core/SkImageEncoder.h | 71 -- .../cpp/skia/include/core/SkImageGenerator.h | 93 +- .../cpp/skia/include/core/SkImageInfo.h | 12 +- .../cpp/skia/include/core/SkM44.h | 11 + .../cpp/skia/include/core/SkMaskFilter.h | 9 +- .../cpp/skia/include/core/SkMatrix.h | 18 +- .../cpp/skia/include/core/SkMesh.h | 70 +- .../cpp/skia/include/core/SkMilestone.h | 2 +- .../cpp/skia/include/core/SkPaint.h | 45 +- .../cpp/skia/include/core/SkPath.h | 27 +- .../cpp/skia/include/core/SkPathBuilder.h | 18 +- .../cpp/skia/include/core/SkPathMeasure.h | 2 +- .../cpp/skia/include/core/SkPathTypes.h | 2 - .../cpp/skia/include/core/SkPathUtils.h | 42 + .../cpp/skia/include/core/SkPicture.h | 5 +- .../cpp/skia/include/core/SkPictureRecorder.h | 2 + .../cpp/skia/include/core/SkPixelRef.h | 12 +- .../cpp/skia/include/core/SkPixmap.h | 32 +- .../cpp/skia/include/core/SkPoint.h | 6 +- .../skia/include/core/SkPromiseImageTexture.h | 4 +- .../cpp/skia/include/core/SkRRect.h | 6 +- .../cpp/skia/include/core/SkRect.h | 9 +- .../cpp/skia/include/core/SkRefCnt.h | 23 +- .../cpp/skia/include/core/SkRegion.h | 2 +- .../cpp/skia/include/core/SkScalar.h | 6 +- .../cpp/skia/include/core/SkSerialProcs.h | 28 +- .../cpp/skia/include/core/SkShader.h | 65 +- .../cpp/skia/include/core/SkSize.h | 2 + .../cpp/skia/include/core/SkSpan.h | 116 +- .../cpp/skia/include/core/SkStream.h | 23 +- .../cpp/skia/include/core/SkString.h | 34 +- .../cpp/skia/include/core/SkStrokeRec.h | 2 +- .../cpp/skia/include/core/SkSurface.h | 144 ++- .../include/core/SkSurfaceCharacterization.h | 6 +- .../cpp/skia/include/core/SkSurfaceProps.h | 10 +- .../cpp/skia/include/core/SkTextBlob.h | 4 +- .../include/core/SkTextureCompressionType.h | 30 + .../cpp/skia/include/core/SkTime.h | 2 +- .../cpp/skia/include/core/SkTypeface.h | 11 +- .../cpp/skia/include/core/SkTypes.h | 503 +------- .../cpp/skia/include/core/SkVertices.h | 2 + .../cpp/skia/include/core/SkYUVAInfo.h | 4 + .../cpp/skia/include/core/SkYUVAPixmaps.h | 8 +- .../cpp/skia/include/docs/SkPDFDocument.h | 13 +- .../cpp/skia/include/effects/SkColorMatrix.h | 3 +- .../skia/include/effects/SkGradientShader.h | 79 +- .../cpp/skia/include/effects/SkImageFilters.h | 11 - .../skia/include/effects/SkRuntimeEffect.h | 52 +- .../cpp/skia/include/encode/SkEncoder.h | 10 +- .../cpp/skia/include/encode/SkICC.h | 36 + .../cpp/skia/include/encode/SkJpegEncoder.h | 173 +-- .../cpp/skia/include/encode/SkPngEncoder.h | 160 +-- .../cpp/skia/include/encode/SkWebpEncoder.h | 103 +- .../cpp/skia/include/gpu/GpuTypes.h | 24 +- .../cpp/skia/include/gpu/GrBackendSurface.h | 16 +- .../cpp/skia/include/gpu/GrConfig.h | 53 - .../cpp/skia/include/gpu/GrContextOptions.h | 37 +- .../include/gpu/GrContextThreadSafeProxy.h | 10 +- .../cpp/skia/include/gpu/GrDirectContext.h | 147 ++- .../skia/include/gpu/GrDriverBugWorkarounds.h | 3 +- .../cpp/skia/include/gpu/GrRecordingContext.h | 14 +- .../cpp/skia/include/gpu/GrTypes.h | 36 +- .../cpp/skia/include/gpu/d3d/GrD3DTypes.h | 8 +- .../cpp/skia/include/gpu/dawn/GrDawnTypes.h | 6 +- .../include/gpu/ganesh/GrTextureGenerator.h | 77 ++ .../skia/include/gpu/ganesh/SkImageGanesh.h | 385 ++++++ .../cpp/skia/include/gpu/gl/GrGLExtensions.h | 6 +- .../cpp/skia/include/gpu/gl/GrGLFunctions.h | 2 +- .../cpp/skia/include/gpu/gl/GrGLInterface.h | 3 - .../cpp/skia/include/gpu/gl/GrGLTypes.h | 3 +- .../include/gpu/graphite/BackendTexture.h | 75 +- .../include/gpu/graphite/CombinationBuilder.h | 195 --- .../cpp/skia/include/gpu/graphite/Context.h | 117 +- .../include/gpu/graphite/ContextOptions.h | 26 +- .../skia/include/gpu/graphite/GraphiteTypes.h | 60 +- .../skia/include/gpu/graphite/ImageProvider.h | 10 +- .../cpp/skia/include/gpu/graphite/Recorder.h | 52 +- .../cpp/skia/include/gpu/graphite/Recording.h | 53 +- .../skia/include/gpu/graphite/TextureInfo.h | 55 +- .../gpu/graphite/YUVABackendTextures.h | 139 +++ .../include/gpu/graphite/dawn/DawnTypes.h | 40 + .../include/gpu/graphite/dawn/DawnUtils.h | 28 + .../gpu/graphite/mtl/MtlBackendContext.h | 2 +- .../gpu/graphite/mtl/MtlGraphiteTypes.h} | 13 +- .../gpu/graphite/mtl/MtlGraphiteUtils.h | 27 + .../gpu/graphite/vk/VulkanGraphiteTypes.h | 13 +- .../gpu/graphite/vk/VulkanGraphiteUtils.h | 28 + .../cpp/skia/include/gpu/mock/GrMockTypes.h | 30 +- .../cpp/skia/include/gpu/mtl/GrMtlTypes.h | 4 +- .../skia/include/gpu/vk/GrVkBackendContext.h | 2 +- .../cpp/skia/include/gpu/vk/GrVkTypes.h | 6 +- .../skia/include/gpu/vk/VulkanExtensions.h | 6 +- .../include/gpu/vk/VulkanMemoryAllocator.h | 12 +- .../cpp/skia/include/pathops/SkPathOps.h | 6 +- .../cpp/skia/include/ports/SkFontMgr_data.h | 22 + .../skia/include/ports/SkFontMgr_indirect.h | 28 +- .../skia/include/ports/SkRemotableFontMgr.h | 4 +- .../cpp/skia/include/ports/SkTypeface_win.h | 3 +- .../cpp/skia/include/private/SkChecksum.h | 39 +- .../cpp/skia/include/private/SkColorData.h | 27 +- .../cpp/skia/include/private/SkGainmapInfo.h | 97 ++ .../skia/include/private/SkGainmapShader.h | 53 + .../cpp/skia/include/private/SkHalf.h | 38 - .../skia/include/private/SkIDChangeListener.h | 7 +- .../skia/include/private/SkImageInfoPriv.h | 199 --- .../include/private/SkJpegGainmapEncoder.h | 71 ++ .../include/private/SkJpegMetadataDecoder.h | 61 + .../cpp/skia/include/private/SkOpts_spi.h | 4 +- .../cpp/skia/include/private/SkPathRef.h | 111 +- .../cpp/skia/include/private/SkSLDefines.h | 10 +- .../cpp/skia/include/private/SkSLIRNode.h | 64 - .../cpp/skia/include/private/SkSLLayout.h | 144 --- .../cpp/skia/include/private/SkSLModifiers.h | 178 --- .../skia/include/private/SkSLProgramElement.h | 77 -- .../skia/include/private/SkSLProgramKind.h | 35 - .../skia/include/private/SkSLSampleUsage.h | 4 - .../cpp/skia/include/private/SkSLStatement.h | 86 -- .../cpp/skia/include/private/SkSLString.h | 41 - .../cpp/skia/include/private/SkSLSymbol.h | 94 -- .../cpp/skia/include/private/SkSafe_math.h | 52 - .../cpp/skia/include/private/SkSpinlock.h | 2 +- .../cpp/skia/include/private/SkStringView.h | 51 - .../cpp/skia/include/private/SkTArray.h | 655 ---------- .../include/private/SkUniquePaintParamsID.h | 35 - .../cpp/skia/include/private/SkVx.h | 1026 --------------- .../cpp/skia/include/private/SkWeakRefCnt.h | 3 + .../include/private/{ => base}/SingleOwner.h | 13 +- .../cpp/skia/include/private/base/SkAPI.h | 52 + .../cpp/skia/include/private/base/SkAlign.h | 39 + .../include/private/base/SkAlignedStorage.h | 32 + .../cpp/skia/include/private/base/SkAssert.h | 92 ++ .../skia/include/private/base/SkAttributes.h | 102 ++ .../skia/include/private/base/SkCPUTypes.h | 25 + .../skia/include/private/base/SkContainers.h | 46 + .../cpp/skia/include/private/base/SkDebug.h | 27 + .../skia/include/private/{ => base}/SkDeque.h | 4 +- .../skia/include/private/base/SkFeatures.h | 151 +++ .../cpp/skia/include/private/base}/SkFixed.h | 16 +- .../include/private/{ => base}/SkFloatBits.h | 5 +- .../include/private/base}/SkFloatingPoint.h | 27 +- .../include/private/base/SkLoadUserConfig.h | 63 + .../include/private/{ => base}/SkMacros.h | 19 +- .../include/private/{ => base}/SkMalloc.h | 11 +- .../cpp/skia/include/private/base}/SkMath.h | 27 +- .../skia/include/private/{ => base}/SkMutex.h | 10 +- .../include/private/base}/SkNoncopyable.h | 4 +- .../cpp/skia/include/private/base}/SkOnce.h | 4 +- .../skia/include/private/base/SkPathEnums.h | 25 + .../cpp/skia/include/private/base}/SkSafe32.h | 17 +- .../include/private/{ => base}/SkSemaphore.h | 7 +- .../skia/include/private/base/SkSpan_impl.h | 129 ++ .../cpp/skia/include/private/base/SkTArray.h | 694 ++++++++++ .../include/private/{ => base}/SkTDArray.h | 71 +- .../skia/include/private/base}/SkTFitsIn.h | 22 +- .../cpp/skia/include/private/base}/SkTLogic.h | 2 +- .../skia/include/private/{ => base}/SkTPin.h | 0 .../include/private/{ => base}/SkTemplates.h | 151 +-- .../private/{ => base}/SkThreadAnnotations.h | 0 .../skia/include/private/base}/SkThreadID.h | 7 +- .../cpp/skia/include/private/base}/SkTo.h | 15 +- .../skia/include/private/base/SkTypeTraits.h | 33 + .../chromium/GrVkSecondaryCBDrawContext.h | 130 ++ .../chromium/SkChromeRemoteGlyphCache.h | 14 +- .../private/chromium/SkDiscardableMemory.h | 70 ++ .../cpp/skia/include/private/chromium/Slug.h | 9 - .../private/gpu/ganesh/GrContext_Base.h | 3 +- .../private/gpu/ganesh/GrD3DTypesMinimal.h | 2 +- .../private/gpu/ganesh/GrDawnTypesPriv.h | 2 +- .../private/gpu/ganesh/GrGLTypesPriv.h | 2 +- .../private/gpu/ganesh/GrImageContext.h | 2 +- .../private/gpu/ganesh/GrMockTypesPriv.h | 5 +- .../private/gpu/ganesh/GrMtlTypesPriv.h | 2 +- .../include/private/gpu/ganesh/GrTypesPriv.h | 40 +- .../private/gpu/ganesh/GrVkTypesPriv.h | 4 +- .../private/gpu/graphite/DawnTypesPriv.h | 38 + ...{MtlTypesPriv.h => MtlGraphiteTypesPriv.h} | 10 +- .../gpu/graphite/VulkanGraphiteTypesPriv.h | 10 +- .../skia/include/private/gpu/vk/SkiaVulkan.h | 4 + .../cpp/skia/include/sksl/DSL.h | 37 - .../cpp/skia/include/sksl/DSLBlock.h | 58 - .../cpp/skia/include/sksl/DSLCase.h | 62 - .../cpp/skia/include/sksl/DSLCore.h | 492 -------- .../cpp/skia/include/sksl/DSLExpression.h | 241 ---- .../cpp/skia/include/sksl/DSLFunction.h | 113 -- .../cpp/skia/include/sksl/DSLLayout.h | 92 -- .../cpp/skia/include/sksl/DSLModifiers.h | 69 - .../cpp/skia/include/sksl/DSLStatement.h | 82 -- .../cpp/skia/include/sksl/DSLSymbols.h | 61 - .../cpp/skia/include/sksl/DSLType.h | 271 ---- .../cpp/skia/include/sksl/DSLVar.h | 231 ---- .../cpp/skia/include/sksl/SkSLErrorReporter.h | 65 - .../cpp/skia/include/sksl/SkSLOperator.h | 154 --- .../cpp/skia/include/sksl/SkSLPosition.h | 104 -- .../cpp/skia/include/utils/SkCamera.h | 2 +- .../cpp/skia/include/utils/SkCustomTypeface.h | 8 +- .../cpp/skia/include/utils/SkNWayCanvas.h | 12 +- .../cpp/skia/include/utils/SkOrderedFontMgr.h | 13 +- .../skia/include/utils/SkPaintFilterCanvas.h | 4 +- .../cpp/skia/include/utils/SkParsePath.h | 2 +- .../cpp/skia/include/utils/SkRandom.h | 169 --- .../cpp/skia/modules/skcms/skcms.h | 14 + .../skia/modules/skcms/src/Transform_inl.h | 19 + .../skparagraph/include/FontCollection.h | 4 +- .../modules/skparagraph/include/Paragraph.h | 74 +- .../skparagraph/include/ParagraphCache.h | 12 +- .../skparagraph/include/ParagraphPainter.h | 63 + .../modules/skparagraph/include/TextStyle.h | 31 +- .../include/TypefaceFontProvider.h | 26 +- .../modules/skresources/include/SkResources.h | 22 +- .../skia/modules/svg/include/SkSVGAttribute.h | 2 +- .../svg/include/SkSVGAttributeParser.h | 4 +- .../skia/modules/svg/include/SkSVGContainer.h | 4 +- .../cpp/skia/modules/svg/include/SkSVGDOM.h | 2 +- .../modules/svg/include/SkSVGFilterContext.h | 4 +- .../skia/modules/svg/include/SkSVGGradient.h | 4 +- .../skia/modules/svg/include/SkSVGIDMapper.h | 4 +- .../modules/svg/include/SkSVGRenderContext.h | 6 +- .../cpp/skia/modules/svg/include/SkSVGSVG.h | 2 +- .../cpp/skia/modules/svg/include/SkSVGTypes.h | 43 +- .../cpp/skia/modules/svg/include/SkSVGValue.h | 2 +- .../cpp/skia/src/core/SkLRUCache.h | 126 -- .../cpp/skia/src/core}/SkTHash.h | 78 +- .../cpp/skia/src/core/SkTInternalLList.h | 302 ----- .../ABI48_0_0react-native-skia.podspec.json | 4 +- .../react-native-skia/cpp/api/JsiSkImage.h | 29 +- .../cpp/api/JsiSkImageFactory.h | 4 +- .../react-native-skia/cpp/api/JsiSkPath.h | 12 +- .../cpp/rnskia/dom/nodes/JsiBlurMaskNode.h | 1 + .../cpp/rnskia/dom/nodes/JsiPathNode.h | 4 +- .../cpp/rnskia/dom/props/BoxShadowProps.h | 2 + .../include/android/SkAndroidFrameworkUtils.h | 10 +- .../cpp/skia/include/android/SkImageAndroid.h | 101 ++ .../cpp/skia/include/codec/SkAndroidCodec.h | 34 +- .../cpp/skia/include/codec/SkCodec.h | 48 +- .../skia/include/codec/SkEncodedImageFormat.h | 36 + .../cpp/skia/include/codec/SkPixmapUtils.h | 31 + .../{core => codec}/SkPngChunkReader.h | 0 .../cpp/skia/include/config/SkUserConfig.h | 90 +- .../cpp/skia/include/core/SkBitmap.h | 50 +- .../cpp/skia/include/core/SkBlurTypes.h | 2 - .../cpp/skia/include/core/SkCanvas.h | 47 +- .../cpp/skia/include/core/SkCapabilities.h | 4 +- .../cpp/skia/include/core/SkColor.h | 2 + .../cpp/skia/include/core/SkColorPriv.h | 23 +- .../cpp/skia/include/core/SkColorSpace.h | 31 +- .../cpp/skia/include/core/SkColorType.h | 1 + .../cpp/skia/include/core/SkContourMeasure.h | 2 +- .../cpp/skia/include/core/SkCoverageMode.h | 2 - .../cpp/skia/include/core/SkCubicMap.h | 2 + .../cpp/skia/include/core/SkData.h | 7 +- .../cpp/skia/include/core/SkDataTable.h | 8 +- .../skia/include/core/SkDeferredDisplayList.h | 21 +- .../core/SkDeferredDisplayListRecorder.h | 17 +- .../cpp/skia/include/core/SkDrawable.h | 12 +- .../skia/include/core/SkEncodedImageFormat.h | 33 +- .../cpp/skia/include/core/SkFlattenable.h | 6 +- .../cpp/skia/include/core/SkFont.h | 1 + .../cpp/skia/include/core/SkFontMetrics.h | 1 + .../cpp/skia/include/core/SkFontMgr.h | 49 +- .../cpp/skia/include/core/SkFontStyle.h | 5 +- .../cpp/skia/include/core/SkGraphics.h | 39 +- .../cpp/skia/include/core/SkICC.h | 16 +- .../cpp/skia/include/core/SkImage.h | 1112 ++++++----------- .../cpp/skia/include/core/SkImageEncoder.h | 71 -- .../cpp/skia/include/core/SkImageGenerator.h | 93 +- .../cpp/skia/include/core/SkImageInfo.h | 12 +- .../cpp/skia/include/core/SkM44.h | 11 + .../cpp/skia/include/core/SkMaskFilter.h | 9 +- .../cpp/skia/include/core/SkMatrix.h | 18 +- .../cpp/skia/include/core/SkMesh.h | 70 +- .../cpp/skia/include/core/SkMilestone.h | 2 +- .../cpp/skia/include/core/SkPaint.h | 45 +- .../cpp/skia/include/core/SkPath.h | 27 +- .../cpp/skia/include/core/SkPathBuilder.h | 18 +- .../cpp/skia/include/core/SkPathMeasure.h | 2 +- .../cpp/skia/include/core/SkPathTypes.h | 2 - .../cpp/skia/include/core/SkPathUtils.h | 42 + .../cpp/skia/include/core/SkPicture.h | 5 +- .../cpp/skia/include/core/SkPictureRecorder.h | 2 + .../cpp/skia/include/core/SkPixelRef.h | 12 +- .../cpp/skia/include/core/SkPixmap.h | 32 +- .../cpp/skia/include/core/SkPoint.h | 6 +- .../skia/include/core/SkPromiseImageTexture.h | 4 +- .../cpp/skia/include/core/SkRRect.h | 6 +- .../cpp/skia/include/core/SkRect.h | 9 +- .../cpp/skia/include/core/SkRefCnt.h | 23 +- .../cpp/skia/include/core/SkRegion.h | 2 +- .../cpp/skia/include/core/SkScalar.h | 6 +- .../cpp/skia/include/core/SkSerialProcs.h | 28 +- .../cpp/skia/include/core/SkShader.h | 65 +- .../cpp/skia/include/core/SkSize.h | 2 + .../cpp/skia/include/core/SkSpan.h | 116 +- .../cpp/skia/include/core/SkStream.h | 23 +- .../cpp/skia/include/core/SkString.h | 34 +- .../cpp/skia/include/core/SkStrokeRec.h | 2 +- .../cpp/skia/include/core/SkSurface.h | 144 ++- .../include/core/SkSurfaceCharacterization.h | 6 +- .../cpp/skia/include/core/SkSurfaceProps.h | 10 +- .../cpp/skia/include/core/SkTextBlob.h | 4 +- .../include/core/SkTextureCompressionType.h | 30 + .../cpp/skia/include/core/SkTime.h | 2 +- .../cpp/skia/include/core/SkTypeface.h | 11 +- .../cpp/skia/include/core/SkTypes.h | 503 +------- .../cpp/skia/include/core/SkVertices.h | 2 + .../cpp/skia/include/core/SkYUVAInfo.h | 4 + .../cpp/skia/include/core/SkYUVAPixmaps.h | 8 +- .../cpp/skia/include/docs/SkPDFDocument.h | 13 +- .../cpp/skia/include/effects/SkColorMatrix.h | 3 +- .../skia/include/effects/SkGradientShader.h | 79 +- .../cpp/skia/include/effects/SkImageFilters.h | 11 - .../skia/include/effects/SkRuntimeEffect.h | 52 +- .../cpp/skia/include/encode/SkEncoder.h | 10 +- .../cpp/skia/include/encode/SkICC.h | 36 + .../cpp/skia/include/encode/SkJpegEncoder.h | 173 +-- .../cpp/skia/include/encode/SkPngEncoder.h | 160 +-- .../cpp/skia/include/encode/SkWebpEncoder.h | 103 +- .../cpp/skia/include/gpu/GpuTypes.h | 24 +- .../cpp/skia/include/gpu/GrBackendSurface.h | 16 +- .../cpp/skia/include/gpu/GrConfig.h | 53 - .../cpp/skia/include/gpu/GrContextOptions.h | 37 +- .../include/gpu/GrContextThreadSafeProxy.h | 10 +- .../cpp/skia/include/gpu/GrDirectContext.h | 147 ++- .../skia/include/gpu/GrDriverBugWorkarounds.h | 3 +- .../cpp/skia/include/gpu/GrRecordingContext.h | 14 +- .../cpp/skia/include/gpu/GrTypes.h | 36 +- .../cpp/skia/include/gpu/d3d/GrD3DTypes.h | 8 +- .../cpp/skia/include/gpu/dawn/GrDawnTypes.h | 6 +- .../include/gpu/ganesh/GrTextureGenerator.h | 77 ++ .../skia/include/gpu/ganesh/SkImageGanesh.h | 385 ++++++ .../cpp/skia/include/gpu/gl/GrGLExtensions.h | 6 +- .../cpp/skia/include/gpu/gl/GrGLFunctions.h | 2 +- .../cpp/skia/include/gpu/gl/GrGLInterface.h | 3 - .../cpp/skia/include/gpu/gl/GrGLTypes.h | 3 +- .../include/gpu/graphite/BackendTexture.h | 75 +- .../include/gpu/graphite/CombinationBuilder.h | 195 --- .../cpp/skia/include/gpu/graphite/Context.h | 117 +- .../include/gpu/graphite/ContextOptions.h | 26 +- .../skia/include/gpu/graphite/GraphiteTypes.h | 60 +- .../skia/include/gpu/graphite/ImageProvider.h | 10 +- .../cpp/skia/include/gpu/graphite/Recorder.h | 52 +- .../cpp/skia/include/gpu/graphite/Recording.h | 53 +- .../skia/include/gpu/graphite/TextureInfo.h | 55 +- .../gpu/graphite/YUVABackendTextures.h | 139 +++ .../include/gpu/graphite/dawn/DawnTypes.h | 40 + .../include/gpu/graphite/dawn/DawnUtils.h | 28 + .../gpu/graphite/mtl/MtlBackendContext.h | 2 +- .../gpu/graphite/mtl/MtlGraphiteTypes.h} | 13 +- .../gpu/graphite/mtl/MtlGraphiteUtils.h | 27 + .../gpu/graphite/vk/VulkanGraphiteTypes.h | 13 +- .../gpu/graphite/vk/VulkanGraphiteUtils.h | 28 + .../cpp/skia/include/gpu/mock/GrMockTypes.h | 30 +- .../cpp/skia/include/gpu/mtl/GrMtlTypes.h | 4 +- .../skia/include/gpu/vk/GrVkBackendContext.h | 2 +- .../cpp/skia/include/gpu/vk/GrVkTypes.h | 6 +- .../skia/include/gpu/vk/VulkanExtensions.h | 6 +- .../include/gpu/vk/VulkanMemoryAllocator.h | 12 +- .../cpp/skia/include/pathops/SkPathOps.h | 6 +- .../cpp/skia/include/ports/SkFontMgr_data.h | 22 + .../skia/include/ports/SkFontMgr_indirect.h | 28 +- .../skia/include/ports/SkRemotableFontMgr.h | 4 +- .../cpp/skia/include/ports/SkTypeface_win.h | 3 +- .../cpp/skia/include/private/SkChecksum.h | 39 +- .../cpp/skia/include/private/SkColorData.h | 27 +- .../cpp/skia/include/private/SkGainmapInfo.h | 97 ++ .../skia/include/private/SkGainmapShader.h | 53 + .../cpp/skia/include/private/SkHalf.h | 38 - .../skia/include/private/SkIDChangeListener.h | 7 +- .../skia/include/private/SkImageInfoPriv.h | 199 --- .../include/private/SkJpegGainmapEncoder.h | 71 ++ .../include/private/SkJpegMetadataDecoder.h | 61 + .../cpp/skia/include/private/SkOpts_spi.h | 4 +- .../cpp/skia/include/private/SkPathRef.h | 111 +- .../cpp/skia/include/private/SkSLDefines.h | 10 +- .../cpp/skia/include/private/SkSLIRNode.h | 64 - .../cpp/skia/include/private/SkSLLayout.h | 144 --- .../cpp/skia/include/private/SkSLModifiers.h | 178 --- .../skia/include/private/SkSLProgramElement.h | 77 -- .../skia/include/private/SkSLProgramKind.h | 35 - .../skia/include/private/SkSLSampleUsage.h | 4 - .../cpp/skia/include/private/SkSLStatement.h | 86 -- .../cpp/skia/include/private/SkSLString.h | 41 - .../cpp/skia/include/private/SkSLSymbol.h | 94 -- .../cpp/skia/include/private/SkSafe_math.h | 52 - .../cpp/skia/include/private/SkSpinlock.h | 2 +- .../cpp/skia/include/private/SkStringView.h | 51 - .../cpp/skia/include/private/SkTArray.h | 655 ---------- .../include/private/SkUniquePaintParamsID.h | 35 - .../cpp/skia/include/private/SkVx.h | 1026 --------------- .../cpp/skia/include/private/SkWeakRefCnt.h | 3 + .../include/private/{ => base}/SingleOwner.h | 13 +- .../cpp/skia/include/private/base/SkAPI.h | 52 + .../cpp/skia/include/private/base/SkAlign.h | 39 + .../include/private/base/SkAlignedStorage.h | 32 + .../cpp/skia/include/private/base/SkAssert.h | 92 ++ .../skia/include/private/base/SkAttributes.h | 102 ++ .../skia/include/private/base/SkCPUTypes.h | 25 + .../skia/include/private/base/SkContainers.h | 46 + .../cpp/skia/include/private/base/SkDebug.h | 27 + .../skia/include/private/{ => base}/SkDeque.h | 4 +- .../skia/include/private/base/SkFeatures.h | 151 +++ .../skia/include/private/{ => base}/SkFixed.h | 16 +- .../include/private/{ => base}/SkFloatBits.h | 5 +- .../private/{ => base}/SkFloatingPoint.h | 27 +- .../include/private/base/SkLoadUserConfig.h | 63 + .../include/private/{ => base}/SkMacros.h | 19 +- .../cpp/skia/include/private/base}/SkMalloc.h | 11 +- .../cpp/skia/include/private/base}/SkMath.h | 27 +- .../cpp/skia/include/private/base}/SkMutex.h | 10 +- .../include/private/base}/SkNoncopyable.h | 4 +- .../cpp/skia/include/private/base}/SkOnce.h | 4 +- .../skia/include/private/base/SkPathEnums.h | 25 + .../cpp/skia/include/private/base}/SkSafe32.h | 17 +- .../skia/include/private/base}/SkSemaphore.h | 7 +- .../skia/include/private/base/SkSpan_impl.h | 129 ++ .../cpp/skia/include/private/base/SkTArray.h | 694 ++++++++++ .../skia/include/private/base}/SkTDArray.h | 71 +- .../include/private/{ => base}/SkTFitsIn.h | 22 +- .../cpp/skia/include/private/base}/SkTLogic.h | 2 +- .../skia/include/private/{ => base}/SkTPin.h | 0 .../include/private/{ => base}/SkTemplates.h | 151 +-- .../private/{ => base}/SkThreadAnnotations.h | 0 .../skia/include/private/base}/SkThreadID.h | 7 +- .../cpp/skia/include/private/base}/SkTo.h | 15 +- .../skia/include/private/base/SkTypeTraits.h | 33 + .../chromium/GrVkSecondaryCBDrawContext.h | 130 ++ .../chromium/SkChromeRemoteGlyphCache.h | 14 +- .../private/chromium/SkDiscardableMemory.h | 70 ++ .../cpp/skia/include/private/chromium/Slug.h | 9 - .../private/gpu/ganesh/GrContext_Base.h | 3 +- .../private/gpu/ganesh/GrD3DTypesMinimal.h | 2 +- .../private/gpu/ganesh/GrDawnTypesPriv.h | 2 +- .../private/gpu/ganesh/GrGLTypesPriv.h | 2 +- .../private/gpu/ganesh/GrImageContext.h | 2 +- .../private/gpu/ganesh/GrMockTypesPriv.h | 5 +- .../private/gpu/ganesh/GrMtlTypesPriv.h | 2 +- .../include/private/gpu/ganesh/GrTypesPriv.h | 40 +- .../private/gpu/ganesh/GrVkTypesPriv.h | 4 +- .../private/gpu/graphite/DawnTypesPriv.h | 38 + .../gpu/graphite/MtlGraphiteTypesPriv.h | 10 +- .../gpu/graphite/VulkanGraphiteTypesPriv.h | 10 +- .../skia/include/private/gpu/vk/SkiaVulkan.h | 4 + .../cpp/skia/include/sksl/DSL.h | 37 - .../cpp/skia/include/sksl/DSLBlock.h | 58 - .../cpp/skia/include/sksl/DSLCase.h | 62 - .../cpp/skia/include/sksl/DSLCore.h | 492 -------- .../cpp/skia/include/sksl/DSLExpression.h | 241 ---- .../cpp/skia/include/sksl/DSLFunction.h | 113 -- .../cpp/skia/include/sksl/DSLLayout.h | 92 -- .../cpp/skia/include/sksl/DSLModifiers.h | 69 - .../cpp/skia/include/sksl/DSLStatement.h | 82 -- .../cpp/skia/include/sksl/DSLSymbols.h | 61 - .../cpp/skia/include/sksl/DSLType.h | 271 ---- .../cpp/skia/include/sksl/DSLVar.h | 231 ---- .../cpp/skia/include/sksl/SkSLErrorReporter.h | 65 - .../cpp/skia/include/sksl/SkSLOperator.h | 154 --- .../cpp/skia/include/sksl/SkSLPosition.h | 104 -- .../cpp/skia/include/utils/SkCamera.h | 2 +- .../cpp/skia/include/utils/SkCustomTypeface.h | 8 +- .../cpp/skia/include/utils/SkNWayCanvas.h | 12 +- .../cpp/skia/include/utils/SkOrderedFontMgr.h | 13 +- .../skia/include/utils/SkPaintFilterCanvas.h | 4 +- .../cpp/skia/include/utils/SkParsePath.h | 2 +- .../cpp/skia/include/utils/SkRandom.h | 169 --- .../cpp/skia/modules/skcms/skcms.h | 14 + .../skia/modules/skcms/src/Transform_inl.h | 19 + .../skparagraph/include/FontCollection.h | 4 +- .../modules/skparagraph/include/Paragraph.h | 74 +- .../skparagraph/include/ParagraphCache.h | 12 +- .../skparagraph/include/ParagraphPainter.h | 63 + .../modules/skparagraph/include/TextStyle.h | 31 +- .../include/TypefaceFontProvider.h | 26 +- .../modules/skresources/include/SkResources.h | 22 +- .../skia/modules/svg/include/SkSVGAttribute.h | 2 +- .../svg/include/SkSVGAttributeParser.h | 4 +- .../skia/modules/svg/include/SkSVGContainer.h | 4 +- .../cpp/skia/modules/svg/include/SkSVGDOM.h | 2 +- .../modules/svg/include/SkSVGFilterContext.h | 4 +- .../skia/modules/svg/include/SkSVGGradient.h | 4 +- .../skia/modules/svg/include/SkSVGIDMapper.h | 4 +- .../modules/svg/include/SkSVGRenderContext.h | 6 +- .../cpp/skia/modules/svg/include/SkSVGSVG.h | 2 +- .../cpp/skia/modules/svg/include/SkSVGTypes.h | 43 +- .../cpp/skia/modules/svg/include/SkSVGValue.h | 2 +- .../cpp/skia/src/core/SkLRUCache.h | 126 -- .../cpp/skia/src/core}/SkTHash.h | 78 +- .../cpp/skia/src/core/SkTInternalLList.h | 302 ----- .../cpp/api/JsiSkColorFilter.h | 19 +- .../cpp/api/JsiSkContourMeasure.h | 20 +- .../cpp/api/JsiSkContourMeasureIter.h | 21 +- .../react-native-skia/cpp/api/JsiSkData.h | 14 +- .../react-native-skia/cpp/api/JsiSkFont.h | 20 +- .../cpp/api/JsiSkHostObjects.h | 97 +- .../react-native-skia/cpp/api/JsiSkImage.h | 51 +- .../cpp/api/JsiSkImageFactory.h | 33 +- .../cpp/api/JsiSkImageFilter.h | 18 +- .../cpp/api/JsiSkMaskFilter.h | 18 +- .../react-native-skia/cpp/api/JsiSkMatrix.h | 21 +- .../react-native-skia/cpp/api/JsiSkPaint.h | 32 +- .../react-native-skia/cpp/api/JsiSkPath.h | 31 +- .../cpp/api/JsiSkPathEffect.h | 19 +- .../cpp/api/JsiSkPathFactory.h | 2 +- .../react-native-skia/cpp/api/JsiSkPicture.h | 26 +- .../cpp/api/JsiSkPictureRecorder.h | 5 +- .../react-native-skia/cpp/api/JsiSkPoint.h | 7 +- .../react-native-skia/cpp/api/JsiSkRRect.h | 7 +- .../react-native-skia/cpp/api/JsiSkRSXform.h | 10 +- .../react-native-skia/cpp/api/JsiSkRect.h | 8 +- .../cpp/api/JsiSkRuntimeEffect.h | 17 +- .../cpp/api/JsiSkRuntimeShaderBuilder.h | 12 +- .../react-native-skia/cpp/api/JsiSkSVG.h | 16 +- .../react-native-skia/cpp/api/JsiSkShader.h | 20 +- .../react-native-skia/cpp/api/JsiSkSurface.h | 31 +- .../cpp/api/JsiSkSurfaceFactory.h | 19 +- .../react-native-skia/cpp/api/JsiSkTextBlob.h | 20 +- .../react-native-skia/cpp/api/JsiSkTypeface.h | 20 +- .../react-native-skia/cpp/api/JsiSkVertices.h | 20 +- .../cpp/jsi/JsiHostObject.cpp | 20 +- .../react-native-skia/cpp/jsi/JsiHostObject.h | 4 +- .../cpp/jsi/RuntimeAwareCache.cpp | 7 + .../cpp/jsi/RuntimeAwareCache.h | 101 ++ .../cpp/jsi/RuntimeLifecycleMonitor.cpp | 57 + .../cpp/jsi/RuntimeLifecycleMonitor.h | 32 + .../cpp/rnskia/RNSkAnimation.h | 6 +- .../cpp/rnskia/RNSkDomView.cpp | 10 +- .../cpp/rnskia/RNSkDomView.h | 18 +- .../cpp/rnskia/RNSkInfoParameter.h | 4 +- .../cpp/rnskia/RNSkJsView.cpp | 5 +- .../react-native-skia/cpp/rnskia/RNSkJsView.h | 16 +- .../cpp/rnskia/RNSkJsiViewApi.h | 10 +- .../cpp/rnskia/RNSkManager.cpp | 4 + .../cpp/rnskia/RNSkPictureView.h | 17 +- .../cpp/rnskia/RNSkPlatformContext.h | 40 +- .../cpp/rnskia/RNSkValueApi.h | 10 +- .../react-native-skia/cpp/rnskia/RNSkView.h | 26 +- .../cpp/rnskia/dom/JsiDomApi.h | 1 + .../cpp/rnskia/dom/base/ConcatablePaint.cpp | 117 ++ .../cpp/rnskia/dom/base/ConcatablePaint.h | 49 + .../cpp/rnskia/dom/base/Declaration.h | 86 ++ .../cpp/rnskia/dom/base/DeclarationContext.h | 79 ++ .../cpp/rnskia/dom/base/DerivedNodeProp.h | 34 +- .../cpp/rnskia/dom/base/DrawingContext.cpp | 218 +--- .../cpp/rnskia/dom/base/DrawingContext.h | 113 +- .../rnskia/dom/base/JsiDependencyManager.h | 110 +- .../rnskia/dom/base/JsiDomDeclarationNode.h | 141 +-- .../cpp/rnskia/dom/base/JsiDomDrawingNode.h | 37 +- .../cpp/rnskia/dom/base/JsiDomNode.h | 281 +++-- .../cpp/rnskia/dom/base/JsiDomRenderNode.h | 158 ++- .../cpp/rnskia/dom/base/NodeProp.h | 24 +- .../cpp/rnskia/dom/base/NodePropsContainer.h | 73 +- .../rnskia/dom/nodes/JsiBackdropFilterNode.h | 33 +- .../cpp/rnskia/dom/nodes/JsiBlendNode.h | 102 +- .../cpp/rnskia/dom/nodes/JsiBlurMaskNode.h | 36 +- .../cpp/rnskia/dom/nodes/JsiBoxShadowNode.h | 11 +- .../rnskia/dom/nodes/JsiColorFilterNodes.h | 116 +- .../cpp/rnskia/dom/nodes/JsiGlyphsNode.h | 15 +- .../cpp/rnskia/dom/nodes/JsiGroupNode.h | 2 +- .../rnskia/dom/nodes/JsiImageFilterNodes.h | 282 ++--- .../cpp/rnskia/dom/nodes/JsiImageNode.h | 8 +- .../cpp/rnskia/dom/nodes/JsiImageSvgNode.h | 39 +- .../cpp/rnskia/dom/nodes/JsiLayerNode.h | 46 +- .../cpp/rnskia/dom/nodes/JsiPaintNode.h | 127 +- .../cpp/rnskia/dom/nodes/JsiPathEffectNodes.h | 171 +-- .../cpp/rnskia/dom/nodes/JsiPathNode.h | 33 +- .../cpp/rnskia/dom/nodes/JsiPointsNode.h | 2 +- .../cpp/rnskia/dom/nodes/JsiShaderNodes.h | 363 +++--- .../cpp/rnskia/dom/nodes/JsiTextNode.h | 9 +- .../cpp/rnskia/dom/nodes/JsiTextPathNode.h | 4 +- .../cpp/rnskia/dom/props/BezierProps.h | 6 +- .../cpp/rnskia/dom/props/BlendModeProp.h | 8 +- .../cpp/rnskia/dom/props/BoxShadowProps.h | 20 +- .../cpp/rnskia/dom/props/CircleProp.h | 13 +- .../cpp/rnskia/dom/props/ClipProp.h | 39 +- .../cpp/rnskia/dom/props/ColorProp.h | 19 +- .../cpp/rnskia/dom/props/DrawingProp.h | 8 +- .../cpp/rnskia/dom/props/FontProp.h | 31 +- .../cpp/rnskia/dom/props/GlyphsProp.h | 6 +- .../cpp/rnskia/dom/props/ImageProps.h | 61 +- .../cpp/rnskia/dom/props/LayerProp.h | 10 +- .../cpp/rnskia/dom/props/MatrixProp.h | 6 +- .../cpp/rnskia/dom/props/NumbersProp.h | 12 +- .../cpp/rnskia/dom/props/PaintProps.h | 149 +-- .../cpp/rnskia/dom/props/PathProp.h | 38 +- .../cpp/rnskia/dom/props/PictureProp.h | 6 +- .../cpp/rnskia/dom/props/PointProp.h | 10 +- .../cpp/rnskia/dom/props/PointsProp.h | 14 +- .../cpp/rnskia/dom/props/RRectProp.h | 143 +-- .../cpp/rnskia/dom/props/RadiusProp.h | 8 +- .../cpp/rnskia/dom/props/RectProp.h | 84 +- .../cpp/rnskia/dom/props/StrokeProps.h | 14 +- .../cpp/rnskia/dom/props/SvgProp.h | 36 +- .../cpp/rnskia/dom/props/TextBlobProp.h | 137 +- .../cpp/rnskia/dom/props/TileModeProp.h | 8 +- .../cpp/rnskia/dom/props/TransformProp.h | 6 +- .../cpp/rnskia/dom/props/TransformsProps.h | 12 +- .../cpp/rnskia/dom/props/UniformsProp.h | 8 +- .../cpp/rnskia/dom/props/VertexModeProp.h | 8 +- .../cpp/rnskia/dom/props/VerticesProps.h | 20 +- .../cpp/rnskia/values/RNSkClockValue.h | 4 +- .../cpp/rnskia/values/RNSkComputedValue.h | 2 +- .../cpp/rnskia/values/RNSkReadonlyValue.h | 10 +- .../cpp/rnskia/values/RNSkValue.h | 10 +- .../include/android/SkAndroidFrameworkUtils.h | 10 +- .../cpp/skia/include/android/SkImageAndroid.h | 101 ++ .../cpp/skia/include/codec/SkAndroidCodec.h | 34 +- .../cpp/skia/include/codec/SkCodec.h | 48 +- .../skia/include/codec/SkEncodedImageFormat.h | 36 + .../cpp/skia/include/codec/SkPixmapUtils.h | 31 + .../{core => codec}/SkPngChunkReader.h | 0 .../cpp/skia/include/config/SkUserConfig.h | 90 +- .../cpp/skia/include/core/SkBitmap.h | 50 +- .../cpp/skia/include/core/SkBlurTypes.h | 2 - .../cpp/skia/include/core/SkCanvas.h | 47 +- .../cpp/skia/include/core/SkCapabilities.h | 4 +- .../cpp/skia/include/core/SkColor.h | 2 + .../cpp/skia/include/core/SkColorPriv.h | 23 +- .../cpp/skia/include/core/SkColorSpace.h | 31 +- .../cpp/skia/include/core/SkColorType.h | 1 + .../cpp/skia/include/core/SkContourMeasure.h | 2 +- .../cpp/skia/include/core/SkCoverageMode.h | 2 - .../cpp/skia/include/core/SkCubicMap.h | 2 + .../cpp/skia/include/core/SkData.h | 7 +- .../cpp/skia/include/core/SkDataTable.h | 8 +- .../skia/include/core/SkDeferredDisplayList.h | 21 +- .../core/SkDeferredDisplayListRecorder.h | 17 +- .../cpp/skia/include/core/SkDrawable.h | 12 +- .../skia/include/core/SkEncodedImageFormat.h | 33 +- .../cpp/skia/include/core/SkFlattenable.h | 6 +- .../cpp/skia/include/core/SkFont.h | 1 + .../cpp/skia/include/core/SkFontMetrics.h | 1 + .../cpp/skia/include/core/SkFontMgr.h | 49 +- .../cpp/skia/include/core/SkFontStyle.h | 5 +- .../cpp/skia/include/core/SkGraphics.h | 39 +- .../cpp/skia/include/core/SkICC.h | 16 +- .../cpp/skia/include/core/SkImage.h | 1112 ++++++----------- .../cpp/skia/include/core/SkImageEncoder.h | 71 -- .../cpp/skia/include/core/SkImageGenerator.h | 93 +- .../cpp/skia/include/core/SkImageInfo.h | 12 +- .../cpp/skia/include/core/SkM44.h | 11 + .../cpp/skia/include/core/SkMaskFilter.h | 9 +- .../cpp/skia/include/core/SkMatrix.h | 18 +- .../cpp/skia/include/core/SkMesh.h | 70 +- .../cpp/skia/include/core/SkMilestone.h | 2 +- .../cpp/skia/include/core/SkPaint.h | 45 +- .../cpp/skia/include/core/SkPath.h | 27 +- .../cpp/skia/include/core/SkPathBuilder.h | 18 +- .../cpp/skia/include/core/SkPathMeasure.h | 2 +- .../cpp/skia/include/core/SkPathTypes.h | 2 - .../cpp/skia/include/core/SkPathUtils.h | 42 + .../cpp/skia/include/core/SkPicture.h | 5 +- .../cpp/skia/include/core/SkPictureRecorder.h | 2 + .../cpp/skia/include/core/SkPixelRef.h | 12 +- .../cpp/skia/include/core/SkPixmap.h | 32 +- .../cpp/skia/include/core/SkPoint.h | 6 +- .../skia/include/core/SkPromiseImageTexture.h | 4 +- .../cpp/skia/include/core/SkRRect.h | 6 +- .../cpp/skia/include/core/SkRect.h | 9 +- .../cpp/skia/include/core/SkRefCnt.h | 23 +- .../cpp/skia/include/core/SkRegion.h | 2 +- .../cpp/skia/include/core/SkScalar.h | 6 +- .../cpp/skia/include/core/SkSerialProcs.h | 28 +- .../cpp/skia/include/core/SkShader.h | 65 +- .../cpp/skia/include/core/SkSize.h | 2 + .../cpp/skia/include/core/SkSpan.h | 116 +- .../cpp/skia/include/core/SkStream.h | 23 +- .../cpp/skia/include/core/SkString.h | 34 +- .../cpp/skia/include/core/SkStrokeRec.h | 2 +- .../cpp/skia/include/core/SkSurface.h | 144 ++- .../include/core/SkSurfaceCharacterization.h | 6 +- .../cpp/skia/include/core/SkSurfaceProps.h | 10 +- .../cpp/skia/include/core/SkTextBlob.h | 4 +- .../include/core/SkTextureCompressionType.h | 30 + .../cpp/skia/include/core/SkTime.h | 2 +- .../cpp/skia/include/core/SkTypeface.h | 11 +- .../cpp/skia/include/core/SkTypes.h | 503 +------- .../cpp/skia/include/core/SkVertices.h | 2 + .../cpp/skia/include/core/SkYUVAInfo.h | 4 + .../cpp/skia/include/core/SkYUVAPixmaps.h | 8 +- .../cpp/skia/include/docs/SkPDFDocument.h | 13 +- .../cpp/skia/include/effects/SkColorMatrix.h | 3 +- .../skia/include/effects/SkGradientShader.h | 79 +- .../cpp/skia/include/effects/SkImageFilters.h | 11 - .../skia/include/effects/SkRuntimeEffect.h | 52 +- .../cpp/skia/include/encode/SkEncoder.h | 10 +- .../cpp/skia/include/encode/SkICC.h | 36 + .../cpp/skia/include/encode/SkJpegEncoder.h | 173 +-- .../cpp/skia/include/encode/SkPngEncoder.h | 160 +-- .../cpp/skia/include/encode/SkWebpEncoder.h | 103 +- .../cpp/skia/include/gpu/GpuTypes.h | 24 +- .../cpp/skia/include/gpu/GrBackendSurface.h | 16 +- .../cpp/skia/include/gpu/GrConfig.h | 53 - .../cpp/skia/include/gpu/GrContextOptions.h | 37 +- .../include/gpu/GrContextThreadSafeProxy.h | 10 +- .../cpp/skia/include/gpu/GrDirectContext.h | 147 ++- .../skia/include/gpu/GrDriverBugWorkarounds.h | 3 +- .../cpp/skia/include/gpu/GrRecordingContext.h | 14 +- .../cpp/skia/include/gpu/GrTypes.h | 36 +- .../cpp/skia/include/gpu/d3d/GrD3DTypes.h | 8 +- .../cpp/skia/include/gpu/dawn/GrDawnTypes.h | 6 +- .../include/gpu/ganesh/GrTextureGenerator.h | 77 ++ .../skia/include/gpu/ganesh/SkImageGanesh.h | 385 ++++++ .../cpp/skia/include/gpu/gl/GrGLExtensions.h | 6 +- .../cpp/skia/include/gpu/gl/GrGLFunctions.h | 2 +- .../cpp/skia/include/gpu/gl/GrGLInterface.h | 3 - .../cpp/skia/include/gpu/gl/GrGLTypes.h | 3 +- .../include/gpu/graphite/BackendTexture.h | 75 +- .../include/gpu/graphite/CombinationBuilder.h | 195 --- .../cpp/skia/include/gpu/graphite/Context.h | 117 +- .../include/gpu/graphite/ContextOptions.h | 26 +- .../skia/include/gpu/graphite/GraphiteTypes.h | 60 +- .../skia/include/gpu/graphite/ImageProvider.h | 10 +- .../cpp/skia/include/gpu/graphite/Recorder.h | 52 +- .../cpp/skia/include/gpu/graphite/Recording.h | 53 +- .../skia/include/gpu/graphite/TextureInfo.h | 55 +- .../gpu/graphite/YUVABackendTextures.h | 139 +++ .../include/gpu/graphite/dawn/DawnTypes.h | 40 + .../include/gpu/graphite/dawn/DawnUtils.h | 28 + .../gpu/graphite/mtl/MtlBackendContext.h | 2 +- .../gpu/graphite/mtl/MtlGraphiteTypes.h | 13 +- .../gpu/graphite/mtl/MtlGraphiteUtils.h | 27 + .../gpu/graphite/vk/VulkanGraphiteTypes.h | 13 +- .../gpu/graphite/vk/VulkanGraphiteUtils.h | 28 + .../cpp/skia/include/gpu/mock/GrMockTypes.h | 30 +- .../cpp/skia/include/gpu/mtl/GrMtlTypes.h | 4 +- .../skia/include/gpu/vk/GrVkBackendContext.h | 2 +- .../cpp/skia/include/gpu/vk/GrVkTypes.h | 6 +- .../skia/include/gpu/vk/VulkanExtensions.h | 6 +- .../include/gpu/vk/VulkanMemoryAllocator.h | 12 +- .../cpp/skia/include/pathops/SkPathOps.h | 6 +- .../cpp/skia/include/ports/SkFontMgr_data.h | 22 + .../skia/include/ports/SkFontMgr_indirect.h | 28 +- .../skia/include/ports/SkRemotableFontMgr.h | 4 +- .../cpp/skia/include/ports/SkTypeface_win.h | 3 +- .../cpp/skia/include/private/SkChecksum.h | 39 +- .../cpp/skia/include/private/SkColorData.h | 27 +- .../cpp/skia/include/private/SkGainmapInfo.h | 97 ++ .../skia/include/private/SkGainmapShader.h | 53 + .../cpp/skia/include/private/SkHalf.h | 38 - .../skia/include/private/SkIDChangeListener.h | 7 +- .../skia/include/private/SkImageInfoPriv.h | 199 --- .../include/private/SkJpegGainmapEncoder.h | 71 ++ .../include/private/SkJpegMetadataDecoder.h | 61 + .../cpp/skia/include/private/SkOpts_spi.h | 4 +- .../cpp/skia/include/private/SkPathRef.h | 111 +- .../cpp/skia/include/private/SkSLDefines.h | 10 +- .../cpp/skia/include/private/SkSLIRNode.h | 64 - .../cpp/skia/include/private/SkSLLayout.h | 144 --- .../cpp/skia/include/private/SkSLModifiers.h | 178 --- .../skia/include/private/SkSLProgramElement.h | 77 -- .../skia/include/private/SkSLProgramKind.h | 35 - .../skia/include/private/SkSLSampleUsage.h | 4 - .../cpp/skia/include/private/SkSLStatement.h | 86 -- .../cpp/skia/include/private/SkSLString.h | 41 - .../cpp/skia/include/private/SkSLSymbol.h | 94 -- .../cpp/skia/include/private/SkSafe_math.h | 52 - .../cpp/skia/include/private/SkSpinlock.h | 2 +- .../cpp/skia/include/private/SkStringView.h | 51 - .../cpp/skia/include/private/SkTArray.h | 655 ---------- .../include/private/SkUniquePaintParamsID.h | 35 - .../cpp/skia/include/private/SkVx.h | 1026 --------------- .../cpp/skia/include/private/SkWeakRefCnt.h | 3 + .../include/private/{ => base}/SingleOwner.h | 13 +- .../cpp/skia/include/private/base/SkAPI.h | 52 + .../cpp/skia/include/private/base/SkAlign.h | 39 + .../include/private/base/SkAlignedStorage.h | 32 + .../cpp/skia/include/private/base/SkAssert.h | 92 ++ .../skia/include/private/base/SkAttributes.h | 102 ++ .../skia/include/private/base/SkCPUTypes.h | 25 + .../skia/include/private/base/SkContainers.h | 46 + .../cpp/skia/include/private/base/SkDebug.h | 27 + .../skia/include/private/{ => base}/SkDeque.h | 4 +- .../skia/include/private/base/SkFeatures.h | 151 +++ .../skia/include/private/{ => base}/SkFixed.h | 16 +- .../include/private/{ => base}/SkFloatBits.h | 5 +- .../private/{ => base}/SkFloatingPoint.h | 27 +- .../include/private/base/SkLoadUserConfig.h | 63 + .../include/private/{ => base}/SkMacros.h | 19 +- .../cpp/skia/include/private/base}/SkMalloc.h | 11 +- .../cpp/skia/include/private/base}/SkMath.h | 27 +- .../cpp/skia/include/private/base}/SkMutex.h | 10 +- .../include/private/base}/SkNoncopyable.h | 4 +- .../skia/include/private/{ => base}/SkOnce.h | 4 +- .../skia/include/private/base/SkPathEnums.h | 25 + .../cpp/skia/include/private/base}/SkSafe32.h | 17 +- .../skia/include/private/base}/SkSemaphore.h | 7 +- .../skia/include/private/base/SkSpan_impl.h | 129 ++ .../cpp/skia/include/private/base/SkTArray.h | 694 ++++++++++ .../include/private/{ => base}/SkTDArray.h | 71 +- .../include/private/{ => base}/SkTFitsIn.h | 22 +- .../cpp/skia/include/private/base}/SkTLogic.h | 2 +- .../skia/include/private/{ => base}/SkTPin.h | 0 .../include/private/{ => base}/SkTemplates.h | 151 +-- .../private/{ => base}/SkThreadAnnotations.h | 0 .../skia/include/private/base}/SkThreadID.h | 7 +- .../cpp/skia/include/private/base}/SkTo.h | 15 +- .../skia/include/private/base/SkTypeTraits.h | 33 + .../chromium/GrVkSecondaryCBDrawContext.h | 130 ++ .../chromium/SkChromeRemoteGlyphCache.h | 14 +- .../private/chromium/SkDiscardableMemory.h | 70 ++ .../cpp/skia/include/private/chromium/Slug.h | 9 - .../private/gpu/ganesh/GrContext_Base.h | 3 +- .../private/gpu/ganesh/GrD3DTypesMinimal.h | 2 +- .../private/gpu/ganesh/GrDawnTypesPriv.h | 2 +- .../private/gpu/ganesh/GrGLTypesPriv.h | 2 +- .../private/gpu/ganesh/GrImageContext.h | 2 +- .../private/gpu/ganesh/GrMockTypesPriv.h | 5 +- .../private/gpu/ganesh/GrMtlTypesPriv.h | 2 +- .../include/private/gpu/ganesh/GrTypesPriv.h | 40 +- .../private/gpu/ganesh/GrVkTypesPriv.h | 4 +- .../private/gpu/graphite/DawnTypesPriv.h | 38 + ...{MtlTypesPriv.h => MtlGraphiteTypesPriv.h} | 10 +- .../gpu/graphite/VulkanGraphiteTypesPriv.h | 10 +- .../skia/include/private/gpu/vk/SkiaVulkan.h | 4 + .../cpp/skia/include/sksl/DSL.h | 37 - .../cpp/skia/include/sksl/DSLBlock.h | 58 - .../cpp/skia/include/sksl/DSLCase.h | 62 - .../cpp/skia/include/sksl/DSLCore.h | 492 -------- .../cpp/skia/include/sksl/DSLExpression.h | 241 ---- .../cpp/skia/include/sksl/DSLFunction.h | 113 -- .../cpp/skia/include/sksl/DSLLayout.h | 92 -- .../cpp/skia/include/sksl/DSLModifiers.h | 69 - .../cpp/skia/include/sksl/DSLStatement.h | 82 -- .../cpp/skia/include/sksl/DSLSymbols.h | 61 - .../cpp/skia/include/sksl/DSLType.h | 271 ---- .../cpp/skia/include/sksl/DSLVar.h | 231 ---- .../cpp/skia/include/sksl/SkSLErrorReporter.h | 65 - .../cpp/skia/include/sksl/SkSLOperator.h | 154 --- .../cpp/skia/include/sksl/SkSLPosition.h | 104 -- .../cpp/skia/include/utils/SkCamera.h | 2 +- .../cpp/skia/include/utils/SkCustomTypeface.h | 8 +- .../cpp/skia/include/utils/SkNWayCanvas.h | 12 +- .../cpp/skia/include/utils/SkOrderedFontMgr.h | 13 +- .../skia/include/utils/SkPaintFilterCanvas.h | 4 +- .../cpp/skia/include/utils/SkParsePath.h | 2 +- .../cpp/skia/include/utils/SkRandom.h | 169 --- .../cpp/skia/modules/skcms/skcms.h | 14 + .../skia/modules/skcms/src/Transform_inl.h | 19 + .../skparagraph/include/FontCollection.h | 4 +- .../modules/skparagraph/include/Paragraph.h | 74 +- .../skparagraph/include/ParagraphCache.h | 12 +- .../skparagraph/include/ParagraphPainter.h | 63 + .../modules/skparagraph/include/TextStyle.h | 31 +- .../include/TypefaceFontProvider.h | 26 +- .../modules/skresources/include/SkResources.h | 22 +- .../skia/modules/svg/include/SkSVGAttribute.h | 2 +- .../svg/include/SkSVGAttributeParser.h | 4 +- .../skia/modules/svg/include/SkSVGContainer.h | 4 +- .../cpp/skia/modules/svg/include/SkSVGDOM.h | 2 +- .../modules/svg/include/SkSVGFilterContext.h | 4 +- .../skia/modules/svg/include/SkSVGGradient.h | 4 +- .../skia/modules/svg/include/SkSVGIDMapper.h | 4 +- .../modules/svg/include/SkSVGRenderContext.h | 6 +- .../cpp/skia/modules/svg/include/SkSVGSVG.h | 2 +- .../cpp/skia/modules/svg/include/SkSVGTypes.h | 43 +- .../cpp/skia/modules/svg/include/SkSVGValue.h | 2 +- .../cpp/skia/src/core/SkLRUCache.h | 126 -- .../{include/private => src/core}/SkTHash.h | 78 +- .../cpp/skia/src/core/SkTInternalLList.h | 302 ----- .../cpp/utils/RNSkMeasureTime.h | 2 +- .../cpp/utils/RNSkTimingInfo.h | 2 +- .../ios/RNSkia-iOS/DisplayLink.mm | 46 +- .../ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm | 138 +- .../ios/RNSkia-iOS/RNSkiOSPlatformContext.h | 30 +- .../ios/RNSkia-iOS/RNSkiOSPlatformContext.mm | 93 +- .../ios/RNSkia-iOS/SkiaDomViewManager.mm | 34 +- .../ios/RNSkia-iOS/SkiaDrawViewManager.mm | 34 +- .../ios/RNSkia-iOS/SkiaManager.mm | 27 +- .../ios/RNSkia-iOS/SkiaMetalRenderer.h | 5 + .../ios/RNSkia-iOS/SkiaMetalRenderer.mm | 53 + .../ios/RNSkia-iOS/SkiaPictureViewManager.mm | 34 +- .../ios/RNSkia-iOS/SkiaUIView.mm | 116 +- .../ios/RNSkia-iOS/ViewScreenshotService.h | 21 + .../ios/RNSkia-iOS/ViewScreenshotService.mm | 91 ++ .../react-native-skia/ios/RNSkiaModule.mm | 12 +- .../react-native-skia.podspec.json | 40 +- packages/expo/bundledNativeModules.json | 2 +- tools/src/vendoring/config/expoGoConfig.ts | 2 +- .../vendoring/config/react-native-skia.patch | 83 +- yarn.lock | 44 +- 1309 files changed, 30167 insertions(+), 39877 deletions(-) create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.cpp create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.cpp create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.cpp create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/Declaration.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DeclarationContext.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h rename android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/{core => codec}/SkPngChunkReader.h (100%) delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h (85%) create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h rename android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SingleOwner.h (86%) create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h rename android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkDeque.h (98%) create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h rename {ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkFixed.h (94%) rename android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkFloatBits.h (96%) rename {ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkFloatingPoint.h (89%) create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h rename android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkMacros.h (77%) rename {ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkMalloc.h (94%) rename {ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkMath.h (64%) rename {ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkMutex.h (86%) rename {ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkNoncopyable.h (89%) rename android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkOnce.h (96%) create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h rename {ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkSafe32.h (64%) rename {ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkSemaphore.h (95%) create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h rename {ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTDArray.h (81%) rename {ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTFitsIn.h (82%) rename {ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTLogic.h (98%) rename android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTPin.h (100%) rename android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTemplates.h (73%) rename android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkThreadAnnotations.h (100%) rename {ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkThreadID.h (69%) rename {ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTo.h (71%) create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h (87%) delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h create mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h rename {ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private => android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core}/SkTHash.h (89%) delete mode 100644 android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/{core => codec}/SkPngChunkReader.h (100%) delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h rename ios/vendored/{sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h => sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h} (85%) create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SingleOwner.h (86%) create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkDeque.h (98%) create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base}/SkFixed.h (94%) rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkFloatBits.h (96%) rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base}/SkFloatingPoint.h (89%) create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkMacros.h (77%) rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkMalloc.h (94%) rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core => ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base}/SkMath.h (64%) rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkMutex.h (86%) rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base}/SkNoncopyable.h (89%) rename ios/vendored/{sdk48/@shopify/react-native-skia/cpp/skia/include/private => sdk47/@shopify/react-native-skia/cpp/skia/include/private/base}/SkOnce.h (96%) create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base}/SkSafe32.h (64%) rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkSemaphore.h (95%) create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTDArray.h (81%) rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTFitsIn.h (82%) rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTLogic.h (98%) rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTPin.h (100%) rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTemplates.h (73%) rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkThreadAnnotations.h (100%) rename ios/vendored/{unversioned/@shopify/react-native-skia/cpp/skia/include/private => sdk47/@shopify/react-native-skia/cpp/skia/include/private/base}/SkThreadID.h (69%) rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTo.h (71%) create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h rename ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/{MtlTypesPriv.h => MtlGraphiteTypesPriv.h} (87%) delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h create mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core}/SkTHash.h (89%) delete mode 100644 ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/{core => codec}/SkPngChunkReader.h (100%) delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h rename ios/vendored/{unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h => sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h} (85%) create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SingleOwner.h (86%) create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkDeque.h (98%) create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkFixed.h (94%) rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkFloatBits.h (96%) rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkFloatingPoint.h (89%) create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkMacros.h (77%) rename ios/vendored/{unversioned/@shopify/react-native-skia/cpp/skia/include/private => sdk48/@shopify/react-native-skia/cpp/skia/include/private/base}/SkMalloc.h (94%) rename ios/vendored/{unversioned/@shopify/react-native-skia/cpp/skia/include/core => sdk48/@shopify/react-native-skia/cpp/skia/include/private/base}/SkMath.h (64%) rename ios/vendored/{unversioned/@shopify/react-native-skia/cpp/skia/include/private => sdk48/@shopify/react-native-skia/cpp/skia/include/private/base}/SkMutex.h (86%) rename ios/vendored/{unversioned/@shopify/react-native-skia/cpp/skia/include/private => sdk48/@shopify/react-native-skia/cpp/skia/include/private/base}/SkNoncopyable.h (89%) rename ios/vendored/{sdk47/@shopify/react-native-skia/cpp/skia/include/private => sdk48/@shopify/react-native-skia/cpp/skia/include/private/base}/SkOnce.h (96%) create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h rename ios/vendored/{unversioned/@shopify/react-native-skia/cpp/skia/include/private => sdk48/@shopify/react-native-skia/cpp/skia/include/private/base}/SkSafe32.h (64%) rename ios/vendored/{unversioned/@shopify/react-native-skia/cpp/skia/include/private => sdk48/@shopify/react-native-skia/cpp/skia/include/private/base}/SkSemaphore.h (95%) create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTDArray.h (81%) rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTFitsIn.h (82%) rename ios/vendored/{unversioned/@shopify/react-native-skia/cpp/skia/include/private => sdk48/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTLogic.h (98%) rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTPin.h (100%) rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTemplates.h (73%) rename ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkThreadAnnotations.h (100%) rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base}/SkThreadID.h (69%) rename ios/vendored/{unversioned/@shopify/react-native-skia/cpp/skia/include/private => sdk48/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTo.h (71%) create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h rename android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h => ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h (87%) delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h create mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h rename ios/vendored/{sdk47/@shopify/react-native-skia/cpp/skia/include/private => sdk48/@shopify/react-native-skia/cpp/skia/src/core}/SkTHash.h (89%) delete mode 100644 ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.cpp create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.cpp create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.cpp create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/Declaration.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DeclarationContext.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/{core => codec}/SkPngChunkReader.h (100%) delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h rename android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h => ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h (85%) create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SingleOwner.h (86%) create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkDeque.h (98%) create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkFixed.h (94%) rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkFloatBits.h (96%) rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkFloatingPoint.h (89%) create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkMacros.h (77%) rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkMalloc.h (94%) rename ios/vendored/{sdk47/@shopify/react-native-skia/cpp/skia/include/core => unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkMath.h (64%) rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkMutex.h (86%) rename ios/vendored/{sdk47/@shopify/react-native-skia/cpp/skia/include/private => unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkNoncopyable.h (89%) rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkOnce.h (96%) create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h rename ios/vendored/{sdk47/@shopify/react-native-skia/cpp/skia/include/private => unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkSafe32.h (64%) rename {android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private => ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkSemaphore.h (95%) create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTDArray.h (81%) rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTFitsIn.h (82%) rename ios/vendored/{sdk47/@shopify/react-native-skia/cpp/skia/include/private => unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTLogic.h (98%) rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTPin.h (100%) rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkTemplates.h (73%) rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/{ => base}/SkThreadAnnotations.h (100%) rename ios/vendored/{sdk47/@shopify/react-native-skia/cpp/skia/include/private => unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkThreadID.h (69%) rename ios/vendored/{sdk47/@shopify/react-native-skia/cpp/skia/include/private => unversioned/@shopify/react-native-skia/cpp/skia/include/private/base}/SkTo.h (71%) create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/{MtlTypesPriv.h => MtlGraphiteTypesPriv.h} (87%) delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h rename ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/{include/private => src/core}/SkTHash.h (89%) delete mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaMetalRenderer.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaMetalRenderer.mm create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/ViewScreenshotService.h create mode 100644 ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/ViewScreenshotService.mm diff --git a/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImage.h b/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImage.h index a00dc63031f82..a0d6f0c6c643d 100644 --- a/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImage.h +++ b/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImage.h @@ -13,7 +13,9 @@ #include #include #include -#include +#include +#include +#include #pragma clang diagnostic pop @@ -69,7 +71,15 @@ namespace RNSkia auto quality = count == 2 ? arguments[1].asNumber() : 100.0; // Get data - auto data = getObject()->encodeToData(format, quality); + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, getObject().get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, getObject().get(), options); + } auto arrayCtor = runtime.global().getPropertyAsFunction(runtime, "Uint8Array"); size_t size = data->size(); @@ -90,8 +100,19 @@ namespace RNSkia auto format = count >= 1 ? static_cast(arguments[0].asNumber()) : SkEncodedImageFormat::kPNG; auto quality = count == 2 ? arguments[1].asNumber() : 100.0; - - auto data = getObject()->encodeToData(format, quality); + auto image = getObject(); + if (image->isTextureBacked()) { + image = image->makeNonTextureImage(); + } + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, image.get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, image.get(), options); + } auto len = SkBase64::Encode(data->bytes(), data->size(), nullptr); auto buffer = std::string(len, 0); SkBase64::Encode(data->bytes(), data->size(), (void *)&buffer[0]); diff --git a/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h b/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h index 549d30841241c..d5e53a8992689 100644 --- a/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h +++ b/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h @@ -18,7 +18,7 @@ namespace RNSkia { public: JSI_HOST_FUNCTION(MakeImageFromEncoded) { auto data = JsiSkData::fromValue(runtime, arguments[0]); - auto image = SkImage::MakeFromEncoded(data); + auto image = SkImages::DeferredFromEncodedData(data); if(image == nullptr) { return jsi::Value::null(); } @@ -30,7 +30,7 @@ namespace RNSkia { auto imageInfo = JsiSkImageInfo::fromValue(runtime, arguments[0]); auto pixelData = JsiSkData::fromValue(runtime, arguments[1]); auto bytesPerRow = arguments[2].asNumber(); - auto image = SkImage::MakeRasterData(*imageInfo, pixelData, bytesPerRow); + auto image = SkImages::RasterFromData(*imageInfo, pixelData, bytesPerRow); if(image == nullptr) { return jsi::Value::null(); } diff --git a/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkPath.h b/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkPath.h index 0fe830b4205c6..89bf85e77634f 100644 --- a/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkPath.h +++ b/android/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkPath.h @@ -7,6 +7,7 @@ #include #include "JsiSkHostObjects.h" +#include "JsiSkMatrix.h" #include "JsiSkPoint.h" #include "JsiSkRRect.h" #include "JsiSkRect.h" @@ -19,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -269,8 +271,11 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { auto jsiPrecision = opts.getProperty(runtime, "precision"); auto precision = jsiPrecision.isUndefined() ? 1 : jsiPrecision.asNumber(); - auto result = p.getFillPath(path, &path, nullptr, precision); - getObject()->swap(path); + auto result = + skpathutils::FillPathWithPaint(path, p, &path, nullptr, precision); + if (result) { + getObject()->swap(path); + } return result ? thisValue.getObject(runtime) : jsi::Value::null(); } @@ -305,8 +310,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { JSI_HOST_FUNCTION(toSVGString) { SkPath path = *getObject(); - SkString s; - SkParsePath::ToSVGString(path, &s); + auto s = SkParsePath::ToSVGString(path); return jsi::String::createFromUtf8(runtime, s.c_str()); } diff --git a/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImage.h b/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImage.h index e60245b60f14f..c206ed56a87a8 100644 --- a/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImage.h +++ b/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImage.h @@ -14,7 +14,9 @@ #include "SkBase64.h" #include "SkImage.h" #include "SkStream.h" -#include +#include "codec/SkEncodedImageFormat.h" +#include "include/encode/SkJpegEncoder.h" +#include "include/encode/SkPngEncoder.h" #pragma clang diagnostic pop @@ -70,7 +72,15 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject { auto quality = count == 2 ? arguments[1].asNumber() : 100.0; // Get data - auto data = getObject()->encodeToData(format, quality); + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, getObject().get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, getObject().get(), options); + } auto arrayCtor = runtime.global().getPropertyAsFunction(runtime, "Uint8Array"); size_t size = data->size(); @@ -95,8 +105,19 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject { : SkEncodedImageFormat::kPNG; auto quality = count == 2 ? arguments[1].asNumber() : 100.0; - - auto data = getObject()->encodeToData(format, quality); + auto image = getObject(); + if (image->isTextureBacked()) { + image = image->makeNonTextureImage(); + } + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, image.get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, image.get(), options); + } auto len = SkBase64::Encode(data->bytes(), data->size(), nullptr); auto buffer = std::string(len, 0); SkBase64::Encode(data->bytes(), data->size(), diff --git a/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h b/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h index ab2756be3de52..e9e4c043296b6 100644 --- a/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h +++ b/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h @@ -18,7 +18,7 @@ class JsiSkImageFactory : public JsiSkHostObject { public: JSI_HOST_FUNCTION(MakeImageFromEncoded) { auto data = JsiSkData::fromValue(runtime, arguments[0]); - auto image = SkImage::MakeFromEncoded(data); + auto image = SkImages::DeferredFromEncodedData(data); if (image == nullptr) { return jsi::Value::null(); } @@ -30,7 +30,7 @@ class JsiSkImageFactory : public JsiSkHostObject { auto imageInfo = JsiSkImageInfo::fromValue(runtime, arguments[0]); auto pixelData = JsiSkData::fromValue(runtime, arguments[1]); auto bytesPerRow = arguments[2].asNumber(); - auto image = SkImage::MakeRasterData(*imageInfo, pixelData, bytesPerRow); + auto image = SkImages::RasterFromData(*imageInfo, pixelData, bytesPerRow); if (image == nullptr) { return jsi::Value::null(); } diff --git a/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkPath.h b/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkPath.h index f6f6daec9e77f..2e7dae817a36e 100644 --- a/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkPath.h +++ b/android/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkPath.h @@ -7,6 +7,7 @@ #include #include "JsiSkHostObjects.h" +#include "JsiSkMatrix.h" #include "JsiSkPoint.h" #include "JsiSkRRect.h" #include "JsiSkRect.h" @@ -20,6 +21,7 @@ #include "SkPathEffect.h" #include "SkPathOps.h" #include "SkPathTypes.h" +#include "SkPathUtils.h" #include "SkString.h" #include "SkStrokeRec.h" #include "SkTextUtils.h" @@ -289,8 +291,11 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { auto jsiPrecision = opts.getProperty(runtime, "precision"); auto precision = jsiPrecision.isUndefined() ? 1 : jsiPrecision.asNumber(); - auto result = p.getFillPath(path, &path, nullptr, precision); - getObject()->swap(path); + auto result = + skpathutils::FillPathWithPaint(path, p, &path, nullptr, precision); + if (result) { + getObject()->swap(path); + } return result ? thisValue.getObject(runtime) : jsi::Value::null(); } @@ -325,8 +330,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { JSI_HOST_FUNCTION(toSVGString) { SkPath path = *getObject(); - SkString s; - SkParsePath::ToSVGString(path, &s); + auto s = SkParsePath::ToSVGString(path); return jsi::String::createFromUtf8(runtime, s.c_str()); } diff --git a/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h b/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h index c6500f09dbc77..374fb1b85c721 100644 --- a/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +++ b/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h @@ -10,6 +10,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" +#include #include #pragma clang diagnostic pop diff --git a/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h b/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h index aa185aa48b4f4..f7dd40f45d30d 100644 --- a/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h +++ b/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h @@ -110,8 +110,8 @@ class JsiPathNode : public JsiDomDrawingNode, // _path is const so we can't mutate it directly, let's replace the // path like this: auto p = std::make_shared(*_path.get()); - if (!strokePaint.getFillPath(*_path.get(), p.get(), nullptr, - precision)) { + if (!skpathutils::FillPathWithPaint(*_path.get(), strokePaint, + p.get(), nullptr, precision)) { _path = nullptr; } else { _path = std::const_pointer_cast(p); diff --git a/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h b/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h index 6c438604d6f0b..e23213cba18cf 100644 --- a/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h +++ b/android/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h @@ -5,6 +5,8 @@ #include #include +#include + namespace RNSkia { class BoxShadowProps : public DerivedProp { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/android/CMakeLists.txt b/android/vendored/unversioned/@shopify/react-native-skia/android/CMakeLists.txt index 794a5d3e23e17..342535b862991 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/android/CMakeLists.txt +++ b/android/vendored/unversioned/@shopify/react-native-skia/android/CMakeLists.txt @@ -3,9 +3,9 @@ cmake_minimum_required(VERSION 3.4.1) set (CMAKE_VERBOSE_MAKEFILE ON) set (CMAKE_CXX_STANDARD 17) -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSK_GL -DSK_BUILD_FOR_ANDROID -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID -DONANDROID") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSK_GL -DSK_GANESH -DSK_BUILD_FOR_ANDROID -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID -DONANDROID") -set (PACKAGE_NAME "reactskia") +set (PACKAGE_NAME "rnskia") set (SKIA_LIB "skia") set (SKIA_SVG_LIB "svg") set (SKIA_SKSHAPER_LIB "skshaper") @@ -31,7 +31,7 @@ link_directories(../libs/android/${ANDROID_ABI}/) if(${REACT_NATIVE_VERSION} LESS 66) file( - TO_CMAKE_PATH + TO_CMAKE_PATH "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp" INCLUDE_JSI_CPP ) @@ -49,6 +49,8 @@ add_library( "${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiHostObject.cpp" "${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiValue.cpp" + "${PROJECT_SOURCE_DIR}/../cpp/jsi/RuntimeLifecycleMonitor.cpp" + "${PROJECT_SOURCE_DIR}/../cpp/jsi/RuntimeAwareCache.cpp" "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkManager.cpp" "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkJsView.cpp" @@ -56,9 +58,10 @@ add_library( "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkDispatchQueue.cpp" "${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base/DrawingContext.cpp" + "${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base/ConcatablePaint.cpp" "${PROJECT_SOURCE_DIR}/../cpp/api/third_party/CSSColorParser.cpp" - + ) target_include_directories( @@ -91,7 +94,7 @@ target_include_directories( ${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base ${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/nodes ${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/props - ${PROJECT_SOURCE_DIR}/../cpp/utils + ${PROJECT_SOURCE_DIR}/../cpp/utils ${libfbjni_include_DIRS} ) diff --git a/android/vendored/unversioned/@shopify/react-native-skia/android/build.gradle b/android/vendored/unversioned/@shopify/react-native-skia/android/build.gradle index 4d951714f6c40..f75d45da2a7d9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/android/build.gradle +++ b/android/vendored/unversioned/@shopify/react-native-skia/android/build.gradle @@ -28,6 +28,11 @@ def safeExtGet(prop, fallback) { apply plugin: 'com.android.library' +def reactNativeArchitectures() { + def value = project.getProperties().get("reactNativeArchitectures") + return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] +} + static def findNodeModules(baseDir) { def basePath = baseDir.toPath().normalize() // Node's module resolution algorithm searches up to the root directory, @@ -76,15 +81,11 @@ if (gradle.startParameter.taskRequests.args[0].toString().contains("Release")) { buildType = "debug" } -def reactNativeArchitectures() { - def value = project.getProperties().get("reactNativeArchitectures") - return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] -} - def reactProperties = new Properties() file("$nodeModules/react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) } def FULL_RN_VERSION = (System.getenv("REACT_NATIVE_OVERRIDE_VERSION") ?: reactProperties.getProperty("VERSION_NAME")) def REACT_NATIVE_VERSION = FULL_RN_VERSION.split("\\.")[1].toInteger() +def ENABLE_PREFAB = REACT_NATIVE_VERSION > 68 logger.warn("react-native-skia: RN Version: ${REACT_NATIVE_VERSION} / ${FULL_RN_VERSION}") logger.warn("react-native-skia: isSourceBuild: ${sourceBuild}") @@ -92,6 +93,7 @@ logger.warn("react-native-skia: PrebuiltDir: ${prebuiltDir}") logger.warn("react-native-skia: buildType: ${buildType}") logger.warn("react-native-skia: buildDir: ${buildDir}") logger.warn("react-native-skia: node_modules: ${nodeModules}") +logger.warn("react-native-skia: Enable Prefab: ${ENABLE_PREFAB}") buildscript { // The Android Gradle plugin is only required when opening the android folder stand-alone. @@ -137,24 +139,33 @@ android { externalNativeBuild { cmake { - path file('CMakeLists.txt') + path file('CMakeLists.txt') } } - buildFeatures { - prefab true - } - packagingOptions { excludes = [ "**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so", "**/libreact_nativemodule_core.so", - "**/libturbomodulejsijni.so" + "**/libturbomodulejsijni.so", + "META-INF/**" ] } + if (ENABLE_PREFAB) { + buildFeatures { + prefab true + prefabPublishing true + } + prefab { + rnskia { + headers "${project.buildDir}/headers/rnskia/" + } + } + } + // Create new configurations that can be referred to in dependencies. // The Android Gradle Plugin 3.* does not allow hooking into existing // configurations like `implementation`. @@ -239,6 +250,30 @@ task extractJNIFiles { extractJNIFiles.mustRunAfter extractAARHeaders +if (ENABLE_PREFAB) { + // Package all the cpp code in a flattened directory structure + task prepareHeaders(type: Copy) { + from("./cpp") + into "${project.buildDir}/headers/rnskia/" + includeEmptyDirs = false + include "**/*.h" + duplicatesStrategy = 'include' + eachFile { + String path = it.path + + // Skip flattening third_party dir + if (path.contains("api/third_party")) { + path = path.substring("api/".length()) + } else { + // flatten anything else + path = path.substring(path.lastIndexOf("/") + 1) + } + it.path = path + } + } + preBuild.dependsOn(prepareHeaders) +} + def nativeBuildDependsOn(dependsOnTask, variant) { def buildTasks = tasks.findAll({ task -> !task.name.contains("Clean") && (task.name.contains("externalNative") || task.name.contains("CMake")) }) @@ -250,5 +285,5 @@ def nativeBuildDependsOn(dependsOnTask, variant) { afterEvaluate { nativeBuildDependsOn(extractAARHeaders, null) - nativeBuildDependsOn(extractJNIFiles, null) + nativeBuildDependsOn(extractJNIFiles, null) } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/jni/JniPlatformContext.cpp b/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/jni/JniPlatformContext.cpp index a8868e9fb30db..07e3786e87c26 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/jni/JniPlatformContext.cpp +++ b/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/jni/JniPlatformContext.cpp @@ -8,7 +8,51 @@ #include "SkRefCnt.h" #include "SkStream.h" #include "SkTypes.h" -#include + +#include + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdocumentation" + +#include "SkBitmap.h" +#include "SkPixmap.h" + +#pragma clang diagnostic pop + +static SkAlphaType alpha_type(int32_t flags) { + switch ((flags >> ANDROID_BITMAP_FLAGS_ALPHA_SHIFT) & + ANDROID_BITMAP_FLAGS_ALPHA_MASK) { + case ANDROID_BITMAP_FLAGS_ALPHA_OPAQUE: + return kOpaque_SkAlphaType; + case ANDROID_BITMAP_FLAGS_ALPHA_PREMUL: + return kPremul_SkAlphaType; + case ANDROID_BITMAP_FLAGS_ALPHA_UNPREMUL: + return kUnpremul_SkAlphaType; + default: + break; + } + + return kUnknown_SkAlphaType; +} + +static SkColorType color_type(int32_t format) { + switch (format) { + case ANDROID_BITMAP_FORMAT_RGBA_8888: + return kRGBA_8888_SkColorType; + case ANDROID_BITMAP_FORMAT_RGB_565: + return kRGB_565_SkColorType; + case ANDROID_BITMAP_FORMAT_RGBA_4444: + return kARGB_4444_SkColorType; + case ANDROID_BITMAP_FORMAT_RGBA_F16: + return kRGBA_F16_SkColorType; + case ANDROID_BITMAP_FORMAT_A_8: + return kAlpha_8_SkColorType; + default: + break; + } + + return kUnknown_SkColorType; +} namespace RNSkia { @@ -31,6 +75,41 @@ TSelf JniPlatformContext::initHybrid(jni::alias_ref jThis, return makeCxxInstance(jThis, pixelDensity); } +sk_sp JniPlatformContext::takeScreenshotFromViewTag(size_t tag) { + // Call the java method for creating a view screenshot as a bitmap: + auto env = jni::Environment::current(); + static auto method = javaPart_->getClass()->getMethod( + "takeScreenshotFromViewTag"); + + auto bitmap = method(javaPart_.get(), tag).release(); + + // Let's convert to a native bitmap and get some info about the bitmap + AndroidBitmapInfo bmi; + AndroidBitmap_getInfo(env, bitmap, &bmi); + + // Convert android bitmap info to a Skia bitmap info + auto colorType = color_type(bmi.format); + auto alphaType = alpha_type(bmi.flags); + + auto skInfo = SkImageInfo::Make(SkISize::Make(bmi.width, bmi.height), + colorType, alphaType); + + // Lock pixels + void *pixels; + AndroidBitmap_lockPixels(env, bitmap, &pixels); + + // Create pixmap from pixels and make a copy of it so that + // the SkImage owns its own pixels + SkPixmap pm(skInfo, pixels, bmi.stride); + auto skImage = SkImages::RasterFromPixmapCopy(pm); + + // Unlock pixels + AndroidBitmap_unlockPixels(env, bitmap); + + // Return our newly created SkImage! + return skImage; +} + void JniPlatformContext::startDrawLoop() { jni::ThreadScope ts; // Start drawing loop @@ -52,7 +131,19 @@ void JniPlatformContext::notifyDrawLoopExternal() { _onNotifyDrawLoop(); } +void JniPlatformContext::runTaskOnMainThread(std::function task) { + _taskMutex->lock(); + _taskCallbacks.push(task); + _taskMutex->unlock(); + + // Notify Java that task is ready + static auto method = javaPart_->getClass()->getMethod( + "notifyTaskReadyOnMainThread"); + method(javaPart_.get()); +} + void JniPlatformContext::notifyTaskReadyExternal() { + jni::ThreadScope ts; _taskMutex->lock(); auto task = _taskCallbacks.front(); if (task != nullptr) { @@ -67,8 +158,6 @@ void JniPlatformContext::notifyTaskReadyExternal() { void JniPlatformContext::performStreamOperation( const std::string &sourceUri, const std::function)> &op) { - auto measure = RNSkMeasureTime("JniPlatformContext::performStreamOperation"); - static auto method = javaPart_->getClass()->getMethod( "getJniStreamFromSource"); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/jni/include/JniPlatformContext.h b/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/jni/include/JniPlatformContext.h index acf5be96fe5a7..00f6af757fe87 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/jni/include/JniPlatformContext.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/jni/include/JniPlatformContext.h @@ -44,8 +44,12 @@ class JniPlatformContext : public jni::HybridClass { void notifyTaskReadyExternal(); + void runTaskOnMainThread(std::function task); + float getPixelDensity() { return _pixelDensity; } + sk_sp takeScreenshotFromViewTag(size_t tag); + void setOnNotifyDrawLoop(const std::function &callback) { _onNotifyDrawLoop = callback; } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h b/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h index 0dcd3b04c9767..2a85adb54c3b8 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h @@ -7,6 +7,7 @@ #include #include +#include namespace RNSkia { namespace jsi = facebook::jsi; @@ -36,6 +37,18 @@ class RNSkAndroidPlatformContext : public RNSkPlatformContext { _jniPlatformContext->raiseError(err); } + sk_sp makeOffscreenSurface(int width, int height) override { + return MakeOffscreenGLSurface(width, height); + } + + void runOnMainThread(std::function task) override { + _jniPlatformContext->runTaskOnMainThread(task); + } + + sk_sp takeScreenshotFromViewTag(size_t tag) override { + return _jniPlatformContext->takeScreenshotFromViewTag(tag); + } + void startDrawLoop() override { _jniPlatformContext->startDrawLoop(); } void stopDrawLoop() override { _jniPlatformContext->stopDrawLoop(); } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp b/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp index 72b9d1ba9f553..1de8d28b81ea2 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +++ b/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp @@ -6,6 +6,112 @@ namespace RNSkia { /** Static members */ +sk_sp MakeOffscreenGLSurface(int width, int height) { + EGLDisplay eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (eglDisplay == EGL_NO_DISPLAY) { + RNSkLogger::logToConsole("eglGetdisplay failed : %i", glGetError()); + return nullptr; + } + + EGLint major; + EGLint minor; + if (!eglInitialize(eglDisplay, &major, &minor)) { + RNSkLogger::logToConsole("eglInitialize failed : %i", glGetError()); + return nullptr; + } + + EGLint att[] = {EGL_RENDERABLE_TYPE, + EGL_OPENGL_ES2_BIT, + EGL_SURFACE_TYPE, + EGL_PBUFFER_BIT, + EGL_ALPHA_SIZE, + 8, + EGL_BLUE_SIZE, + 8, + EGL_GREEN_SIZE, + 8, + EGL_RED_SIZE, + 8, + EGL_DEPTH_SIZE, + 0, + EGL_STENCIL_SIZE, + 0, + EGL_NONE}; + + EGLint numConfigs; + EGLConfig eglConfig; + eglConfig = 0; + if (!eglChooseConfig(eglDisplay, att, &eglConfig, 1, &numConfigs) || + numConfigs == 0) { + RNSkLogger::logToConsole("Failed to choose a config %d\n", eglGetError()); + return nullptr; + } + + EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; + + EGLContext eglContext = + eglCreateContext(eglDisplay, eglConfig, NULL, contextAttribs); + + if (eglContext == EGL_NO_CONTEXT) { + RNSkLogger::logToConsole("eglCreateContext failed: %d\n", eglGetError()); + return nullptr; + } + + const EGLint offScreenSurfaceAttribs[] = {EGL_WIDTH, width, EGL_HEIGHT, + height, EGL_NONE}; + EGLSurface eglSurface = + eglCreatePbufferSurface(eglDisplay, eglConfig, offScreenSurfaceAttribs); + if (!eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) { + RNSkLogger::logToConsole("eglMakeCurrent failed: %d\n", eglGetError()); + return nullptr; + } + GLint buffer; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &buffer); + + GLint stencil; + glGetIntegerv(GL_STENCIL_BITS, &stencil); + + GLint samples; + glGetIntegerv(GL_SAMPLES, &samples); + + // Create the Skia backend context + auto backendInterface = GrGLMakeNativeInterface(); + auto grContext = GrDirectContext::MakeGL(backendInterface); + if (grContext == nullptr) { + RNSkLogger::logToConsole("GrDirectContext::MakeGL failed"); + return nullptr; + } + auto maxSamples = + grContext->maxSurfaceSampleCountForColorType(kRGBA_8888_SkColorType); + + if (samples > maxSamples) + samples = maxSamples; + + GrGLFramebufferInfo fbInfo; + fbInfo.fFBOID = buffer; + fbInfo.fFormat = 0x8058; + + auto renderTarget = + GrBackendRenderTarget(width, height, samples, stencil, fbInfo); + + struct OffscreenRenderContext { + EGLDisplay display; + EGLSurface surface; + }; + auto ctx = new OffscreenRenderContext({eglDisplay, eglSurface}); + + auto surface = SkSurface::MakeFromBackendRenderTarget( + grContext.get(), renderTarget, kBottomLeft_GrSurfaceOrigin, + kRGBA_8888_SkColorType, nullptr, nullptr, + [](void *addr) { + auto ctx = reinterpret_cast(addr); + eglDestroySurface(ctx->display, ctx->surface); + delete ctx; + }, + reinterpret_cast(ctx)); + return surface; +} + std::shared_ptr SkiaOpenGLRenderer::getThreadDrawingContext() { auto threadId = std::this_thread::get_id(); @@ -57,13 +163,8 @@ void SkiaOpenGLRenderer::run(const std::function &cb, // during rendering. getThreadDrawingContext()->skContext->resetContext(); - // Clear with transparent - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClear(GL_COLOR_BUFFER_BIT); - // Draw picture into surface cb(_skSurface->getCanvas()); - // Flush _skSurface->flushAndSubmit(); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/SkiaOpenGLRenderer.h b/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/SkiaOpenGLRenderer.h index 576097a8b26df..e7d89133b7c0a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/android/cpp/rnskia-android/SkiaOpenGLRenderer.h @@ -26,6 +26,8 @@ #pragma clang diagnostic pop namespace RNSkia { +sk_sp MakeOffscreenGLSurface(int width, int height); + using OpenGLDrawingContext = struct { EGLContext glContext; EGLDisplay glDisplay; @@ -127,4 +129,4 @@ class SkiaOpenGLRenderer { std::atomic _renderState = {RenderState::Initializing}; }; -} // namespace RNSkia +} // namespace RNSkia \ No newline at end of file diff --git a/android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java b/android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java index c3a71a2e4eae4..0e7c7df2a1569 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +++ b/android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java @@ -1,6 +1,7 @@ package com.shopify.reactnative.skia; import android.app.Application; +import android.graphics.Bitmap; import android.os.Handler; import android.os.Looper; import android.util.Log; @@ -53,7 +54,7 @@ private void postFrameLoop() { Choreographer.FrameCallback frameCallback = new Choreographer.FrameCallback() { @Override public void doFrame(long frameTimeNanos) { - if(_isPaused) { + if (_isPaused) { return; } notifyDrawLoop(); @@ -65,6 +66,21 @@ public void doFrame(long frameTimeNanos) { Choreographer.getInstance().postFrameCallback(frameCallback); } + @DoNotStrip + public void notifyTaskReadyOnMainThread() { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + notifyTaskReady(); + } + }); + } + + @DoNotStrip + Object takeScreenshotFromViewTag(int tag) { + return ViewScreenshotService.makeViewScreenshotFromTag(mContext, tag); + } + @DoNotStrip public void raise(final String message) { new Handler(Looper.getMainLooper()).post(new Runnable() { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/RNSkiaModule.java b/android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/RNSkiaModule.java index 0521f0534e796..3cb5dae94777b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/RNSkiaModule.java +++ b/android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/RNSkiaModule.java @@ -57,7 +57,7 @@ public boolean install() { } try { - System.loadLibrary("reactskia"); + System.loadLibrary("rnskia"); ReactApplicationContext context = weakReactContext.get(); if (context == null) { Log.e(NAME, "React Application Context was null!"); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java b/android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java new file mode 100644 index 0000000000000..b0c4431ce4838 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java @@ -0,0 +1,180 @@ +package com.shopify.reactnative.skia; + +import static android.view.View.VISIBLE; + +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.os.Build; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; +import android.view.PixelCopy; +import android.view.SurfaceView; +import android.view.TextureView; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; + +import com.facebook.react.bridge.ReactContext; +import com.facebook.react.uimanager.UIManagerModule; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + + +public class ViewScreenshotService { + private static final long SURFACE_VIEW_READ_PIXELS_TIMEOUT = 5; + private static final String TAG = "SkiaScreenshot"; + + public static Bitmap makeViewScreenshotFromTag(ReactContext context, int tag) { + UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class); + View view = uiManager.resolveView(tag); + if (view == null) { + throw new RuntimeException("Could not resolve view from view tag " + tag); + } + + // Measure and get size of view + int width = view.getWidth(); + int height = view.getHeight(); + + if (width <= 0 || height <= 0) { + return null; + } + + // The following code is taken from react-native-view-shot to be able to handle and + // correctly render all kinds of views, also including TextureViews and SurfaceViews + Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + + final Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setFilterBitmap(true); + paint.setDither(true); + + // Render the main view and its children + final Canvas c = new Canvas(bitmap); + view.draw(c); + + // Enumerate children + final List childrenList = getAllChildren(view); + + for (final View child : childrenList) { + // skip any child that we don't know how to process + if (child instanceof TextureView) { + // skip all invisible to user child views + if (child.getVisibility() != VISIBLE) continue; + + final TextureView tvChild = (TextureView) child; + tvChild.setOpaque(false); // <-- switch off background fill + + // TextureView should use bitmaps with matching size, + // otherwise content of the TextureView will be scaled to provided bitmap dimensions + final Bitmap childBitmapBuffer = tvChild.getBitmap(Bitmap.createBitmap(child.getWidth(), child.getHeight(), Bitmap.Config.ARGB_8888)); + + final int countCanvasSave = c.save(); + applyTransformations(c, view, child); + + // due to re-use of bitmaps for screenshot, we can get bitmap that is bigger in size than requested + c.drawBitmap(childBitmapBuffer, 0, 0, paint); + + c.restoreToCount(countCanvasSave); + } else if (child instanceof SurfaceView) { + final SurfaceView svChild = (SurfaceView)child; + final CountDownLatch latch = new CountDownLatch(1); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + final Bitmap childBitmapBuffer = Bitmap.createBitmap(child.getWidth(), child.getHeight(), Bitmap.Config.ARGB_8888); + try { + PixelCopy.request(svChild, childBitmapBuffer, new PixelCopy.OnPixelCopyFinishedListener() { + @Override + public void onPixelCopyFinished(int copyResult) { + final int countCanvasSave = c.save(); + applyTransformations(c, view, child); + c.drawBitmap(childBitmapBuffer, 0, 0, paint); + c.restoreToCount(countCanvasSave); + latch.countDown(); + } + }, new Handler(Looper.getMainLooper())); + latch.await(SURFACE_VIEW_READ_PIXELS_TIMEOUT, TimeUnit.SECONDS); + } catch (Exception e) { + Log.e(TAG, "Cannot PixelCopy for " + svChild, e); + } + } else { + Bitmap cache = svChild.getDrawingCache(); + if (cache != null) { + c.drawBitmap(svChild.getDrawingCache(), 0, 0, paint); + } + } + } + } + + return bitmap; + } + + private static List getAllChildren(@NonNull final View v) { + if (!(v instanceof ViewGroup)) { + final ArrayList viewArrayList = new ArrayList<>(); + viewArrayList.add(v); + + return viewArrayList; + } + + final ArrayList result = new ArrayList<>(); + + ViewGroup viewGroup = (ViewGroup) v; + for (int i = 0; i < viewGroup.getChildCount(); i++) { + View child = viewGroup.getChildAt(i); + + //Do not add any parents, just add child elements + result.addAll(getAllChildren(child)); + } + + return result; + } + + /** + * Concat all the transformation matrix's from parent to child. + */ + @NonNull + @SuppressWarnings("UnusedReturnValue") + private static Matrix applyTransformations(final Canvas c, @NonNull final View root, @NonNull final View child) { + final Matrix transform = new Matrix(); + final LinkedList ms = new LinkedList<>(); + + // find all parents of the child view + View iterator = child; + do { + ms.add(iterator); + + iterator = (View) iterator.getParent(); + } while (iterator != root); + + // apply transformations from parent --> child order + Collections.reverse(ms); + + for (final View v : ms) { + c.save(); + + // apply each view transformations, so each child will be affected by them + final float dx = v.getLeft() + ((v != child) ? v.getPaddingLeft() : 0) + v.getTranslationX(); + final float dy = v.getTop() + ((v != child) ? v.getPaddingTop() : 0) + v.getTranslationY(); + c.translate(dx, dy); + c.rotate(v.getRotation(), v.getPivotX(), v.getPivotY()); + c.scale(v.getScaleX(), v.getScaleY()); + + // compute the matrix just for any future use + transform.postTranslate(dx, dy); + transform.postRotate(v.getRotation(), v.getPivotX(), v.getPivotY()); + transform.postScale(v.getScaleX(), v.getScaleY()); + } + + return transform; + } + +} diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkColorFilter.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkColorFilter.h index d5c3a361ef5d9..06410738e20ab 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkColorFilter.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkColorFilter.h @@ -23,23 +23,8 @@ class JsiSkColorFilter : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(colorFilter)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "ColorFilter"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkColorFilter, - __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkColorFilter, "ColorFilter") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkColorFilter, dispose)) }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasure.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasure.h index 36331765e1266..3dff4ebdd856c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasure.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasure.h @@ -68,26 +68,12 @@ class JsiSkContourMeasure return JsiSkPath::toValue(runtime, getContext(), std::move(path)); } - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "ContourMeasure"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkContourMeasure, - __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkContourMeasure, "ContourMeasure") JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkContourMeasure, getPosTan), JSI_EXPORT_FUNC(JsiSkContourMeasure, length), JSI_EXPORT_FUNC(JsiSkContourMeasure, isClosed), - JSI_EXPORT_FUNC(JsiSkContourMeasure, getSegment)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + JSI_EXPORT_FUNC(JsiSkContourMeasure, getSegment), + JSI_EXPORT_FUNC(JsiSkContourMeasure, dispose)) }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasureIter.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasureIter.h index c945a3e3b0a8a..8ea8d7cd1da24 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasureIter.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasureIter.h @@ -29,14 +29,6 @@ class JsiSkContourMeasureIter std::move(context), std::make_shared( path, forceClosed, resScale)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "ContourMeasureIter"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkContourMeasureIter, - __typename__), ) - JSI_HOST_FUNCTION(next) { auto next = getObject()->next(); if (next == nullptr) { @@ -48,17 +40,10 @@ class JsiSkContourMeasureIter return jsi::Object::createFromHostObject(runtime, std::move(nextObject)); } - JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkContourMeasureIter, next)) + EXPORT_JSI_API_TYPENAME(JsiSkContourMeasureIter, "ContourMeasureIter") - /** - Returns the underlying object from a host object of this type - */ - static std::shared_ptr - fromValue(jsi::Runtime &runtime, const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkContourMeasureIter, next), + JSI_EXPORT_FUNC(JsiSkContourMeasureIter, dispose)) /** * Creates the function for construction a new instance of the diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkData.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkData.h index b791c300d13a7..3e24df5119f45 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkData.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkData.h @@ -24,17 +24,7 @@ class JsiSkData : public JsiSkWrappingSkPtrHostObject { JsiSkData(std::shared_ptr context, sk_sp asset) : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(asset)) {} - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Data"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkData, __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, const jsi::Value &obj) { - return obj.asObject(runtime).asHostObject(runtime)->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkData, "Data") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkData, dispose)) }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkFont.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkFont.h index 4cb11c6003951..917791ee90538 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkFont.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkFont.h @@ -6,7 +6,7 @@ #include #include "JsiSkHostObjects.h" -#include +#include "RNSkLog.h" #include #include "JsiSkPaint.h" @@ -28,11 +28,6 @@ namespace jsi = facebook::jsi; class JsiSkFont : public JsiSkWrappingSharedPtrHostObject { public: - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Font"); - } - JSI_HOST_FUNCTION(getGlyphWidths) { auto jsiGlyphs = arguments[0].asObject(runtime).asArray(runtime); std::vector glyphs; @@ -244,6 +239,8 @@ class JsiSkFont : public JsiSkWrappingSharedPtrHostObject { return jsi::Value::undefined(); } + EXPORT_JSI_API_TYPENAME(JsiSkFont, "Font") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFont, getSize), JSI_EXPORT_FUNC(JsiSkFont, getMetrics), JSI_EXPORT_FUNC(JsiSkFont, getGlyphIDs), @@ -262,20 +259,13 @@ class JsiSkFont : public JsiSkWrappingSharedPtrHostObject { JSI_EXPORT_FUNC(JsiSkFont, setSubpixel), JSI_EXPORT_FUNC(JsiSkFont, setTypeface), JSI_EXPORT_FUNC(JsiSkFont, getGlyphWidths), - JSI_EXPORT_FUNC(JsiSkFont, getTextWidth)) + JSI_EXPORT_FUNC(JsiSkFont, getTextWidth), + JSI_EXPORT_FUNC(JsiSkFont, dispose)) JsiSkFont(std::shared_ptr context, const SkFont &font) : JsiSkWrappingSharedPtrHostObject(std::move(context), std::make_shared(font)) {} - /** - Returns the underlying object from a host object of this type - */ - static std::shared_ptr fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime).asHostObject(runtime)->getObject(); - } - /** * Creates the function for construction a new instance of the SkFont * wrapper diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkHostObjects.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkHostObjects.h index 660761d8583e1..68410f9c45bbc 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkHostObjects.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkHostObjects.h @@ -3,15 +3,16 @@ #include #include +#include "JsiHostObject.h" #include "RNSkPlatformContext.h" -#include namespace RNSkia { namespace jsi = facebook::jsi; /** - * Base class for jsi host objects + * Base class for jsi host objects - these are all implemented as JsiHostObjects + * and has a pointer to the platform context. */ class JsiSkHostObject : public RNJsi::JsiHostObject { public: @@ -32,6 +33,15 @@ class JsiSkHostObject : public RNJsi::JsiHostObject { std::shared_ptr _context; }; +#define JSI_API_TYPENAME(A) \ + JSI_PROPERTY_GET(__typename__) { \ + return jsi::String::createFromUtf8(runtime, #A); \ + } + +#define EXPORT_JSI_API_TYPENAME(CLASS, TYPENAME) \ + JSI_API_TYPENAME(TYPENAME) \ + JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(CLASS, __typename__)) + template class JsiSkWrappingHostObject : public JsiSkHostObject { public: /** @@ -39,32 +49,65 @@ template class JsiSkWrappingHostObject : public JsiSkHostObject { * @param context Platform context */ JsiSkWrappingHostObject(std::shared_ptr context, - T &&object) + T object) : JsiSkHostObject(std::move(context)), _object(std::move(object)) {} - JsiSkWrappingHostObject(std::shared_ptr context, - const T &object) - : JsiSkHostObject(std::move(context)), _object(object) {} - /** * Returns the underlying object exposed by this host object. This object * should be wrapped in a shared pointer of some kind * @return Underlying object */ - T &getObject() { return _object; } - const T &getObject() const { return _object; } + T getObject() { return _object; } + const T getObject() const { return _object; } /** Updates the inner object with a new version of the object. */ - void setObject(T &object) { _object = object; } - void setObject(const T &object) { _object = object; } + void setObject(T object) { _object = object; } + + /** + Dispose function that can be exposed to JS by using the JSI_API_TYPENAME + macro + */ + JSI_HOST_FUNCTION(dispose) { + safeDispose(); + return jsi::Value::undefined(); + } + +protected: + /** + Override to implement disposale of allocated resources like smart pointers + etc. This method will only be called once for each instance of this class. + */ + virtual void releaseResources() = 0; + + /** + Throws a runtime error if this method is called after the object has been + disposed. + */ + void ensureNotDisposed() { + if (_isDisposed) { + throw std::runtime_error("API Object accessed after it was disposed"); + } + } private: + void safeDispose() { + if (!_isDisposed) { + _isDisposed = true; + releaseResources(); + } + } + /** * Wrapped object */ T _object; + + /** + Resource disposed flag + */ + std::atomic _isDisposed = {false}; }; template @@ -75,6 +118,22 @@ class JsiSkWrappingSharedPtrHostObject std::shared_ptr object) : JsiSkWrappingHostObject>(std::move(context), std::move(object)) {} + + /** + Returns the underlying object from a host object of this type + */ + static std::shared_ptr fromValue(jsi::Runtime &runtime, + const jsi::Value &obj) { + return std::static_pointer_cast( + obj.asObject(runtime).asHostObject(runtime)) + ->getObject(); + } + +protected: + void releaseResources() override { + // Clear internally allocated objects + this->setObject(nullptr); + } }; template @@ -84,5 +143,21 @@ class JsiSkWrappingSkPtrHostObject : public JsiSkWrappingHostObject> { sk_sp object) : JsiSkWrappingHostObject>(std::move(context), std::move(object)) {} + + /** + Returns the underlying object from a host object of this type + */ + static sk_sp fromValue(jsi::Runtime &runtime, const jsi::Value &obj) { + return std::static_pointer_cast( + obj.asObject(runtime).asHostObject(runtime)) + ->getObject(); + } + +protected: + void releaseResources() override { + // Clear internally allocated objects + this->setObject(nullptr); + } }; + } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImage.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImage.h index e60245b60f14f..9591906ef160b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImage.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImage.h @@ -4,9 +4,9 @@ #include #include +#include "JsiSkHostObjects.h" #include "JsiSkMatrix.h" #include "JsiSkShader.h" -#include #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -14,7 +14,9 @@ #include "SkBase64.h" #include "SkImage.h" #include "SkStream.h" -#include +#include "codec/SkEncodedImageFormat.h" +#include "include/encode/SkJpegEncoder.h" +#include "include/encode/SkPngEncoder.h" #pragma clang diagnostic pop @@ -70,7 +72,15 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject { auto quality = count == 2 ? arguments[1].asNumber() : 100.0; // Get data - auto data = getObject()->encodeToData(format, quality); + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, getObject().get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, getObject().get(), options); + } auto arrayCtor = runtime.global().getPropertyAsFunction(runtime, "Uint8Array"); size_t size = data->size(); @@ -95,8 +105,19 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject { : SkEncodedImageFormat::kPNG; auto quality = count == 2 ? arguments[1].asNumber() : 100.0; - - auto data = getObject()->encodeToData(format, quality); + auto image = getObject(); + if (image->isTextureBacked()) { + image = image->makeNonTextureImage(); + } + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, image.get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, image.get(), options); + } auto len = SkBase64::Encode(data->bytes(), data->size(), nullptr); auto buffer = std::string(len, 0); SkBase64::Encode(data->bytes(), data->size(), @@ -104,25 +125,27 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject { return jsi::String::createFromAscii(runtime, buffer); } + JSI_HOST_FUNCTION(makeNonTextureImage) { + auto image = getObject()->makeNonTextureImage(); + return jsi::Object::createFromHostObject( + runtime, std::make_shared(getContext(), std::move(image))); + } + + EXPORT_JSI_API_TYPENAME(JsiSkImage, "Image") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkImage, width), JSI_EXPORT_FUNC(JsiSkImage, height), JSI_EXPORT_FUNC(JsiSkImage, makeShaderOptions), JSI_EXPORT_FUNC(JsiSkImage, makeShaderCubic), JSI_EXPORT_FUNC(JsiSkImage, encodeToBytes), - JSI_EXPORT_FUNC(JsiSkImage, encodeToBase64)) + JSI_EXPORT_FUNC(JsiSkImage, encodeToBase64), + JSI_EXPORT_FUNC(JsiSkImage, makeNonTextureImage), + JSI_EXPORT_FUNC(JsiSkImage, dispose)) JsiSkImage(std::shared_ptr context, const sk_sp image) : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(image)) {} - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime).asHostObject(runtime)->getObject(); - } }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h index ab2756be3de52..2ccb32af0d626 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h @@ -18,7 +18,7 @@ class JsiSkImageFactory : public JsiSkHostObject { public: JSI_HOST_FUNCTION(MakeImageFromEncoded) { auto data = JsiSkData::fromValue(runtime, arguments[0]); - auto image = SkImage::MakeFromEncoded(data); + auto image = SkImages::DeferredFromEncodedData(data); if (image == nullptr) { return jsi::Value::null(); } @@ -30,7 +30,7 @@ class JsiSkImageFactory : public JsiSkHostObject { auto imageInfo = JsiSkImageInfo::fromValue(runtime, arguments[0]); auto pixelData = JsiSkData::fromValue(runtime, arguments[1]); auto bytesPerRow = arguments[2].asNumber(); - auto image = SkImage::MakeRasterData(*imageInfo, pixelData, bytesPerRow); + auto image = SkImages::RasterFromData(*imageInfo, pixelData, bytesPerRow); if (image == nullptr) { return jsi::Value::null(); } @@ -38,7 +38,36 @@ class JsiSkImageFactory : public JsiSkHostObject { runtime, std::make_shared(getContext(), std::move(image))); } + JSI_HOST_FUNCTION(MakeImageFromViewTag) { + auto viewTag = arguments[0].asNumber(); + auto context = getContext(); + return react::createPromiseAsJSIValue( + runtime, + [context = std::move(context), + viewTag](jsi::Runtime &runtime, + std::shared_ptr promise) -> void { + // Create a stream operation - this will be run on the main thread + context->makeViewScreenshot( + viewTag, [&runtime, context = std::move(context), + promise = std::move(promise)](sk_sp image) { + context->runOnJavascriptThread([&runtime, + context = std::move(context), + promise = std::move(promise), + result = std::move(image)]() { + if (result == nullptr) { + promise->reject("Failed to create image from view tag"); + return; + } + promise->resolve(jsi::Object::createFromHostObject( + runtime, std::make_shared( + std::move(context), std::move(result)))); + }); + }); + }); + } + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkImageFactory, MakeImageFromEncoded), + JSI_EXPORT_FUNC(JsiSkImageFactory, MakeImageFromViewTag), JSI_EXPORT_FUNC(JsiSkImageFactory, MakeImage), ) explicit JsiSkImageFactory(std::shared_ptr context) diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFilter.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFilter.h index c70fe83c7eb79..1969add100b75 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFilter.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFilter.h @@ -25,23 +25,7 @@ class JsiSkImageFilter : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(imageFilter)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "ImageFilter"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkImageFilter, - __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkImageFilter, "ImageFilter") }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMaskFilter.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMaskFilter.h index b382da6b909c0..664193d3ee83d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMaskFilter.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMaskFilter.h @@ -25,23 +25,7 @@ class JsiSkMaskFilter : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(maskFilter)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "MaskFilter"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkMaskFilter, - __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkMaskFilter, "MaskFilter") }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMatrix.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMatrix.h index ad17c1ea57949..262ab87da54aa 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMatrix.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMatrix.h @@ -40,46 +40,42 @@ class JsiSkMatrix : public JsiSkWrappingSharedPtrHostObject { pers0, pers1, pers2); } - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Matrix"); - } - JSI_HOST_FUNCTION(concat) { auto m3 = JsiSkMatrix::fromValue(runtime, arguments[0]); getObject()->preConcat(*m3); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(translate) { auto x = arguments[0].asNumber(); auto y = arguments[1].asNumber(); getObject()->preTranslate(x, y); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(scale) { auto x = arguments[0].asNumber(); auto y = count > 1 ? arguments[1].asNumber() : 1; getObject()->preScale(x, y); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(skew) { auto x = arguments[0].asNumber(); auto y = arguments[1].asNumber(); getObject()->preSkew(x, y); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(rotate) { auto a = arguments[0].asNumber(); getObject()->preRotate(SkRadiansToDegrees(a)); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(identity) { getObject()->setIdentity(); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(get) { @@ -90,7 +86,7 @@ class JsiSkMatrix : public JsiSkWrappingSharedPtrHostObject { return values; } - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkMatrix, __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkMatrix, "Matrix") JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkMatrix, concat), JSI_EXPORT_FUNC(JsiSkMatrix, translate), @@ -98,7 +94,8 @@ class JsiSkMatrix : public JsiSkWrappingSharedPtrHostObject { JSI_EXPORT_FUNC(JsiSkMatrix, skew), JSI_EXPORT_FUNC(JsiSkMatrix, rotate), JSI_EXPORT_FUNC(JsiSkMatrix, identity), - JSI_EXPORT_FUNC(JsiSkMatrix, get), ) + JSI_EXPORT_FUNC(JsiSkMatrix, get), + JSI_EXPORT_FUNC(JsiSkMatrix, dispose)) /** * Returns the underlying object from a host object of this type diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPaint.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPaint.h index 46f2a051afb4e..fdf54033f5f44 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPaint.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPaint.h @@ -5,13 +5,13 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "JsiSkColor.h" +#include "JsiSkColorFilter.h" +#include "JsiSkHostObjects.h" +#include "JsiSkImageFilter.h" +#include "JsiSkMaskFilter.h" +#include "JsiSkPathEffect.h" +#include "JsiSkShader.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -25,12 +25,7 @@ namespace jsi = facebook::jsi; class JsiSkPaint : public JsiSkWrappingSharedPtrHostObject { public: - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Paint"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkPaint, __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkPaint, "Paint") JSI_HOST_FUNCTION(copy) { const auto *paint = getObject().get(); @@ -183,7 +178,8 @@ class JsiSkPaint : public JsiSkWrappingSharedPtrHostObject { JSI_EXPORT_FUNC(JsiSkPaint, setStrokeWidth), JSI_EXPORT_FUNC(JsiSkPaint, setStyle), JSI_EXPORT_FUNC(JsiSkPaint, setColor), - JSI_EXPORT_FUNC(JsiSkPaint, setAlphaf)) + JSI_EXPORT_FUNC(JsiSkPaint, setAlphaf), + JSI_EXPORT_FUNC(JsiSkPaint, dispose)) JsiSkPaint(std::shared_ptr context, SkPaint paint) : JsiSkWrappingSharedPtrHostObject( @@ -196,14 +192,6 @@ class JsiSkPaint : public JsiSkWrappingSharedPtrHostObject { setObject(std::make_shared(std::move(paint))); } - /** - Returns the underlying object from a host object of this type - */ - static std::shared_ptr fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime).asHostObject(runtime)->getObject(); - } - /** * Creates the function for construction a new instance of the SkPaint * wrapper diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPath.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPath.h index f6f6daec9e77f..7938ca885f383 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPath.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPath.h @@ -7,6 +7,7 @@ #include #include "JsiSkHostObjects.h" +#include "JsiSkMatrix.h" #include "JsiSkPoint.h" #include "JsiSkRRect.h" #include "JsiSkRect.h" @@ -20,13 +21,12 @@ #include "SkPathEffect.h" #include "SkPathOps.h" #include "SkPathTypes.h" +#include "SkPathUtils.h" #include "SkString.h" #include "SkStrokeRec.h" #include "SkTextUtils.h" #include "SkTrimPathEffect.h" -#include "JsiSkMatrix.h" - #pragma clang diagnostic pop namespace RNSkia { @@ -36,11 +36,6 @@ namespace jsi = facebook::jsi; class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { public: - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Path"); - } - JSI_HOST_FUNCTION(addPath) { auto src = JsiSkPath::fromValue(runtime, arguments[0]); auto matrix = @@ -289,8 +284,11 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { auto jsiPrecision = opts.getProperty(runtime, "precision"); auto precision = jsiPrecision.isUndefined() ? 1 : jsiPrecision.asNumber(); - auto result = p.getFillPath(path, &path, nullptr, precision); - getObject()->swap(path); + auto result = + skpathutils::FillPathWithPaint(path, p, &path, nullptr, precision); + if (result) { + getObject()->swap(path); + } return result ? thisValue.getObject(runtime) : jsi::Value::null(); } @@ -325,8 +323,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { JSI_HOST_FUNCTION(toSVGString) { SkPath path = *getObject(); - SkString s; - SkParsePath::ToSVGString(path, &s); + auto s = SkParsePath::ToSVGString(path); return jsi::String::createFromUtf8(runtime, s.c_str()); } @@ -526,7 +523,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { return cmds; } - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkPath, __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkPath, "Path") JSI_EXPORT_FUNCTIONS( JSI_EXPORT_FUNC(JsiSkPath, addPath), JSI_EXPORT_FUNC(JsiSkPath, addArc), @@ -562,20 +559,12 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { JSI_EXPORT_FUNC(JsiSkPath, op), JSI_EXPORT_FUNC(JsiSkPath, isInterpolatable), JSI_EXPORT_FUNC(JsiSkPath, interpolate), - JSI_EXPORT_FUNC(JsiSkPath, toCmds), ) + JSI_EXPORT_FUNC(JsiSkPath, toCmds), JSI_EXPORT_FUNC(JsiSkPath, dispose)) JsiSkPath(std::shared_ptr context, SkPath path) : JsiSkWrappingSharedPtrHostObject( std::move(context), std::make_shared(std::move(path))) {} - /** - Returns the underlying object from a host object of this type - */ - static std::shared_ptr fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime).asHostObject(runtime)->getObject(); - } - static jsi::Value toValue(jsi::Runtime &runtime, std::shared_ptr context, const SkPath &path) { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathEffect.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathEffect.h index 3e410db89c571..925dd46441946 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathEffect.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathEffect.h @@ -25,23 +25,8 @@ class JsiSkPathEffect : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(pathEffect)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "PathEffect"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkPathEffect, - __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkPathEffect, "PathEffect") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkColorFilter, dispose)) }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathFactory.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathFactory.h index d7bccf42f8892..143ef95bffaa4 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathFactory.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathFactory.h @@ -11,9 +11,9 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" +#include "RNSkLog.h" #include "SkPath.h" #include "SkPathOps.h" -#include #pragma clang diagnostic pop diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPicture.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPicture.h index a38383e1ef637..1c375e0fe53c9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPicture.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPicture.h @@ -2,9 +2,9 @@ #include +#include "JsiSkData.h" #include "JsiSkHostObjects.h" -#include -#include +#include "JsiSkShader.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -23,12 +23,6 @@ class JsiSkPicture : public JsiSkWrappingSkPtrHostObject { const sk_sp picture) : JsiSkWrappingSkPtrHostObject(context, picture) {} - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Picture"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkPicture, __typename__)) - JSI_HOST_FUNCTION(makeShader) { auto tmx = (SkTileMode)arguments[0].asNumber(); auto tmy = (SkTileMode)arguments[1].asNumber(); @@ -66,18 +60,10 @@ class JsiSkPicture : public JsiSkWrappingSkPtrHostObject { return array; } + EXPORT_JSI_API_TYPENAME(JsiSkPicture, "Picture") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPicture, makeShader), - JSI_EXPORT_FUNC(JsiSkPicture, serialize)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - .get() - ->getObject(); - } + JSI_EXPORT_FUNC(JsiSkPicture, serialize), + JSI_EXPORT_FUNC(JsiSkPicture, dispose)) }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPictureRecorder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPictureRecorder.h index c8561127261a0..fc8601020595f 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPictureRecorder.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPictureRecorder.h @@ -40,9 +40,12 @@ class JsiSkPictureRecorder runtime, std::make_shared(getContext(), picture)); } + EXPORT_JSI_API_TYPENAME(JsiSkPictureRecorder, "PictureRecorder") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPictureRecorder, beginRecording), JSI_EXPORT_FUNC(JsiSkPictureRecorder, - finishRecordingAsPicture)) + finishRecordingAsPicture), + JSI_EXPORT_FUNC(JsiSkPictureRecorder, dispose)) static const jsi::HostFunctionType createCtor(std::shared_ptr context) { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPoint.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPoint.h index 660f01087e69c..d14593d93992c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPoint.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPoint.h @@ -24,8 +24,13 @@ class JsiSkPoint : public JsiSkWrappingSharedPtrHostObject { JSI_PROPERTY_GET(y) { return static_cast(getObject()->y()); } + JSI_API_TYPENAME("Point"); + JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkPoint, x), - JSI_EXPORT_PROP_GET(JsiSkPoint, y)) + JSI_EXPORT_PROP_GET(JsiSkPoint, y), + JSI_EXPORT_PROP_GET(JsiSkPoint, __typename__)) + + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPoint, dispose)) JsiSkPoint(std::shared_ptr context, const SkPoint &point) : JsiSkWrappingSharedPtrHostObject( diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRRect.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRRect.h index 73ac73121350a..b77c48a683592 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRRect.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRRect.h @@ -34,9 +34,14 @@ class JsiSkRRect : public JsiSkWrappingSharedPtrHostObject { std::make_shared(getContext(), getObject()->getBounds())); } + JSI_API_TYPENAME("RRect"); + JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkRRect, rx), JSI_EXPORT_PROP_GET(JsiSkRRect, ry), - JSI_EXPORT_PROP_GET(JsiSkRRect, rect)) + JSI_EXPORT_PROP_GET(JsiSkRRect, rect), + JSI_EXPORT_PROP_GET(JsiSkRRect, __typename__)) + + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRRect, dispose)) JsiSkRRect(std::shared_ptr context, const SkRRect &rect) : JsiSkWrappingSharedPtrHostObject( diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRSXform.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRSXform.h index 5fd43fcb59053..2d4e69092fcc3 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRSXform.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRSXform.h @@ -25,11 +25,7 @@ class JsiSkRSXform : public JsiSkWrappingSharedPtrHostObject { : JsiSkWrappingSharedPtrHostObject( std::move(context), std::make_shared(rsxform)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "RSXform"); - } + JSI_API_TYPENAME("RSXform"); JSI_PROPERTY_GET(scos) { return jsi::Value(SkScalarToDouble(getObject()->fSCos)); @@ -48,7 +44,9 @@ class JsiSkRSXform : public JsiSkWrappingSharedPtrHostObject { JSI_EXPORT_PROP_GET(JsiSkRSXform, scos), JSI_EXPORT_PROP_GET(JsiSkRSXform, ssin), JSI_EXPORT_PROP_GET(JsiSkRSXform, tx), - JSI_EXPORT_PROP_GET(JsiSkRSXform, ty), ) + JSI_EXPORT_PROP_GET(JsiSkRSXform, ty)) + + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRSXform, dispose)) /** Returns the underlying object from a host object of this type diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRect.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRect.h index 2d74f6f554955..c37a042f8db2e 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRect.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRect.h @@ -33,10 +33,13 @@ class JsiSkRect : public JsiSkWrappingSharedPtrHostObject { return static_cast(getObject()->bottom()); } + JSI_API_TYPENAME("Rect"); + JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkRect, x), JSI_EXPORT_PROP_GET(JsiSkRect, y), JSI_EXPORT_PROP_GET(JsiSkRect, width), - JSI_EXPORT_PROP_GET(JsiSkRect, height)) + JSI_EXPORT_PROP_GET(JsiSkRect, height), + JSI_EXPORT_PROP_GET(JsiSkRect, __typename__)) JSI_HOST_FUNCTION(setXYWH) { getObject()->setXYWH(arguments[0].asNumber(), arguments[1].asNumber(), @@ -51,7 +54,8 @@ class JsiSkRect : public JsiSkWrappingSharedPtrHostObject { } JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRect, setXYWH), - JSI_EXPORT_FUNC(JsiSkRect, setLTRB), ) + JSI_EXPORT_FUNC(JsiSkRect, setLTRB), + JSI_EXPORT_FUNC(JsiSkRect, dispose)) /** Constructor diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeEffect.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeEffect.h index 8987d206812a6..698a01a37e3f1 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeEffect.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeEffect.h @@ -5,9 +5,9 @@ #include #include -#include -#include -#include +#include "JsiSkHostObjects.h" +#include "JsiSkMatrix.h" +#include "JsiSkShader.h" #include @@ -32,12 +32,6 @@ struct RuntimeEffectUniform { class JsiSkRuntimeEffect : public JsiSkWrappingSkPtrHostObject { public: - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - const auto &object = obj.asObject(runtime); - return object.asHostObject(runtime)->getObject(); - } - JSI_HOST_FUNCTION(makeShader) { auto uniforms = castUniforms(runtime, arguments[0]); @@ -121,6 +115,8 @@ class JsiSkRuntimeEffect return jsi::String::createFromAscii(runtime, getObject()->source()); } + EXPORT_JSI_API_TYPENAME(JsiSkRuntimeEffect, "RuntimeEffect") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeEffect, makeShader), JSI_EXPORT_FUNC(JsiSkRuntimeEffect, makeShaderWithChildren), @@ -129,7 +125,8 @@ class JsiSkRuntimeEffect getUniformFloatCount), JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformName), JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniform), - JSI_EXPORT_FUNC(JsiSkRuntimeEffect, source)) + JSI_EXPORT_FUNC(JsiSkRuntimeEffect, source), + JSI_EXPORT_FUNC(JsiSkRuntimeEffect, dispose)) JsiSkRuntimeEffect(std::shared_ptr context, sk_sp rt) diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeShaderBuilder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeShaderBuilder.h index d51126b6aa631..99deecdb67f8d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeShaderBuilder.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeShaderBuilder.h @@ -47,16 +47,8 @@ class JsiSkRuntimeShaderBuilder return jsi::Value::undefined(); } - JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeShaderBuilder, setUniform)) - - /** - Returns the underlying object from a host object of this type - */ - static std::shared_ptr - fromValue(jsi::Runtime &runtime, const jsi::Value &obj) { - const auto &object = obj.asObject(runtime); - return object.asHostObject(runtime)->getObject(); - } + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeShaderBuilder, setUniform), + JSI_EXPORT_FUNC(JsiSkRuntimeShaderBuilder, dispose)) /** Returns the jsi object from a host object of this type diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSVG.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSVG.h index 1838965f2b826..e715481181b2c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSVG.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSVG.h @@ -5,7 +5,7 @@ #include -#include +#include "JsiSkHostObjects.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -24,11 +24,19 @@ class JsiSkSVG : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(svgdom)) {} - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "SVG"); + EXPORT_JSI_API_TYPENAME(JsiSkSVG, "SVG") + + JSI_HOST_FUNCTION(width) { + return static_cast(getObject()->containerSize().width()); + } + + JSI_HOST_FUNCTION(height) { + return static_cast(getObject()->containerSize().height()); } - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkSVG, __typename__)) + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSVG, width), + JSI_EXPORT_FUNC(JsiSkSVG, height), + JSI_EXPORT_FUNC(JsiSkSVG, dispose)) /** Returns the underlying object from a host object of this type diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkShader.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkShader.h index 2dd3f77746c40..eee6753e9f7bf 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkShader.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkShader.h @@ -5,7 +5,7 @@ #include -#include +#include "JsiSkHostObjects.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -26,21 +26,7 @@ class JsiSkShader : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(shader)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Shader"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkShader, __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkShader, "Shader") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkShader, dispose)) }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurface.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurface.h index f4ddaf9ab0858..0ea0d1820450b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurface.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurface.h @@ -7,9 +7,9 @@ #include "JsiSkHostObjects.h" -#include -#include -#include +#include "JsiSkCanvas.h" +#include "JsiSkImage.h" +#include "JsiSkSurfaceFactory.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -29,10 +29,7 @@ class JsiSkSurface : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(surface)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Surface"); - } + EXPORT_JSI_API_TYPENAME(JsiSkSurface, "Surface") JSI_HOST_FUNCTION(getCanvas) { return jsi::Object::createFromHostObject( @@ -40,6 +37,11 @@ class JsiSkSurface : public JsiSkWrappingSkPtrHostObject { std::make_shared(getContext(), getObject()->getCanvas())); } + JSI_HOST_FUNCTION(flush) { + getObject()->flush(); + return jsi::Value::undefined(); + } + JSI_HOST_FUNCTION(makeImageSnapshot) { sk_sp image; if (count == 1) { @@ -53,19 +55,10 @@ class JsiSkSurface : public JsiSkWrappingSkPtrHostObject { runtime, std::make_shared(getContext(), std::move(image))); } - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkSurface, __typename__)) JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurface, getCanvas), - JSI_EXPORT_FUNC(JsiSkSurface, makeImageSnapshot)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + JSI_EXPORT_FUNC(JsiSkSurface, makeImageSnapshot), + JSI_EXPORT_FUNC(JsiSkSurface, flush), + JSI_EXPORT_FUNC(JsiSkSurface, dispose)) }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurfaceFactory.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurfaceFactory.h index e068b6bbc3437..1f83f8b8f0302 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurfaceFactory.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurfaceFactory.h @@ -7,12 +7,11 @@ #include "JsiSkHostObjects.h" -#include +#include "JsiSkSurface.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include "SkImage.h" #include "SkSurface.h" #pragma clang diagnostic pop @@ -35,7 +34,21 @@ class JsiSkSurfaceFactory : public JsiSkHostObject { std::make_shared(getContext(), std::move(surface))); } - JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurfaceFactory, Make)) + JSI_HOST_FUNCTION(MakeOffscreen) { + auto width = static_cast(arguments[0].asNumber()); + auto height = static_cast(arguments[1].asNumber()); + auto context = getContext(); + auto surface = context->makeOffscreenSurface(width, height); + if (surface == nullptr) { + return jsi::Value::null(); + } + return jsi::Object::createFromHostObject( + runtime, + std::make_shared(getContext(), std::move(surface))); + } + + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurfaceFactory, Make), + JSI_EXPORT_FUNC(JsiSkSurfaceFactory, MakeOffscreen)) explicit JsiSkSurfaceFactory(std::shared_ptr context) : JsiSkHostObject(std::move(context)) {} diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTextBlob.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTextBlob.h index e4c2f68888b2e..9874f888e9a03 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTextBlob.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTextBlob.h @@ -25,23 +25,7 @@ class JsiSkTextBlob : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(shader)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "TextBlob"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkTextBlob, - __typename__), ) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkTextBlob, "TextBlob") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTextBlob, dispose)) }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTypeface.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTypeface.h index 0e52d7c7a4f25..e043543212edd 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTypeface.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTypeface.h @@ -6,7 +6,7 @@ #include #include "JsiSkHostObjects.h" -#include +#include "RNSkLog.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -22,27 +22,13 @@ namespace jsi = facebook::jsi; class JsiSkTypeface : public JsiSkWrappingSkPtrHostObject { public: - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Typeface"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkTypeface, __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkTypeface, "Typeface") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTypeface, dispose)) JsiSkTypeface(std::shared_ptr context, sk_sp typeface) : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(typeface)) {} - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } - /** Returns the jsi object from a host object of this type */ diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkVertices.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkVertices.h index e1cf0ba7777fb..8c84a0abcf9b2 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkVertices.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkVertices.h @@ -25,12 +25,7 @@ class JsiSkVertices : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(vertices)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Vertices"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkVertices, __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkVertices, "Vertices") JSI_HOST_FUNCTION(bounds) { const auto &result = getObject()->bounds(); @@ -43,17 +38,8 @@ class JsiSkVertices : public JsiSkWrappingSkPtrHostObject { } JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkVertices, bounds), - JSI_EXPORT_FUNC(JsiSkVertices, uniqueID), ) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + JSI_EXPORT_FUNC(JsiSkVertices, uniqueID), + JSI_EXPORT_FUNC(JsiSkVertices, dispose)) /** * Creates the function for construction a new instance of the SkVertices diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.cpp b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.cpp index 3e4a67ba1f0b6..684168de1d6f8 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.cpp +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.cpp @@ -55,12 +55,18 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime, const jsi::PropNameID &name) { auto nameStr = name.utf8(runtime); - // Do the happy-paths first + // Happy path - cached host functions are cheapest to look up + const JsiFunctionMap &funcs = getExportedFunctionMap(); + auto func = funcs.find(nameStr); // Check function cache - auto cachedFunc = _hostFunctionCache.find(nameStr); - if (cachedFunc != _hostFunctionCache.end()) { - return cachedFunc->second.asFunction(runtime); + if (func != funcs.end()) { + std::map &runtimeCache = + _hostFunctionCache.get(runtime); + auto cachedFunc = runtimeCache.find(nameStr); + if (cachedFunc != runtimeCache.end()) { + return cachedFunc->second.asFunction(runtime); + } } // Check the static getters map @@ -72,9 +78,9 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime, } // Check the static function map - const JsiFunctionMap &funcs = getExportedFunctionMap(); - auto func = funcs.find(nameStr); if (func != funcs.end()) { + + // Create dispatcher auto dispatcher = std::bind(func->second, reinterpret_cast(this), std::placeholders::_1, std::placeholders::_2, @@ -82,7 +88,7 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime, // Add to cache - it is important to cache the results from the // createFromHostFunction function which takes some time. - return _hostFunctionCache + return _hostFunctionCache.get(runtime) .emplace(nameStr, jsi::Function::createFromHostFunction(runtime, name, 0, dispatcher)) .first->second.asFunction(runtime); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.h index 4a96b48c4706c..79c1fe42441f4 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.h @@ -9,6 +9,8 @@ #include #include +#include "RuntimeAwareCache.h" + #define STR_CAT_NX(A, B) A##B #define STR_CAT(A, B) STR_CAT_NX(A, B) #define STR_GET get_ @@ -363,6 +365,6 @@ class JsiHostObject : public jsi::HostObject { std::unordered_map _funcMap; std::unordered_map _propMap; - std::map _hostFunctionCache; + RuntimeAwareCache> _hostFunctionCache; }; } // namespace RNJsi diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.cpp b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.cpp new file mode 100644 index 0000000000000..ec9d5bad74242 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.cpp @@ -0,0 +1,7 @@ +#include "RuntimeAwareCache.h" + +namespace RNJsi { + +jsi::Runtime *BaseRuntimeAwareCache::_mainRuntime = nullptr; + +} // namespace RNJsi diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.h new file mode 100644 index 0000000000000..2b5f16b53af7e --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.h @@ -0,0 +1,101 @@ +#pragma once + +#include + +#include +#include +#include + +#include "RuntimeLifecycleMonitor.h" + +namespace RNJsi { + +namespace jsi = facebook::jsi; + +class BaseRuntimeAwareCache { +public: + static void setMainJsRuntime(jsi::Runtime *rt) { _mainRuntime = rt; } + +protected: + static jsi::Runtime *getMainJsRuntime() { + assert(_mainRuntime != nullptr && + "Expected main Javascript runtime to be set in the " + "BaseRuntimeAwareCache class."); + + return _mainRuntime; + } + +private: + static jsi::Runtime *_mainRuntime; +}; + +/** + * Provides a way to keep data specific to a jsi::Runtime instance that gets + * cleaned up when that runtime is destroyed. This is necessary because JSI does + * not allow for its associated objects to be retained past the runtime + * lifetime. If an object (e.g. jsi::Values or jsi::Function instances) is kept + * after the runtime is torn down, its destructor (once it is destroyed + * eventually) will result in a crash (JSI objects keep a pointer to memory + * managed by the runtime, accessing that portion of the memory after runtime is + * deleted is the root cause of that crash). + * + * In order to provide an efficient implementation that does not add an overhead + * for the cases when only a single runtiome is used, which is the primary + * usecase, the following assumption has been made: Only for secondary runtimes + * we track destruction and clean up the store associated with that runtime. For + * the first runtime we assume that the object holding the store is destroyed + * prior to the destruction of that runtime. + * + * The above assumption makes it work without any overhead when only single + * runtime is in use. Specifically, we don't perform any additional operations + * related to tracking runtime lifecycle when only a single runtime is used. + */ +template +class RuntimeAwareCache : public BaseRuntimeAwareCache, + public RuntimeLifecycleListener { + +public: + void onRuntimeDestroyed(jsi::Runtime *rt) override { + if (getMainJsRuntime() != rt) { + // We are removing a secondary runtime + _secondaryRuntimeCaches.erase(rt); + } + } + + ~RuntimeAwareCache() { + for (auto &cache : _secondaryRuntimeCaches) { + RuntimeLifecycleMonitor::removeListener( + *static_cast(cache.first), this); + } + } + + T &get(jsi::Runtime &rt) { + // We check if we're accessing the main runtime - this is the happy path + // to avoid us having to lookup by runtime for caches that only has a single + // runtime + if (getMainJsRuntime() == &rt) { + return _primaryCache; + } else { + if (_secondaryRuntimeCaches.count(&rt) == 0) { + // we only add listener when the secondary runtime is used, this assumes + // that the secondary runtime is terminated first. This lets us avoid + // additional complexity for the majority of cases when objects are not + // shared between runtimes. Otherwise we'd have to register all objecrts + // with the RuntimeMonitor as opposed to only registering ones that are + // used in secondary runtime. Note that we can't register listener here + // with the primary runtime as it may run on a separate thread. + RuntimeLifecycleMonitor::addListener(rt, this); + + T cache; + _secondaryRuntimeCaches.emplace(&rt, std::move(cache)); + } + } + return _secondaryRuntimeCaches.at(&rt); + } + +private: + std::unordered_map _secondaryRuntimeCaches; + T _primaryCache; +}; + +} // namespace RNJsi diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.cpp b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.cpp new file mode 100644 index 0000000000000..d94b3717c5eac --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.cpp @@ -0,0 +1,57 @@ +#include "RuntimeLifecycleMonitor.h" + +#include +#include +#include + +namespace RNJsi { + +static std::unordered_map> + listeners; + +struct RuntimeLifecycleMonitorObject : public jsi::HostObject { + jsi::Runtime *_rt; + explicit RuntimeLifecycleMonitorObject(jsi::Runtime *rt) : _rt(rt) {} + ~RuntimeLifecycleMonitorObject() { + auto listenersSet = listeners.find(_rt); + if (listenersSet != listeners.end()) { + for (auto listener : listenersSet->second) { + listener->onRuntimeDestroyed(_rt); + } + listeners.erase(listenersSet); + } + } +}; + +void RuntimeLifecycleMonitor::addListener(jsi::Runtime &rt, + RuntimeLifecycleListener *listener) { + auto listenersSet = listeners.find(&rt); + if (listenersSet == listeners.end()) { + // We install a global host object in the provided runtime, this way we can + // use that host object destructor to get notified when the runtime is being + // terminated. We use a unique name for the object as it gets saved with the + // runtime's global object. + rt.global().setProperty( + rt, "__rnskia_rt_lifecycle_monitor", + jsi::Object::createFromHostObject( + rt, std::make_shared(&rt))); + std::unordered_set newSet; + newSet.insert(listener); + listeners.emplace(&rt, std::move(newSet)); + } else { + listenersSet->second.insert(listener); + } +} + +void RuntimeLifecycleMonitor::removeListener( + jsi::Runtime &rt, RuntimeLifecycleListener *listener) { + auto listenersSet = listeners.find(&rt); + if (listenersSet == listeners.end()) { + // nothing to do here + } else { + listenersSet->second.erase(listener); + } +} + +} // namespace RNJsi diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.h new file mode 100644 index 0000000000000..baec54f51a4de --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.h @@ -0,0 +1,32 @@ +#pragma once + +#include + +#include + +namespace RNJsi { + +namespace jsi = facebook::jsi; + +/** + * Listener interface that allows for getting notified when a jsi::Runtime + * instance is destroyed. + */ +struct RuntimeLifecycleListener { + virtual ~RuntimeLifecycleListener() {} + virtual void onRuntimeDestroyed(jsi::Runtime *) = 0; +}; + +/** + * This class provides an API via static methods for registering and + * unregistering runtime lifecycle listeners. The listeners can be used to + * cleanup any data that references a given jsi::Runtime instance before it gets + * destroyed. + */ +struct RuntimeLifecycleMonitor { + static void addListener(jsi::Runtime &rt, RuntimeLifecycleListener *listener); + static void removeListener(jsi::Runtime &rt, + RuntimeLifecycleListener *listener); +}; + +} // namespace RNJsi diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkAnimation.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkAnimation.h index 87ee94e8192c7..9abd4418b57f4 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkAnimation.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkAnimation.h @@ -3,9 +3,9 @@ #include #include -#include -#include -#include +#include "JsiHostObject.h" +#include "RNSkClockValue.h" +#include "RNSkPlatformContext.h" #include namespace RNSkia { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.cpp b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.cpp index 6762a0e47ed0f..9226a5649bb80 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.cpp +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.cpp @@ -22,7 +22,7 @@ RNSkDomRenderer::RNSkDomRenderer(std::function requestRedraw, RNSkDomRenderer::~RNSkDomRenderer() { if (_root != nullptr) { - _root->dispose(); + _root->dispose(true); _root = nullptr; } } @@ -63,7 +63,7 @@ void RNSkDomRenderer::renderImmediate( void RNSkDomRenderer::setRoot(std::shared_ptr node) { std::lock_guard lock(_rootLock); if (_root != nullptr) { - _root->dispose(); + _root->dispose(true); _root = nullptr; } _root = node; @@ -79,14 +79,12 @@ void RNSkDomRenderer::renderCanvas(SkCanvas *canvas, float scaledWidth, _renderTimingInfo.beginTiming(); auto pd = _platformContext->getPixelDensity(); - + canvas->clear(SK_ColorTRANSPARENT); canvas->save(); canvas->scale(pd, pd); if (_drawingContext == nullptr) { - auto paint = std::make_shared(); - paint->setAntiAlias(true); - _drawingContext = std::make_shared(paint); + _drawingContext = std::make_shared(); _drawingContext->setRequestRedraw([weakSelf = weak_from_this()]() { auto self = weakSelf.lock(); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.h index 12e246f387f1d..5832d3dbcfbb6 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.h @@ -9,21 +9,21 @@ #include -#include -#include +#include "JsiValueWrapper.h" +#include "RNSkView.h" #include "JsiDomRenderNode.h" -#include -#include -#include -#include +#include "RNSkInfoParameter.h" +#include "RNSkLog.h" +#include "RNSkPlatformContext.h" +#include "RNSkTimingInfo.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include -#include -#include +#include "SkBBHFactory.h" +#include "SkCanvas.h" +#include "SkPictureRecorder.h" #pragma clang diagnostic pop diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkInfoParameter.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkInfoParameter.h index 49a3ad2c9cedb..aa981d63a3b8a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkInfoParameter.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkInfoParameter.h @@ -8,8 +8,8 @@ #include -#include -#include +#include "JsiHostObject.h" +#include "RNSkView.h" namespace RNSkia { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.cpp b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.cpp index facdc0a775271..3c4abb892f398 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.cpp +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.cpp @@ -8,7 +8,7 @@ RNSkJsRenderer::RNSkJsRenderer(std::function requestRedraw, std::shared_ptr context) : RNSkRenderer(requestRedraw), _jsiCanvas(std::make_shared(context)), - _platformContext(std::move(context)), + _platformContext(context), _infoObject(std::make_shared()), _jsDrawingLock(std::make_shared()), _gpuDrawingLock(std::make_shared()), @@ -197,11 +197,14 @@ void RNSkJsRenderer::drawInJsiCanvas(std::shared_ptr jsiCanvas, if (_drawCallback != nullptr && skCanvas != nullptr) { // Make sure to scale correctly auto pd = _platformContext->getPixelDensity(); + skCanvas->clear(SK_ColorTRANSPARENT); skCanvas->save(); skCanvas->scale(pd, pd); // Call draw function. callJsDrawCallback(jsiCanvas, width / pd, height / pd, time); + + skCanvas->restore(); } } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.h index 71e65e2ba8489..f286682d13c0a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.h @@ -9,14 +9,14 @@ #include -#include -#include - -#include -#include -#include -#include -#include +#include "JsiValueWrapper.h" +#include "RNSkView.h" + +#include "JsiSkCanvas.h" +#include "RNSkInfoParameter.h" +#include "RNSkLog.h" +#include "RNSkPlatformContext.h" +#include "RNSkTimingInfo.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsiViewApi.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsiViewApi.h index eb4a97628370c..5096c6dfc288f 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsiViewApi.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsiViewApi.h @@ -7,11 +7,11 @@ #include #include -#include -#include -#include -#include -#include +#include "JsiHostObject.h" +#include "JsiValueWrapper.h" +#include "RNSkPlatformContext.h" +#include "RNSkValue.h" +#include "RNSkView.h" #include namespace RNSkia { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkManager.cpp b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkManager.cpp index 5bb6b11fd4ec4..819e491d66ba6 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkManager.cpp +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkManager.cpp @@ -11,6 +11,7 @@ #include #include +#include namespace RNSkia { namespace jsi = facebook::jsi; @@ -23,6 +24,9 @@ RNSkManager::RNSkManager( _platformContext(platformContext), _viewApi(std::make_shared(platformContext)) { + // Register main runtime + BaseRuntimeAwareCache::setMainJsRuntime(_jsRuntime); + // Install bindings installBindings(); } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPictureView.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPictureView.h index 666f83f6f4edd..71cd91e023274 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPictureView.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPictureView.h @@ -9,14 +9,14 @@ #include -#include -#include +#include "JsiValueWrapper.h" +#include "RNSkView.h" -#include -#include -#include -#include -#include +#include "JsiSkPicture.h" +#include "RNSkInfoParameter.h" +#include "RNSkLog.h" +#include "RNSkPlatformContext.h" +#include "RNSkTimingInfo.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -72,10 +72,13 @@ class RNSkPictureRenderer canvasProvider->renderToCanvas([=](SkCanvas *canvas) { // Make sure to scale correctly auto pd = _platformContext->getPixelDensity(); + canvas->clear(SK_ColorTRANSPARENT); canvas->save(); canvas->scale(pd, pd); canvas->drawPicture(_picture->getObject()); + + canvas->restore(); }); } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPlatformContext.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPlatformContext.h index 1b008a3f74a2b..f7f9827d40d85 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPlatformContext.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPlatformContext.h @@ -9,12 +9,15 @@ #include #include -#include +#include "RNSkDispatchQueue.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" +#include "SkData.h" +#include "SkImage.h" #include "SkStream.h" +#include "SkSurface.h" #pragma clang diagnostic pop @@ -87,6 +90,18 @@ class RNSkPlatformContext { _dispatchQueue->dispatch(std::move(func)); } + /** + * Runs the passed function on the main thread + * @param func Function to run. + */ + virtual void runOnMainThread(std::function func) = 0; + + /** + * Takes a screenshot of a given view represented by the view tag + * @param tag React view tag + */ + virtual sk_sp takeScreenshotFromViewTag(size_t tag) = 0; + /** Returns the javascript runtime */ @@ -109,6 +124,29 @@ class RNSkPlatformContext { */ virtual void raiseError(const std::exception &err) = 0; + /** + * Creates an offscreen surface + * @param width Width of the offscreen surface + * @param height Height of the offscreen surface + * @return sk_sp + */ + virtual sk_sp makeOffscreenSurface(int width, int height) = 0; + + /** + * Creates an skImage containing the screenshot of a native view and its + * children. + * @param viewTag React viewtag + * @param callback Called when image is ready or with null if something + * failed. + */ + virtual void + makeViewScreenshot(int viewTag, + std::function)> callback) { + runOnMainThread([this, callback, viewTag]() { + callback(takeScreenshotFromViewTag(viewTag)); + }); + } + /** * Raises an exception on the platform. This function does not necessarily * throw an exception and stop execution, so it is important to stop execution diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkValueApi.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkValueApi.h index facc0d6343c3a..302f9755db2b9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkValueApi.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkValueApi.h @@ -2,11 +2,11 @@ #include -#include -#include -#include -#include -#include +#include "JsiHostObject.h" +#include "RNSkAnimation.h" +#include "RNSkComputedValue.h" +#include "RNSkPlatformContext.h" +#include "RNSkValue.h" #include namespace RNSkia { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkView.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkView.h index d93f7a41cbdf7..ba52e1fec8924 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkView.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkView.h @@ -6,13 +6,13 @@ #include #include -#include -#include -#include +#include "JsiValueWrapper.h" +#include "RNSkPlatformContext.h" +#include "RNSkValue.h" -#include -#include -#include +#include "JsiSkImage.h" +#include "JsiSkPoint.h" +#include "JsiSkRect.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -88,23 +88,26 @@ class RNSkRenderer { class RNSkImageCanvasProvider : public RNSkCanvasProvider { public: - RNSkImageCanvasProvider(std::function requestRedraw, float width, + RNSkImageCanvasProvider(std::shared_ptr context, + std::function requestRedraw, float width, float height) : RNSkCanvasProvider(requestRedraw), _width(width), _height(height) { - _surface = SkSurface::MakeRasterN32Premul(_width, _height); + _surface = context->makeOffscreenSurface(_width, _height); } /** Returns a snapshot of the current surface/canvas */ sk_sp makeSnapshot(std::shared_ptr bounds) { + sk_sp image; if (bounds != nullptr) { SkIRect b = SkIRect::MakeXYWH(bounds->x(), bounds->y(), bounds->width(), bounds->height()); - return _surface->makeImageSnapshot(b); + image = _surface->makeImageSnapshot(b); } else { - return _surface->makeImageSnapshot(); + image = _surface->makeImageSnapshot(); } + return image->makeNonTextureImage(); } /** @@ -261,8 +264,9 @@ class RNSkView : public std::enable_shared_from_this { Renders the view into an SkImage instead of the screen. */ sk_sp makeImageSnapshot(std::shared_ptr bounds) { + auto provider = std::make_shared( - std::bind(&RNSkView::requestRedraw, this), + getPlatformContext(), std::bind(&RNSkView::requestRedraw, this), _canvasProvider->getScaledWidth(), _canvasProvider->getScaledHeight()); _renderer->renderImmediate(provider); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/JsiDomApi.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/JsiDomApi.h index 2d5731fbcd91d..8a84498b06608 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/JsiDomApi.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/JsiDomApi.h @@ -2,6 +2,7 @@ /* Enable output of dom trees and paint contexts */ #define SKIA_DOM_DEBUG 0 +#define SKIA_DOM_DEBUG_VERBOSE 0 #include diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.cpp b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.cpp new file mode 100644 index 0000000000000..1f56372a0dd47 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.cpp @@ -0,0 +1,117 @@ +#include "ConcatablePaint.h" + +#include "DeclarationContext.h" +#include "JsiDomNode.h" +#include "PaintProps.h" + +namespace RNSkia { + +ConcatablePaint::ConcatablePaint( + DeclarationContext *declarationContext, PaintProps *paintProps, + const std::vector> &children) + : _declarationContext(declarationContext), _paintProps(paintProps), + _children(children) { + + auto hasPropertyValues = _paintProps->getColor()->isSet() || + _paintProps->getStrokeWidth()->isSet() || + _paintProps->getBlendMode()->isSet() || + _paintProps->getStyle()->isSet() || + _paintProps->getStrokeJoin()->isSet() || + _paintProps->getStrokeCap()->isSet() || + _paintProps->getStrokeMiter()->isSet() || + _paintProps->getOpacity()->isSet() || + _paintProps->getAntiAlias()->isSet(); + + _declarationContext->save(); + + for (auto &child : _children) { + child->decorateContext(_declarationContext); + } + + _imageFilter = declarationContext->getImageFilters()->popAsOne(); + _colorFilter = declarationContext->getColorFilters()->popAsOne(); + _shader = declarationContext->getShaders()->pop(); + _maskFilter = declarationContext->getMaskFilters()->pop(); + _pathEffect = declarationContext->getPathEffects()->popAsOne(); + + _declarationContext->restore(); + + _isEmpty = !hasPropertyValues && _imageFilter == nullptr && + _colorFilter == nullptr && _shader == nullptr && + _maskFilter == nullptr && _pathEffect == nullptr; +} + +bool ConcatablePaint::isEmpty() { return _isEmpty; } + +void ConcatablePaint::concatTo(std::shared_ptr paint) { + + if (_paintProps->getOpacity()->isSet()) { + paint->setAlphaf(paint->getAlphaf() * + _paintProps->getOpacity()->value().getAsNumber()); + } + + if (_paintProps->getColor()->isSet()) { + auto currentOpacity = paint->getAlphaf(); + paint->setShader(nullptr); + paint->setColor(*_paintProps->getColor()->getDerivedValue()); + paint->setAlphaf(paint->getAlphaf() * currentOpacity); + } + + if (_paintProps->getStrokeWidth()->isSet()) { + paint->setStrokeWidth(_paintProps->getStrokeWidth()->value().getAsNumber()); + } + + if (_paintProps->getBlendMode()->isSet()) { + paint->setBlendMode(*_paintProps->getBlendMode()->getDerivedValue()); + } + + if (_paintProps->getStyle()->isSet()) { + auto styleValue = _paintProps->getStyle()->value().getAsString(); + if (styleValue == "stroke") { + paint->setStyle(SkPaint::Style::kStroke_Style); + } else if (styleValue == "fill") { + paint->setStyle(SkPaint::Style::kFill_Style); + } else { + throw std::runtime_error(styleValue + + " is not a valud value for the style property."); + } + } + + if (_paintProps->getStrokeJoin()->isSet()) { + paint->setStrokeJoin(*_paintProps->getStrokeJoin()->getDerivedValue()); + } + + if (_paintProps->getStrokeCap()->isSet()) { + paint->setStrokeCap(*_paintProps->getStrokeCap()->getDerivedValue()); + } + + if (_paintProps->getStrokeMiter()->isSet()) { + paint->setStrokeMiter(_paintProps->getStrokeMiter()->value().getAsNumber()); + } + + if (_paintProps->getAntiAlias()->isSet()) { + paint->setAntiAlias(_paintProps->getAntiAlias()->value().getAsBool()); + } + + if (_imageFilter) { + paint->setImageFilter(_imageFilter); + } + + if (_colorFilter) { + paint->setColorFilter(_colorFilter); + } + + if (_shader) { + paint->setShader(_shader); + } + + if (_maskFilter) { + paint->setMaskFilter(_maskFilter); + } + + if (_pathEffect) { + paint->setPathEffect(_pathEffect); + } +} + +} // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.h new file mode 100644 index 0000000000000..dd4c2f0b52bdb --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.h @@ -0,0 +1,49 @@ +#pragma once + +#include +#include + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdocumentation" + +#include "SkColorFilter.h" +#include "SkImageFilter.h" +#include "SkMaskFilter.h" +#include "SkPaint.h" +#include "SkPathEffect.h" +#include "SkShader.h" + +#pragma clang diagnostic pop + +namespace RNSkia { + +class JsiDomNode; +class PaintProps; +class DeclarationContext; + +/** + Class for concatenating SkPaint objects. + */ +class ConcatablePaint { +public: + ConcatablePaint(DeclarationContext *context, PaintProps *paintProps, + const std::vector> &children); + + void concatTo(std::shared_ptr paint); + bool isEmpty(); + +private: + DeclarationContext *_declarationContext; + const std::vector> _children; + PaintProps *_paintProps; + + bool _isEmpty{true}; + + sk_sp _imageFilter; + sk_sp _colorFilter; + sk_sp _pathEffect; + sk_sp _maskFilter; + sk_sp _shader; +}; + +} // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/Declaration.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/Declaration.h new file mode 100644 index 0000000000000..f95478c7b341d --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/Declaration.h @@ -0,0 +1,86 @@ +#pragma once + +#include +#include +#include +#include +#include + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdocumentation" + +#include "SkRefCnt.h" + +#pragma clang diagnostic pop + +namespace RNSkia { + +/** + Small container for shaders, filters, masks and effects + */ +template class Declaration { +public: + // Pushes to the stack + void push(T el) { _elements.push(el); } + + // Clears and returns all elements + std::vector popAll() { + auto size = _elements.size(); + std::vector tmp; + tmp.reserve(size); + for (size_t i = 0; i < size; ++i) { + tmp.push_back(_elements.top()); + _elements.pop(); + } + std::reverse(std::begin(tmp), std::end(tmp)); + return tmp; + } + + T pop() { + if (_elements.size() == 0) { + return nullptr; + } + auto tmp = _elements.top(); + _elements.pop(); + return tmp; + } + + // Clears and returns through reducer function in reversed order + T popAsOne(std::function composer) { + auto tmp = popAll(); + std::reverse(std::begin(tmp), std::end(tmp)); + return std::accumulate(std::begin(tmp), std::end(tmp), + static_cast(nullptr), [=](T inner, T outer) { + if (inner == nullptr) { + return outer; + } + return composer(inner, outer); + }); + } + + // Returns the size of the elements + size_t size() { return _elements.size(); } + +private: + std::stack _elements; +}; + +/** + Small container for shaders, filters, masks and effects + */ +template class ComposableDeclaration : public Declaration { +public: + /** + Constructor + */ + explicit ComposableDeclaration(std::function composer) + : Declaration(), _composer(composer) {} + + // Clears and returns through reducer function in reversed order + T popAsOne() { return Declaration::popAsOne(_composer); } + +private: + std::function _composer; +}; + +} // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DeclarationContext.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DeclarationContext.h new file mode 100644 index 0000000000000..dcb33f891b9bc --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DeclarationContext.h @@ -0,0 +1,79 @@ +#pragma once + +#include "Declaration.h" + +#include +#include +#include + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdocumentation" + +#include "SkColorFilter.h" +#include "SkImageFilter.h" +#include "SkImageFilters.h" +#include "SkMaskFilter.h" +#include "SkPaint.h" +#include "SkPathEffect.h" +#include "SkShader.h" + +#pragma clang diagnostic pop + +namespace RNSkia { + +class DeclarationContext { +public: + DeclarationContext() { save(); } + + Declaration> *getShaders() { return &_shaders.top(); } + ComposableDeclaration> *getImageFilters() { + return &_imageFilters.top(); + } + ComposableDeclaration> *getColorFilters() { + return &_colorFilters.top(); + } + ComposableDeclaration> *getPathEffects() { + return &_pathEffects.top(); + } + Declaration> *getMaskFilters() { + return &_maskFilters.top(); + } + Declaration> *getPaints() { return &_paints.top(); } + + void save() { + _paints.emplace(); + _shaders.emplace(); + _imageFilters.emplace( + [](sk_sp inner, sk_sp outer) { + return SkImageFilters::Compose(outer, inner); + }); + _colorFilters.emplace( + [](sk_sp inner, sk_sp outer) { + return SkColorFilters::Compose(outer, inner); + }); + _pathEffects.emplace( + [](sk_sp inner, sk_sp outer) { + return SkPathEffect::MakeCompose(outer, inner); + }); + _maskFilters.emplace(); + } + + void restore() { + _shaders.pop(); + _imageFilters.pop(); + _colorFilters.pop(); + _pathEffects.pop(); + _maskFilters.pop(); + _paints.pop(); + } + +private: + std::stack>> _shaders; + std::stack>> _imageFilters; + std::stack>> _colorFilters; + std::stack>> _pathEffects; + std::stack>> _maskFilters; + std::stack>> _paints; +}; + +} // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DerivedNodeProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DerivedNodeProp.h index 27c97c45913e5..3a9ecb4476b1b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DerivedNodeProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DerivedNodeProp.h @@ -15,7 +15,8 @@ namespace RNSkia { */ class BaseDerivedProp : public BaseNodeProp { public: - BaseDerivedProp() : BaseNodeProp() {} + explicit BaseDerivedProp(const std::function &onChange) + : _onChange(onChange), BaseNodeProp() {} /** Starts the process of updating and reading props @@ -70,7 +71,11 @@ class BaseDerivedProp : public BaseNodeProp { /** Adds a property to the derived property child props. */ - template P *addProperty(std::shared_ptr

prop) { + template ::value>> + _Tp *defineProperty(_Args &&...__args) { + auto prop = + std::make_shared<_Tp>(std::forward<_Args>(__args)..., _onChange); _properties.push_back(prop); return prop.get(); } @@ -104,6 +109,7 @@ class BaseDerivedProp : public BaseNodeProp { private: std::vector> _properties; std::atomic _isChanged = {false}; + std::function _onChange; }; /** @@ -111,12 +117,21 @@ class BaseDerivedProp : public BaseNodeProp { */ template class DerivedProp : public BaseDerivedProp { public: - DerivedProp() : BaseDerivedProp() {} + explicit DerivedProp(const std::function &onChange) + : BaseDerivedProp(onChange) {} /** Returns the derived value */ - std::shared_ptr getDerivedValue() { return _derivedValue; } + std::shared_ptr getDerivedValue() { + return std::const_pointer_cast(_derivedValue); + } + + /** + Returns a mutable version of the derived value. Used by the paint props to + keep a drawing context + */ + std::shared_ptr getUnsafeDerivedValue() { return _derivedValue; } /** Returns true if is optional and one of the child props has a value, or all @@ -128,7 +143,7 @@ template class DerivedProp : public BaseDerivedProp { /** Set derived value from sub classes */ - void setDerivedValue(std::shared_ptr value) { + void setDerivedValue(std::shared_ptr value) { setIsChanged(_derivedValue != value); _derivedValue = value; } @@ -136,13 +151,13 @@ template class DerivedProp : public BaseDerivedProp { /** Set derived value from sub classes */ - void setDerivedValue(const T &&value) { + void setDerivedValue(T &&value) { setIsChanged(true); - _derivedValue = std::make_shared(std::move(value)); + _derivedValue = std::make_shared(std::move(value)); } private: - std::shared_ptr _derivedValue; + std::shared_ptr _derivedValue; }; /** @@ -150,7 +165,8 @@ template class DerivedProp : public BaseDerivedProp { */ template class DerivedSkProp : public BaseDerivedProp { public: - DerivedSkProp() : BaseDerivedProp() {} + explicit DerivedSkProp(const std::function &onChange) + : BaseDerivedProp(onChange) {} /** Returns the derived value diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.cpp b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.cpp index c4c87d5bf019e..b8cd985a42aac 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.cpp +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.cpp @@ -1,209 +1,55 @@ #include "DrawingContext.h" -namespace RNSkia { - -DrawingContext::DrawingContext(std::shared_ptr paint) - : DrawingContext("root") { - _paint = paint; -} - -DrawingContext::DrawingContext(DrawingContext *parent, const char *source) - : DrawingContext(source) { - _parent = parent; -} - -std::shared_ptr -DrawingContext::inheritContext(const char *source) { - auto result = std::make_shared(this, source); - _children.push_back(result); - return result; -} - -std::string DrawingContext::getDebugDescription() { - std::string v = "ctx for " + std::string(_source) + ":"; - - if (_paint != nullptr) { - auto clr = _paint->getColor(); - auto a = SkColorGetA(clr); - auto r = SkColorGetR(clr); - auto g = SkColorGetG(clr); - auto b = SkColorGetB(clr); - - if (r > 0 || g > 0 || b > 0) { - v += " color:rgba(" + std::to_string(r) + ", " + std::to_string(g) + - ", " + std::to_string(b) + ", " + std::to_string(a) + ")"; - } - - if (_paint->getMaskFilter() != nullptr) { - v += " maskFilter:set"; - } - auto blendMode = _paint->getBlendMode_or(SkBlendMode::kSrc); - if (blendMode != SkBlendMode::kSrc) { - v += " blendMode:" + std::to_string(static_cast(blendMode)); - } - - auto opacity = _paint->getAlphaf(); - v += " opacity:" + std::to_string(opacity); +#include "ConcatablePaint.h" +#include "JsiDomNode.h" +#include "PaintProps.h" - if (_paint->getPathEffect() != nullptr) { - v += " [PathEffect]"; - } - - if (_paint->getShader() != nullptr) { - v += " [Shader]"; - } - - if (_paint->getImageFilter() != nullptr) { - v += " [ImageFilter]"; - } - - if (_paint->getMaskFilter() != nullptr) { - v += " [MaskFilter]"; - } - - if (_paint->getColorFilter() != nullptr) { - v += " [ColorFilter]"; - } - - } else { - v = v + "[inherited] " + - (_parent != nullptr ? _parent->getDebugDescription() : ""); - } - - v = v + "\n"; - - return v; -} - -/** - Invalidate cache - */ -void DrawingContext::markAsChanged() { - markChildrenAsChanged(); - _paint = nullptr; - _isChanged = true; -} +#include -/** - Call to reset invalidate flag after render cycle - */ -void DrawingContext::resetChangedFlag() { _isChanged = false; } - -/** - Dispose and remove the drawing context from its parent. - */ -void DrawingContext::dispose() { - if (_parent != nullptr) { - auto position = std::find(_parent->_children.begin(), - _parent->_children.end(), shared_from_this()); +namespace RNSkia { - if (position != _parent->_children.end()) { - _parent->_children.erase(position); - } - // TODO: This is called from the JS thread so we need somehow to avoid - // rendering after setting this to null, and we also need to protect this - // section. - _parent = nullptr; - } +DrawingContext::DrawingContext(std::shared_ptr paint) { + _declarationContext = std::make_unique(); + paint->setAntiAlias(true); + _paints.push_back(paint); } -/** - Returns true if the current cache is changed - */ -bool DrawingContext::isChanged() { return _isChanged; } +DrawingContext::DrawingContext() + : DrawingContext(std::make_shared()) {} -/** - Get/Sets the canvas object - */ -SkCanvas *DrawingContext::getCanvas() { - if (_parent != nullptr) { - return _parent->getCanvas(); - } - - return _canvas; -} +bool DrawingContext::saveAndConcat( + PaintProps *paintProps, + const std::vector> &children, + std::shared_ptr paintCache) { -/** - Sets the canvas - */ -void DrawingContext::setCanvas(SkCanvas *canvas) { _canvas = canvas; } - -/** - Gets the paint object - */ -std::shared_ptr DrawingContext::getPaint() { - if (_paint != nullptr) { - return _paint; + if (paintCache) { + _paints.push_back(paintCache); + return true; } - return _parent->getPaint(); -} -/** - To be able to mutate and change the paint in a context we need to mutate the - underlying paint object - otherwise we'll just use the parent paint object - (to avoid having to create multiple paint objects for nodes that does not - change the paint). - */ -std::shared_ptr DrawingContext::getMutablePaint() { - if (_paint == nullptr) { - auto parentPaint = _parent->getPaint(); - _paint = std::make_shared(*parentPaint); + ConcatablePaint paint(_declarationContext.get(), paintProps, children); + if (!paint.isEmpty()) { + save(); + paint.concatTo(getPaint()); + return true; } - // Calling the getMutablePaint accessor implies that the paint - // is about to be mutatet and will therefore invalidate - // any child contexts to pick up changes from this context as - // the parent context. - markChildrenAsChanged(); - return _paint; -} - -/** - Sets the paint in the current sub context - */ -void DrawingContext::setMutablePaint(std::shared_ptr paint) { - _paint = paint; -} -float DrawingContext::getScaledWidth() { - if (_parent != nullptr) { - return _parent->getScaledWidth(); - } - return _scaledWidth; + return false; } -float DrawingContext::getScaledHeight() { - if (_parent != nullptr) { - return _parent->getScaledHeight(); - } - return _scaledHeight; +void DrawingContext::save() { + // Copy paint and push + _paints.push_back(std::make_shared(*getPaint())); } -DrawingContext *DrawingContext::getParent() { return _parent; } +void DrawingContext::restore() { _paints.pop_back(); } -void DrawingContext::setScaledWidth(float v) { _scaledWidth = v; } -void DrawingContext::setScaledHeight(float v) { _scaledHeight = v; } - -void DrawingContext::setRequestRedraw(std::function &&requestRedraw) { - if (_parent != nullptr) { - _parent->setRequestRedraw(std::move(requestRedraw)); - } else { - _requestRedraw = std::move(requestRedraw); - } -} +SkCanvas *DrawingContext::getCanvas() { return _canvas; } -const std::function &DrawingContext::getRequestRedraw() { - if (_parent != nullptr) { - return _parent->getRequestRedraw(); - } - return _requestRedraw; -} - -DrawingContext::DrawingContext(const char *source) { _source = source; } +void DrawingContext::setCanvas(SkCanvas *canvas) { _canvas = canvas; } -void DrawingContext::markChildrenAsChanged() { - for (auto &child : _children) { - child->markAsChanged(); - } +std::shared_ptr DrawingContext::getPaint() { + return _paints[_paints.size() - 1]; } } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.h index 184a1eebdb279..b347acd550505 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.h @@ -2,6 +2,9 @@ #include "JsiHostObject.h" +#include "Declaration.h" +#include "DeclarationContext.h" + #include #include #include @@ -10,49 +13,57 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include -#include +#include "SkCanvas.h" +#include "SkPaint.h" +#include "SkRefCnt.h" #pragma clang diagnostic pop namespace RNSkia { -class DrawingContext : public std::enable_shared_from_this { +class PaintProps; +class JsiDomNode; + +class DomRenderContext { public: - /** - Creates a root drawing context with paint and opacity - */ - explicit DrawingContext(std::shared_ptr paint); + float getScaledWidth() { return _scaledWidth; } + float getScaledHeight() { return _scaledHeight; } - /** - Initilalizes a new draw context. - */ - DrawingContext(DrawingContext *parent, const char *source); + void setScaledWidth(float v) { _scaledWidth = v; } + void setScaledHeight(float v) { _scaledHeight = v; } - /** - Factory for creating a child context that inherits from this context - */ - std::shared_ptr inheritContext(const char *source); + void setRequestRedraw(std::function &&requestRedraw) { + _requestRedraw = std::move(requestRedraw); + } - /** - Returns the debug description for the context - */ - std::string getDebugDescription(); + const std::function &getRequestRedraw() { return _requestRedraw; } + +private: + float _scaledWidth = -1; + float _scaledHeight = -1; + std::function _requestRedraw; +}; +class DrawingContext : public DomRenderContext, + public std::enable_shared_from_this { +public: /** - Mark the drawing context and any child contexts as changed + Creates a root drawing context with paint and opacity */ - void markAsChanged(); + DrawingContext(); /** - Call to reset invalidate flag after render cycle - */ - void resetChangedFlag(); + Creates a drawing context with the given paint as its starting paint object + */ + explicit DrawingContext(std::shared_ptr paint); /** - Dispose and remove the drawing context from its parent. + Factory for saving/restoring the context for a node */ - void dispose(); + bool saveAndConcat(PaintProps *paintProps, + const std::vector> &children, + std::shared_ptr paintCache); + void restore(); /** Returns true if the current cache is changed @@ -72,52 +83,22 @@ class DrawingContext : public std::enable_shared_from_this { /** Gets the paint object */ - std::shared_ptr getPaint(); - - /** - To be able to mutate and change the paint in a context we need to mutate the - underlying paint object - otherwise we'll just use the parent paint object - (to avoid having to create multiple paint objects for nodes that does not - change the paint). - */ - std::shared_ptr getMutablePaint(); + std::shared_ptr getPaint(); - /** - Sets the paint in the current sub context + /* + Returns the root declaratiins object */ - void setMutablePaint(std::shared_ptr paint); - - float getScaledWidth(); - - float getScaledHeight(); - - void setScaledWidth(float v); - void setScaledHeight(float v); - - void setRequestRedraw(std::function &&requestRedraw); - const std::function &getRequestRedraw(); - - DrawingContext *getParent(); + DeclarationContext *getDeclarationContext() { + return _declarationContext.get(); + } private: - explicit DrawingContext(const char *source); - - void markChildrenAsChanged(); - - bool _isChanged = true; - - std::shared_ptr _paint; + void save(); + explicit DrawingContext(const char *source); SkCanvas *_canvas = nullptr; - const char *_source; - - DrawingContext *_parent = nullptr; - std::vector> _children; - - float _scaledWidth = -1; - float _scaledHeight = -1; - - std::function _requestRedraw; + std::vector> _paints; + std::unique_ptr _declarationContext; }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDependencyManager.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDependencyManager.h index d8ed4be35548d..6fb59310f8fa1 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDependencyManager.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDependencyManager.h @@ -23,8 +23,10 @@ class JsiDependencyManager public std::enable_shared_from_this { public: JsiDependencyManager(std::shared_ptr context, - jsi::Object &®isterValuesCallback) - : _registerValuesCallback(std::move(registerValuesCallback)), + jsi::Runtime &runtime, + const jsi::Value ®isterValuesCallback) + : _registerValuesCallback(std::make_shared( + registerValuesCallback.asObject(runtime))), JsiHostObject() {} ~JsiDependencyManager() { unsubscribeAll(); } @@ -62,53 +64,53 @@ class JsiDependencyManager // Enumerate registered keys for the given node to only handle known // properties - for (const auto &propMapping : - node->getPropsContainer()->getMappedProperties()) { - auto key = propMapping.first; - auto jsValue = nextProps.getProperty(runtime, key); - JsiValue nativeValue(runtime, jsValue); - - if (isAnimatedValue(nativeValue)) { - // Handle Skia Animation Values - auto animatedValue = getAnimatedValue(nativeValue); - auto unsubscribe = animatedValue->addListener( - [animatedValue, propMapping](jsi::Runtime &runtime) { - // Get value from animation value - auto nextJsValue = animatedValue->getCurrent(runtime); - // Update all props that listens to this animation value - for (auto &prop : propMapping.second) { - prop->updateValue(runtime, nextJsValue); - } - }); - - // Save unsubscribe methods - unsubscribers.push_back(std::make_pair(animatedValue, unsubscribe)); - - } else if (isSelector(nativeValue)) { - // Handle Skia Animation Value Selectors - auto animatedValue = std::dynamic_pointer_cast( - nativeValue.getValue(PropNameValue).getAsHostObject()); - - auto selector = nativeValue.getValue(PropNameSelector).getAsFunction(); - // Add subscription to animated value in selector - auto unsubscribe = animatedValue->addListener( - [nativeValue, propMapping, selector = std::move(selector), - animatedValue](jsi::Runtime &runtime) { - // Get value from animation value - jsi::Value jsValue = animatedValue->getCurrent(runtime); - // Call selector to transform new value - auto selectedJsValue = - selector(runtime, jsi::Value::null(), &jsValue, 1); - // Update all props that listens to this animation value - for (auto &prop : propMapping.second) { - prop->updateValue(runtime, selectedJsValue); - } - }); - - // Save unsubscribe methods - unsubscribers.push_back(std::make_pair(animatedValue, unsubscribe)); - } - } + node->getPropsContainer()->enumerateMappedProps( + [&](const PropId key, const std::vector &propMapping) { + auto jsValue = nextProps.getProperty(runtime, key); + JsiValue nativeValue(runtime, jsValue); + + if (isAnimatedValue(nativeValue)) { + // Handle Skia Animation Values + auto animatedValue = getAnimatedValue(nativeValue); + auto unsubscribe = animatedValue->addListener( + [animatedValue, propMapping](jsi::Runtime &runtime) { + // Get value from animation value + auto nextJsValue = animatedValue->getCurrent(runtime); + // Update all props that listens to this animation value + for (auto &prop : propMapping) { + prop->updateValue(runtime, nextJsValue); + } + }); + + // Save unsubscribe methods + unsubscribers.push_back(std::make_pair(animatedValue, unsubscribe)); + + } else if (isSelector(nativeValue)) { + // Handle Skia Animation Value Selectors + auto animatedValue = std::dynamic_pointer_cast( + nativeValue.getValue(PropNameValue).getAsHostObject()); + + auto selector = + nativeValue.getValue(PropNameSelector).getAsFunction(); + // Add subscription to animated value in selector + auto unsubscribe = animatedValue->addListener( + [nativeValue, propMapping, selector = std::move(selector), + animatedValue](jsi::Runtime &runtime) { + // Get value from animation value + jsi::Value jsValue = animatedValue->getCurrent(runtime); + // Call selector to transform new value + auto selectedJsValue = + selector(runtime, jsi::Value::null(), &jsValue, 1); + // Update all props that listens to this animation value + for (auto &prop : propMapping) { + prop->updateValue(runtime, selectedJsValue); + } + }); + + // Save unsubscribe methods + unsubscribers.push_back(std::make_pair(animatedValue, unsubscribe)); + } + }); // Now let's store the subscription info _subscriptions.emplace(node.get(), unsubscribers); @@ -158,7 +160,7 @@ class JsiDependencyManager } // Call JS registerValues callback - auto func = _registerValuesCallback.asFunction(runtime); + auto func = _registerValuesCallback->asFunction(runtime); _unregisterValues = std::make_shared( func.call(runtime, array, 1).asObject(runtime)); @@ -187,6 +189,8 @@ class JsiDependencyManager unsubscribeAll(); + _registerValuesCallback = nullptr; + return jsi::Value::undefined(); } @@ -203,8 +207,8 @@ class JsiDependencyManager return JSI_HOST_FUNCTION_LAMBDA { // Params: registerValues: (values: Array>) => () => // void - auto obj = std::make_shared( - context, getArgumentAsObject(runtime, arguments, count, 0)); + auto obj = std::make_shared(context, runtime, + arguments[0]); return jsi::Object::createFromHostObject(runtime, std::move(obj)); }; @@ -283,7 +287,7 @@ class JsiDependencyManager return false; } - jsi::Object _registerValuesCallback; + std::shared_ptr _registerValuesCallback; std::shared_ptr _unregisterValues; std::map, diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDeclarationNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDeclarationNode.h index ccf1d9f4427e4..d9ec57debedfb 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDeclarationNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDeclarationNode.h @@ -9,17 +9,29 @@ namespace RNSkia { -class JsiBaseDomDeclarationNode : public JsiDomNode { +enum DeclarationType { + Unknown = 0, + Paint = 1, + Shader = 2, + ImageFilter = 3, + ColorFilter = 4, + PathEffect = 5, + MaskFilter = 6, +}; + +class JsiDomDeclarationNode : public JsiDomNode { public: - JsiBaseDomDeclarationNode(std::shared_ptr context, - const char *type) - : JsiDomNode(context, type) {} + JsiDomDeclarationNode(std::shared_ptr context, + const char *type, DeclarationType declarationType) + : JsiDomNode(context, type, NodeClass::DeclarationNode), + _declarationType(declarationType) {} JSI_PROPERTY_GET(declarationType) { + // FIXME: Shouldn't this be the declaration type instead? It has been return jsi::String::createFromUtf8(runtime, std::string(getType())); } - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiBaseDomDeclarationNode, + JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiDomDeclarationNode, declarationType), JSI_EXPORT_PROP_GET(JsiDomNode, type)) @@ -34,30 +46,27 @@ class JsiBaseDomDeclarationNode : public JsiDomNode { /** Called when rendering the tree to create all derived values from all nodes. */ - virtual void decorateContext(DrawingContext *context) { + void decorateContext(DeclarationContext *context) override { + JsiDomNode::decorateContext(context); + #if SKIA_DOM_DEBUG - printDebugInfo("Begin Materialize " + std::string(getType())); + printDebugInfo("Begin decorate " + std::string(getType())); #endif - // Materialize children first so that any inner nodes get the opportunity - // to calculate their state before this node continues. - for (auto &child : getChildren()) { - if (child->getNodeClass() == JsiDomNodeClass::DeclarationNode) { - std::static_pointer_cast(child) - ->decorateContext(context); - } - } // decorate drawing context decorate(context); #if SKIA_DOM_DEBUG - printDebugInfo("End / Commit Materialize " + std::string(getType())); + printDebugInfo("End / Commit decorate " + std::string(getType())); #endif } - JsiDomNodeClass getNodeClass() override { - return JsiDomNodeClass::DeclarationNode; - } + DeclarationType getDeclarationType() { return _declarationType; } + + /** + Override to implement materialization + */ + virtual void decorate(DeclarationContext *context) = 0; protected: /** @@ -71,16 +80,15 @@ class JsiBaseDomDeclarationNode : public JsiDomNode { } /** - Override to implement materialization + A property changed */ - virtual void decorate(DrawingContext *context) = 0; + void onPropertyChanged(BaseNodeProp *prop) override { invalidateContext(); } /** Validates that only declaration nodes can be children */ void addChild(std::shared_ptr child) override { - if (std::dynamic_pointer_cast(child) == - nullptr) { + if (child->getNodeClass() != NodeClass::DeclarationNode) { getContext()->raiseError(std::runtime_error( "Cannot add a child of type \"" + std::string(child->getType()) + "\" to a \"" + std::string(getType()) + "\".")); @@ -93,98 +101,19 @@ class JsiBaseDomDeclarationNode : public JsiDomNode { */ void insertChildBefore(std::shared_ptr child, std::shared_ptr before) override { - if (std::dynamic_pointer_cast(child) == - nullptr) { + if (child->getNodeClass() != NodeClass::DeclarationNode) { getContext()->raiseError(std::runtime_error( "Cannot add a child of type \"" + std::string(child->getType()) + "\" to a \"" + std::string(getType()) + "\".")); } JsiDomNode::insertChildBefore(child, before); } -}; - -template -class JsiDomDeclarationNode : public JsiBaseDomDeclarationNode { -public: - JsiDomDeclarationNode(std::shared_ptr context, - const char *type) - : JsiBaseDomDeclarationNode(context, type) {} - - bool isChanged(DrawingContext *context) { - return getCurrent() == nullptr || context->isChanged() || - getPropsContainer()->isChanged(); - } - - /** - Returns the inner element - */ - ST getCurrent() { return _current; } - - /** - Clears the current - */ - void clearCurrent() { _current = nullptr; } - -protected: - /** - Sets the current value - */ - void setCurrent(ST c) { _current = c; } - - /** - Returns a required child image filter by index - */ - ST requireChild(size_t index) { - auto filter = optionalChild(index); - if (filter == nullptr) { - throw std::runtime_error("Expected child node at index " + - std::to_string(index) + " in node " + getType()); - } - return filter; - } - - /** - Returns an optional child image filter by index - */ - ST optionalChild(size_t index) { - if (index >= getChildren().size()) { - return nullptr; - } - - auto child = getChildren()[index]; - // Support all types here!! ImageFilters, ColorFilters - // package/src/dom/nodes/paint/ImageFilters.ts#80 - return resolve(child); - } - - /** - Returns child as inner type or nullptr - */ - virtual ST resolve(std::shared_ptr child) = 0; +private: /** - Sets or composes the image filter + Type of declaration */ - virtual void set(DrawingContext *context, ST imageFilter) = 0; - - void removeChild(std::shared_ptr child) override { - JsiBaseDomDeclarationNode::removeChild(child); - clearCurrent(); - } - - void addChild(std::shared_ptr child) override { - JsiBaseDomDeclarationNode::addChild(child); - clearCurrent(); - } - - void insertChildBefore(std::shared_ptr child, - std::shared_ptr before) override { - JsiBaseDomDeclarationNode::insertChildBefore(child, before); - clearCurrent(); - } - -private: - ST _current; + DeclarationType _declarationType; }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDrawingNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDrawingNode.h index 62174ab6b7329..302c49bfd3cf4 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDrawingNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDrawingNode.h @@ -16,7 +16,7 @@ class JsiDomDrawingNode : public JsiDomRenderNode { protected: void defineProperties(NodePropsContainer *container) override { JsiDomRenderNode::defineProperties(container); - container->defineProperty(); + _paintProp = container->defineProperty(); } /** @@ -28,23 +28,42 @@ class JsiDomDrawingNode : public JsiDomRenderNode { #if SKIA_DOM_DEBUG printDebugInfo("Begin Draw", 1); #endif - -#if SKIA_DOM_DEBUG - printDebugInfo(context->getDebugDescription(), 2); -#endif - draw(context); + // Save paint if the paint property is set + if (_paintProp->isSet()) { + draw(_paintProp->getUnsafeDerivedValue().get()); + } else { + // Call abstract draw method + draw(context); + } // Draw once more for each child paint node + auto declarationCtx = context->getDeclarationContext(); for (auto &child : getChildren()) { - auto ptr = std::dynamic_pointer_cast(child); - if (ptr != nullptr) { - draw(ptr->getDrawingContext()); + if (child->getNodeClass() == NodeClass::DeclarationNode && + std::static_pointer_cast(child) + ->getDeclarationType() == DeclarationType::Paint) { + auto paintNode = std::static_pointer_cast(child); + // Draw once again with the paint + declarationCtx->save(); + paintNode->decorate(declarationCtx); + auto paint = declarationCtx->getPaints()->pop(); + declarationCtx->restore(); + + // FIXME: Can we avoid creating a new drawing context here each time? + auto localContext = + std::make_shared(std::shared_ptr(paint)); + localContext->setCanvas(context->getCanvas()); + draw(localContext.get()); } } + #if SKIA_DOM_DEBUG printDebugInfo("End Draw", 1); #endif } + +private: + PaintDrawingContextProp *_paintProp; }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomNode.h index 45c296f580905..3d47ec57cf85c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomNode.h @@ -33,7 +33,7 @@ static std::atomic NodeIdent = 1000; typedef enum { RenderNode = 1, DeclarationNode = 2, -} JsiDomNodeClass; +} NodeClass; /** Implements an abstract base class for nodes in the Skia Reconciler. This node @@ -46,8 +46,22 @@ class JsiDomNode : public JsiHostObject, Contructor. Takes as parameters the values comming from the JS world that initialized the class. */ - JsiDomNode(std::shared_ptr context, const char *type) - : _type(type), _context(context), _nodeId(NodeIdent++), JsiHostObject() {} + JsiDomNode(std::shared_ptr context, const char *type, + NodeClass nodeClass) + : _type(type), _context(context), _nodeClass(nodeClass), + _nodeId(NodeIdent++), JsiHostObject() { +#if SKIA_DOM_DEBUG + printDebugInfo("JsiDomNode." + std::string(_type) + + " CTOR - nodeId: " + std::to_string(_nodeId)); +#endif + } + + virtual ~JsiDomNode() { +#if SKIA_DOM_DEBUG + printDebugInfo("JsiDomNode." + std::string(_type) + + " DTOR - nodeId: " + std::to_string(_nodeId)); +#endif + } /** Called when creating the node, resolves properties from the node constructor. @@ -63,7 +77,7 @@ class JsiDomNode : public JsiHostObject, JSI_HOST_FUNCTION(setProps) { if (count == 1) { // Initialize properties container - setProps(runtime, getArgumentAsObject(runtime, arguments, count, 0)); + setProps(runtime, arguments[0]); } else { setEmptyProps(); } @@ -71,16 +85,35 @@ class JsiDomNode : public JsiHostObject, } /** - Empty setProp implementation - compatibility with JS node + Updates the selected property value */ - JSI_HOST_FUNCTION(setProp) { return jsi::Value::undefined(); } + JSI_HOST_FUNCTION(setProp) { + if (_propsContainer == nullptr) { + // TODO: we ignore individual properties updates if the initial properties + // hasn't been defined. It is likely an error if we reach this branch and + // perhaps should throw an exception but platformContext isn't available + // here. + return jsi::Value::undefined(); + } + auto propName = arguments[0].asString(runtime).utf8(runtime); + const jsi::Value &propValue = arguments[1]; + + // Enumerate all props with this name and update. The + // enumerateMappedPropsByName function is thread safe and locks props so it + // can be called from all threads. + _propsContainer->enumerateMappedPropsByName(propName, [&](NodeProp *prop) { + prop->updateValue(runtime, propValue); + }); + + return jsi::Value::undefined(); + } /** JS Function to be called when the node is no longer part of the reconciler tree. Use for cleaning up. */ JSI_HOST_FUNCTION(dispose) { - dispose(); + dispose(false); return jsi::Value::undefined(); } @@ -183,7 +216,7 @@ class JsiDomNode : public JsiHostObject, Returns the class of node so that we can do loops faster without having to check using runtime type information */ - virtual JsiDomNodeClass getNodeClass() = 0; + NodeClass getNodeClass() { return _nodeClass; } /** Updates any pending property changes in all nodes and child nodes. This @@ -205,11 +238,6 @@ class JsiDomNode : public JsiHostObject, op(); } - // If there are any ops here we should invalidate the cached context - if (_queuedNodeOps.size() > 0) { - invalidateContext(); - } - _queuedNodeOps.clear(); } @@ -230,36 +258,9 @@ class JsiDomNode : public JsiHostObject, _propsContainer->markAsResolved(); } - // Now let's dispose if needed + // Now let's invalidate if needed if (_isDisposing && !_isDisposed) { - _isDisposed = true; - - this->setParent(nullptr); - - // Callback signaling that we're done - if (_disposeCallback != nullptr) { - _disposeCallback(); - _disposeCallback = nullptr; - } - - // Clear props - if (_propsContainer != nullptr) { - _propsContainer->dispose(); - } - - // Remove children - std::vector> tmp; - { - std::lock_guard lock(_childrenLock); - tmp.reserve(_children.size()); - for (auto &child : _children) { - tmp.push_back(child); - } - _children.clear(); - } - for (auto &child : tmp) { - child->dispose(); - } + invalidate(); } // Resolve children @@ -268,7 +269,37 @@ class JsiDomNode : public JsiHostObject, } } + /** + Empty implementation of the decorate context method + */ + virtual void decorateContext(DeclarationContext *context) { + // Empty implementation + } + + /** + Called when a node has been removed from the dom tree and needs to be cleaned + up. If the invalidate parameter is set, we will invalidate the node directly. + Calling dispose from the JS dispose function calls this with invalidate set + to false, while the dom render view calls this with true. + */ + virtual void dispose(bool immediate) { + if (_isDisposing) { + return; + } + _isDisposing = true; + if (immediate) { + invalidate(); + } + } + protected: + /** + Adds an operation that will be executed when the render cycle is finished. + */ + void enqueAsynOperation(std::function &&fp) { + std::lock_guard lock(_childrenLock); + _queuedNodeOps.push_back(std::move(fp)); + } /** Override to define properties in node implementations */ @@ -288,23 +319,17 @@ class JsiDomNode : public JsiHostObject, /** Native implementation of the set properties method. This is called from the - reconciler when properties are set due to changes in React. This method will - always call the onPropsSet method as a signal that things have changed. + reconciler when properties are set due to changes in React. */ - void setProps(jsi::Runtime &runtime, jsi::Object &&props) { + void setProps(jsi::Runtime &runtime, const jsi::Value &maybeProps) { #if SKIA_DOM_DEBUG printDebugInfo("JS:setProps(nodeId: " + std::to_string(_nodeId) + ")"); #endif - if (_propsContainer == nullptr) { - - // Initialize properties container - _propsContainer = std::make_shared(getType()); + // Initialize properties container + ensurePropertyContainer(); - // Ask sub classes to define their properties - defineProperties(_propsContainer.get()); - } // Update properties container - _propsContainer->setProps(runtime, std::move(props)); + _propsContainer->setProps(runtime, maybeProps); // Invalidate context invalidateContext(); @@ -317,14 +342,8 @@ class JsiDomNode : public JsiHostObject, #if SKIA_DOM_DEBUG printDebugInfo("JS:setEmptyProps(nodeId: " + std::to_string(_nodeId) + ")"); #endif - if (_propsContainer == nullptr) { - - // Initialize properties container - _propsContainer = std::make_shared(getType()); - - // Ask sub classes to define their properties - defineProperties(_propsContainer.get()); - } + // Initialize properties container + ensurePropertyContainer(); } /** @@ -335,6 +354,11 @@ class JsiDomNode : public JsiHostObject, return _children; } + /** + Override to be notified when a node property has changed + */ + virtual void onPropertyChanged(BaseNodeProp *prop) {} + /** Adds a child node to the array of children for this node */ @@ -343,10 +367,12 @@ class JsiDomNode : public JsiHostObject, printDebugInfo("JS:addChild(childId: " + std::to_string(child->_nodeId) + ")"); #endif - std::lock_guard lock(_childrenLock); - _queuedNodeOps.push_back([child, this]() { - _children.push_back(child); - child->setParent(this); + enqueAsynOperation([child, weakSelf = weak_from_this()]() { + auto self = weakSelf.lock(); + if (self) { + self->_children.push_back(child); + child->setParent(self.get()); + } }); } @@ -361,11 +387,14 @@ class JsiDomNode : public JsiHostObject, "JS:insertChildBefore(childId: " + std::to_string(child->_nodeId) + ", beforeId: " + std::to_string(before->_nodeId) + ")"); #endif - std::lock_guard lock(_childrenLock); - _queuedNodeOps.push_back([child, before, this]() { - auto position = std::find(_children.begin(), _children.end(), before); - _children.insert(position, child); - child->setParent(this); + enqueAsynOperation([child, before, weakSelf = weak_from_this()]() { + auto self = weakSelf.lock(); + if (self) { + auto position = + std::find(self->_children.begin(), self->_children.end(), before); + self->_children.insert(position, child); + child->setParent(self.get()); + } }); } @@ -378,28 +407,25 @@ class JsiDomNode : public JsiHostObject, printDebugInfo("JS:removeChild(childId: " + std::to_string(child->_nodeId) + ")"); #endif - std::lock_guard lock(_childrenLock); - _queuedNodeOps.push_back([child, this]() { - // Delete child itself - _children.erase( - std::remove_if(_children.begin(), _children.end(), - [child](const auto &node) { return node == child; }), - _children.end()); - - child->dispose(); - }); - } + auto removeChild = [child, + weakSelf = weak_from_this()](bool immediate = false) { + auto self = weakSelf.lock(); + if (self) { + // Delete child itself + self->_children.erase( + std::remove_if(self->_children.begin(), self->_children.end(), + [child](const auto &node) { return node == child; }), + self->_children.end()); + + child->dispose(immediate); + } + }; - /** - Called when a node has been removed from the dom tree and needs to be cleaned - up. - */ - virtual void dispose() { if (_isDisposing) { - return; + removeChild(false); + } else { + enqueAsynOperation(removeChild); } - - _isDisposing = true; } #if SKIA_DOM_DEBUG @@ -429,7 +455,82 @@ class JsiDomNode : public JsiHostObject, */ JsiDomNode *getParent() { return _parent; } + /** + Loops through all declaration nodes and gives each one of them the + opportunity to decorate the context. + */ + void decorateChildren(DeclarationContext *context) { + for (auto &child : getChildren()) { + // All JsiDomNodes has the decorateContext method - but only the + // JsiDomDeclarationNode is actually doing stuff inside this method. + child->decorateContext(context); + } + } + private: + /** + Invalidates the node - meaning removing and clearing children and properties + **/ + void invalidate() { + if (_isDisposing && !_isDisposed) { +#if SKIA_DOM_DEBUG + printDebugInfo("JsiDomNode::invalidate: nodeid: " + + std::to_string(_nodeId)); +#endif + + _isDisposed = true; + + // Clear parent + this->setParent(nullptr); + + // Clear any async operations + _queuedNodeOps.clear(); + + // Callback signaling that we're done + if (_disposeCallback != nullptr) { + _disposeCallback(); + _disposeCallback = nullptr; + } + + // Clear props + if (_propsContainer != nullptr) { + _propsContainer->dispose(); + } + + // Remove children + std::vector> tmp; + { + std::lock_guard lock(_childrenLock); + tmp.reserve(_children.size()); + for (auto &child : _children) { + tmp.push_back(child); + } + _children.clear(); + } + for (auto &child : tmp) { + child->dispose(true); + } + } + } + + /** + Creates and sets up the property container + */ + void ensurePropertyContainer() { + if (_propsContainer == nullptr) { + _propsContainer = std::make_shared( + getType(), [weakSelf = weak_from_this()](BaseNodeProp *p) { + auto self = weakSelf.lock(); + if (self) { + self->onPropertyChanged(p); + } + }); + + // Ask sub classes to define their properties + defineProperties(_propsContainer.get()); + } + } + const char *_type; std::shared_ptr _context; @@ -448,6 +549,8 @@ class JsiDomNode : public JsiHostObject, std::vector> _queuedNodeOps; JsiDomNode *_parent = nullptr; + + NodeClass _nodeClass; }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomRenderNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomRenderNode.h index e05274055b689..d811203a703be 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomRenderNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomRenderNode.h @@ -15,6 +15,7 @@ #include #include +#include namespace RNSkia { @@ -22,17 +23,19 @@ class JsiDomRenderNode : public JsiDomNode { public: JsiDomRenderNode(std::shared_ptr context, const char *type) - : JsiDomNode(context, type) {} + : JsiDomNode(context, type, NodeClass::RenderNode) {} void render(DrawingContext *context) { #if SKIA_DOM_DEBUG printDebugInfo("Begin Render"); #endif - // Ensure we have a local drawing context inheriting from the parent context - if (_localContext == nullptr) { - _localContext = context->inheritContext(getType()); - } + auto parentPaint = context->getPaint(); + auto cache = + _paintCache.parent == parentPaint ? _paintCache.child : nullptr; + + auto shouldRestore = + context->saveAndConcat(_paintProps, getChildren(), cache); auto shouldTransform = _matrixProp->isSet() || _transformProp->isSet(); auto shouldSave = @@ -43,37 +46,36 @@ class JsiDomRenderNode : public JsiDomNode { // Save canvas state if (_layerProp->isSet()) { if (_layerProp->isBool()) { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->saveLayer()"); #endif - _localContext->getCanvas()->saveLayer( + context->getCanvas()->saveLayer( SkCanvas::SaveLayerRec(nullptr, nullptr, nullptr, 0)); } else { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->saveLayer(paint)"); #endif - _localContext->getCanvas()->saveLayer(SkCanvas::SaveLayerRec( + context->getCanvas()->saveLayer(SkCanvas::SaveLayerRec( nullptr, _layerProp->getDerivedValue().get(), nullptr, 0)); } } else { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->save()"); #endif - _localContext->getCanvas()->save(); + context->getCanvas()->save(); } if (_originProp->isSet()) { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->translate(origin)"); #endif // Handle origin - _localContext->getCanvas()->translate( - _originProp->getDerivedValue()->x(), - _originProp->getDerivedValue()->y()); + context->getCanvas()->translate(_originProp->getDerivedValue()->x(), + _originProp->getDerivedValue()->y()); } if (shouldTransform) { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo( "canvas->concat(" + std::string(_matrixProp->isSet() ? "matrix" : "transform") + @@ -83,43 +85,40 @@ class JsiDomRenderNode : public JsiDomNode { : _transformProp->getDerivedValue(); // Concat canvas' matrix with our matrix - _localContext->getCanvas()->concat(*matrix); + context->getCanvas()->concat(*matrix); } // Clipping if (_clipProp->isSet()) { auto invert = _invertClip->isSet() && _invertClip->value().getAsBool(); - clip(context, _localContext->getCanvas(), invert); + clip(context, context->getCanvas(), invert); } if (_originProp->isSet()) { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->translate(-origin)"); #endif // Handle origin - _localContext->getCanvas()->translate( - -_originProp->getDerivedValue()->x(), - -_originProp->getDerivedValue()->y()); + context->getCanvas()->translate(-_originProp->getDerivedValue()->x(), + -_originProp->getDerivedValue()->y()); } } - // Let any local paint props decorate the context - _paintProps->decorate(_localContext.get()); - - // Now let's make sure the local context is resolved correctly - ie. that - // all children of type declaration (except paint) is given the opportunity - // to decorate the context. - materializeDeclarations(); - // Render the node - renderNode(_localContext.get()); + renderNode(context); // Restore if needed if (shouldSave) { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->restore()"); #endif - _localContext->getCanvas()->restore(); + context->getCanvas()->restore(); + } + + if (shouldRestore) { + _paintCache.parent = parentPaint; + _paintCache.child = context->getPaint(); + context->restore(); } #if SKIA_DOM_DEBUG @@ -131,26 +130,14 @@ class JsiDomRenderNode : public JsiDomNode { Override reset (last thing that happens in the render cycle) to also reset the changed flag on the local drawing context if necessary. */ - void resetPendingChanges() override { - JsiDomNode::resetPendingChanges(); - _localContext->resetChangedFlag(); - } + void resetPendingChanges() override { JsiDomNode::resetPendingChanges(); } /** - Signal from the JS side that the node is removed from the dom. + Overridden dispose to release resources */ - void dispose() override { - JsiDomNode::dispose(); - - // Clear local drawing context - if (_localContext != nullptr) { - _localContext->dispose(); - _localContext = nullptr; - } - } - - JsiDomNodeClass getNodeClass() override { - return JsiDomNodeClass::RenderNode; + void dispose(bool immediate) override { + JsiDomNode::dispose(immediate); + _paintCache.clear(); } protected: @@ -158,9 +145,15 @@ class JsiDomRenderNode : public JsiDomNode { Invalidates and marks then context as changed. */ void invalidateContext() override { - if (_localContext != nullptr) { - _localContext->markAsChanged(); - } + enqueAsynOperation([weakSelf = weak_from_this()]() { + auto self = weakSelf.lock(); + if (self) { + std::static_pointer_cast(self)->_paintCache.parent = + nullptr; + std::static_pointer_cast(self)->_paintCache.child = + nullptr; + } + }); } /** @@ -185,6 +178,43 @@ class JsiDomRenderNode : public JsiDomNode { _layerProp = container->defineProperty("layer"); } + /** + Validates that only declaration nodes can be children + */ + void addChild(std::shared_ptr child) override { + JsiDomNode::addChild(child); + _paintCache.parent = nullptr; + _paintCache.child = nullptr; + } + + /** + Validates that only declaration nodes can be children + */ + void insertChildBefore(std::shared_ptr child, + std::shared_ptr before) override { + JsiDomNode::insertChildBefore(child, before); + _paintCache.parent = nullptr; + _paintCache.child = nullptr; + } + + /** + A property changed + */ + void onPropertyChanged(BaseNodeProp *prop) override { + static std::vector paintProps = { + JsiPropId::get("color"), JsiPropId::get("strokeWidth"), + JsiPropId::get("blendMode"), JsiPropId::get("strokeCap"), + JsiPropId::get("strokeJoin"), JsiPropId::get("strokeMiter"), + JsiPropId::get("style"), JsiPropId::get("antiAlias"), + JsiPropId::get("opacity")}; + + // We'll invalidate paint if a prop change happened in a paint property + if (std::find(paintProps.begin(), paintProps.end(), prop->getName()) != + paintProps.end()) { + invalidateContext(); + } + } + private: /** Clips the canvas depending on the clip property @@ -209,18 +239,16 @@ class JsiDomRenderNode : public JsiDomNode { } } - /** - Loops through all declaration nodes and gives each one of them the - opportunity to decorate the context - */ - void materializeDeclarations() { - for (auto &child : getChildren()) { - if (child->getNodeClass() == JsiDomNodeClass::DeclarationNode) { - std::static_pointer_cast(child) - ->decorateContext(_localContext.get()); - } + struct PaintCache { + void clear() { + parent = nullptr; + child = nullptr; } - } + std::shared_ptr parent; + std::shared_ptr child; + }; + + PaintCache _paintCache; PointProp *_originProp; MatrixProp *_matrixProp; @@ -229,8 +257,6 @@ class JsiDomRenderNode : public JsiDomNode { ClipProp *_clipProp; LayerProp *_layerProp; PaintProps *_paintProps; - - std::shared_ptr _localContext; }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodeProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodeProp.h index 14a96b6f63966..e3df3bdd2f2cf 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodeProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodeProp.h @@ -5,6 +5,7 @@ #include #include +#include #include namespace RNSkia { @@ -19,8 +20,9 @@ class NodeProp : public BaseNodeProp, /** Constructs a new optional dom node properrty */ - explicit NodeProp(const std::string &name) - : _name(JsiPropId::get(name)), BaseNodeProp() {} + explicit NodeProp(const std::string &name, + const std::function &onChange) + : _name(JsiPropId::get(name)), _onChange(onChange), BaseNodeProp() {} /** Reads JS value and swaps out with a new value @@ -31,7 +33,7 @@ class NodeProp : public BaseNodeProp, // readValueFromJS Function (which comes from the reconciler // setting a new property value on the property if (_value == nullptr) { - _value = std::make_shared(runtime, read(runtime, _name, this)); + _value = std::make_unique(runtime, read(runtime, _name, this)); _isChanged = true; _hasNewValue = false; } else { @@ -39,11 +41,14 @@ class NodeProp : public BaseNodeProp, std::lock_guard lock(_swapMutex); if (_buffer == nullptr) { _buffer = - std::make_shared(runtime, read(runtime, _name, this)); + std::make_unique(runtime, read(runtime, _name, this)); } else { _buffer->setCurrent(runtime, read(runtime, _name, this)); } _hasNewValue = *_buffer.get() != *_value.get(); + if (_hasNewValue && _onChange != nullptr) { + _onChange(this); + } } } @@ -55,13 +60,16 @@ class NodeProp : public BaseNodeProp, // and we don't want to rip out the underlying value object. std::lock_guard lock(_swapMutex); if (_buffer == nullptr) { - _buffer = std::make_shared(runtime, value); + _buffer = std::make_unique(runtime, value); } else { _buffer->setCurrent(runtime, value); } // This is almost always a change - meaning a swap is // cheaper than comparing for equality. _hasNewValue = true; + if (_onChange != nullptr) { + _onChange(this); + } } /** @@ -119,8 +127,10 @@ class NodeProp : public BaseNodeProp, private: PropId _name; - std::shared_ptr _value; - std::shared_ptr _buffer; + std::function _onChange; + + std::unique_ptr _value; + std::unique_ptr _buffer; std::atomic _isChanged = {false}; std::atomic _hasNewValue = {false}; std::mutex _swapMutex; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodePropsContainer.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodePropsContainer.h index 0db3dc2a99ea7..7348276ea40b2 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodePropsContainer.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodePropsContainer.h @@ -20,11 +20,12 @@ namespace RNSkia { class NodePropsContainer { public: /** - Constructor. Pass the runtime and the JS object representing the properties, - and a function that will be called when any property was changed from within - this class as a result of a Skia value change. + Constructor for the node prop container */ - explicit NodePropsContainer(PropId componentType) : _type(componentType) {} + explicit NodePropsContainer( + PropId componentType, + const std::function &onPropChanged) + : _onPropChanged(onPropChanged), _type(componentType) {} /** Returns true if there are any changes in the props container in the current @@ -40,10 +41,30 @@ class NodePropsContainer { } /** - Returns a list of mappings betwen property names and property objects + Enumerate all mapped properties */ - const std::map> &getMappedProperties() { - return _mappedProperties; + void enumerateMappedProps( + const std::function)> &callback) { + std::lock_guard lock(_mappedPropsLock); + for (auto &props : _mappedProperties) { + callback(props.first, props.second); + } + } + + /** + Enumerates a named property instances from the mapped properties list + */ + void + enumerateMappedPropsByName(const std::string &name, + const std::function &callback) { + std::lock_guard lock(_mappedPropsLock); + auto propMapIt = _mappedProperties.find(JsiPropId::get(name)); + if (propMapIt != _mappedProperties.end()) { + for (auto &prop : propMapIt->second) { + callback(prop); + } + } } /** @@ -53,7 +74,7 @@ class NodePropsContainer { void updatePendingValues() { for (auto &prop : _properties) { prop->updatePendingChanges(); - if (!prop->isSet() && prop->isRequired()) { + if (prop->isRequired() && !prop->isSet()) { throw std::runtime_error("Missing one or more required properties " + std::string(prop->getName()) + " in the " + _type + " component."); @@ -74,6 +95,7 @@ class NodePropsContainer { Clears all props and data from the container */ void dispose() { + std::lock_guard lock(_mappedPropsLock); _properties.clear(); _mappedProperties.clear(); } @@ -81,10 +103,18 @@ class NodePropsContainer { /** Called when the React / JS side sets properties on a node */ - void setProps(jsi::Runtime &runtime, jsi::Object &&props) { + void setProps(jsi::Runtime &runtime, const jsi::Value &maybePropsObject) { + std::lock_guard lock(_mappedPropsLock); + // Clear property mapping _mappedProperties.clear(); + if (!maybePropsObject.isObject()) { + throw jsi::JSError(runtime, "Expected property object."); + } + + auto props = maybePropsObject.asObject(runtime); + // Use specialized reader function to be able to intercept calls that // reads specific named values from the js property object. auto read = [&](jsi::Runtime &runtime, PropId name, NodeProp *prop) { @@ -102,28 +132,27 @@ class NodePropsContainer { } /** - Defines a property that will be updated with the container changes. - */ - template - T *defineProperty(std::shared_ptr prop) { - _properties.push_back(prop); - return prop.get(); - } - - /** - Defines a property that will be updated with the container changes. + Defines a property that will be added to the container */ template ::value>> + class = std::enable_if_t::value>> _Tp *defineProperty(_Args &&...__args) { - return defineProperty( - std::make_shared<_Tp>(std::forward<_Args>(__args)...)); + // Create property and set onChange callback + auto prop = + std::make_shared<_Tp>(std::forward<_Args>(__args)..., _onPropChanged); + + // Add to props list + _properties.push_back(prop); + + return prop.get(); } private: + std::function _onPropChanged; std::vector> _properties; std::map> _mappedProperties; PropId _type; + std::mutex _mappedPropsLock; }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h index 119819530d59d..b176bc10f440a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h @@ -15,22 +15,33 @@ class JsiBackdropFilterNode : public JsiDomDrawingNode, protected: void draw(DrawingContext *context) override { - if (getChildren().size() == 0) { - throw std::runtime_error( - "Expected at least one child in the BackdropFilter node."); + auto children = getChildren(); + + if (children.size() == 0) { + return; } - auto child = getChildren()[0]; - auto colorFilter = std::dynamic_pointer_cast(child); - auto imageFilter = std::dynamic_pointer_cast(child); auto canvas = context->getCanvas(); - auto filter = - colorFilter != nullptr - ? SkImageFilters::ColorFilter(colorFilter->getCurrent(), nullptr) - : imageFilter->getCurrent(); + auto firstChild = children[0]; + sk_sp imageFilter; + + if (firstChild->getNodeClass() == NodeClass::DeclarationNode) { + context->getDeclarationContext()->save(); + firstChild->decorateContext(context->getDeclarationContext()); + auto imgF = context->getDeclarationContext()->getImageFilters()->pop(); + if (imgF) { + imageFilter = imgF; + } else { + auto cf = context->getDeclarationContext()->getColorFilters()->pop(); + if (cf) { + imageFilter = SkImageFilters::ColorFilter(cf, nullptr); + } + } + context->getDeclarationContext()->restore(); + } canvas->saveLayer( - SkCanvas::SaveLayerRec(nullptr, nullptr, filter.get(), 0)); + SkCanvas::SaveLayerRec(nullptr, nullptr, imageFilter.get(), 0)); canvas->restore(); } }; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlendNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlendNode.h index 970e02d433134..4dd6d8f6f5bd5 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlendNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlendNode.h @@ -2,74 +2,55 @@ #include "JsiDomDeclarationNode.h" +#include #include #include namespace RNSkia { -class JsiBlendNode : public JsiBaseDomDeclarationNode, +class JsiBlendNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiBlendNode(std::shared_ptr context) - : JsiBaseDomDeclarationNode(context, "skBlend") {} + : JsiDomDeclarationNode(context, "skBlend", + DeclarationType::ImageFilter) {} -protected: - void decorate(DrawingContext *context) override { - if (context->isChanged() || getPropsContainer()->isChanged()) { - auto children = getChildren(); - auto childSize = children.size(); - - // No need to do anything if there are no children here - if (childSize == 0) { - return; - } - - // Blend mode - auto blendMode = *_blendProp->getDerivedValue(); - - // Find the latest child and check if it is a shader or image filter - bool asShader = std::dynamic_pointer_cast( - children.at(childSize - 1)) != nullptr; - - // Traverse children in reverse - sk_sp innerShader; - sk_sp innerImageFilter; - - for (size_t i = childSize - 1; i != (std::size_t)-1; i--) { - auto child = children.at(i); - auto maybeShader = std::dynamic_pointer_cast(child); - auto maybeImageFilter = - std::dynamic_pointer_cast(child); - - if (maybeShader) { - sk_sp outer = maybeShader->getCurrent(); - if (innerShader != nullptr) { - innerShader = SkShaders::Blend(blendMode, outer, innerShader); - } else { - innerShader = outer; - } - } else if (maybeImageFilter) { - sk_sp outer = maybeImageFilter->getCurrent(); - if (outer != nullptr) { - innerImageFilter = SkImageFilters::Blend(blendMode, outer, - innerImageFilter, nullptr); - } else { - innerImageFilter = outer; - } - } - } - - // Materialize - if (asShader) { - context->getMutablePaint()->setShader(innerShader); - } else { - context->getMutablePaint()->setImageFilter(innerImageFilter); - } + void decorate(DeclarationContext *context) override { + + // No need to do anything if there are no children here + if (getChildren().size() == 0) { + return; + } + + decorateChildren(context); + + // Blend mode + auto blendMode = *_blendProp->getDerivedValue(); + + // Shader + auto shader = context->getShaders()->popAsOne( + [blendMode](sk_sp inner, sk_sp outer) { + return SkShaders::Blend(blendMode, outer, inner); + }); + + if (shader != nullptr) { + context->getShaders()->push(shader); + } + + auto imageFilter = + context->getImageFilters()->Declaration>::popAsOne( + [blendMode](sk_sp inner, + sk_sp outer) { + return SkImageFilters::Blend(blendMode, outer, inner); + }); + if (imageFilter != nullptr) { + context->getImageFilters()->push(imageFilter); } } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _blendProp = container->defineProperty("mode"); _blendProp->require(); } @@ -78,7 +59,7 @@ class JsiBlendNode : public JsiBaseDomDeclarationNode, Validates that only declaration nodes can be children */ void addChild(std::shared_ptr child) override { - JsiBaseDomDeclarationNode::addChild(child); + JsiDomDeclarationNode::addChild(child); // Verify declaration of either shader or image filter verifyChild(child); } @@ -88,15 +69,18 @@ class JsiBlendNode : public JsiBaseDomDeclarationNode, */ void insertChildBefore(std::shared_ptr child, std::shared_ptr before) override { - JsiBaseDomDeclarationNode::insertChildBefore(child, before); + JsiDomDeclarationNode::insertChildBefore(child, before); // Verify declaration of either shader or image filter verifyChild(child); } private: void verifyChild(std::shared_ptr child) { - if (std::dynamic_pointer_cast(child) == nullptr && - std::dynamic_pointer_cast(child) == nullptr) { + if (child->getNodeClass() != NodeClass::DeclarationNode || + (std::static_pointer_cast(child) + ->getDeclarationType() != DeclarationType::Shader && + std::static_pointer_cast(child) + ->getDeclarationType() != DeclarationType::ImageFilter)) { // We'll raise an error when other children are added. std::runtime_error("Blend nodes only supports either shaders or image " "filters as children, got " + diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h index c6500f09dbc77..e98b29e4c60ce 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h @@ -10,39 +10,39 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkBlurTypes.h" +#include "SkMaskFilter.h" #pragma clang diagnostic pop namespace RNSkia { -class JsiBlurMaskNode : public JsiBaseDomDeclarationNode, +class JsiBlurMaskNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiBlurMaskNode(std::shared_ptr context) - : JsiBaseDomDeclarationNode(context, "skBlurMaskFilter") {} + : JsiDomDeclarationNode(context, "skBlurMaskFilter", + DeclarationType::MaskFilter) {} -protected: - void decorate(DrawingContext *context) override { - if (context->isChanged() || getPropsContainer()->isChanged()) { + void decorate(DeclarationContext *context) override { - bool respectCTM = - _respectCTM->isSet() ? _respectCTM->value().getAsBool() : true; - SkBlurStyle style = SkBlurStyle::kNormal_SkBlurStyle; - if (_style->isSet()) { - style = getBlurStyleFromString(_style->value().getAsString()); - } + bool respectCTM = + _respectCTM->isSet() ? _respectCTM->value().getAsBool() : true; + SkBlurStyle style = SkBlurStyle::kNormal_SkBlurStyle; + if (_style->isSet()) { + style = getBlurStyleFromString(_style->value().getAsString()); + } - auto filter = SkMaskFilter::MakeBlur(style, _blur->value().getAsNumber(), - respectCTM); + auto filter = + SkMaskFilter::MakeBlur(style, _blur->value().getAsNumber(), respectCTM); - // Set the mask filter - context->getMutablePaint()->setMaskFilter(filter); - } + // Set the mask filter + context->getMaskFilters()->push(filter); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _style = container->defineProperty("style"); _respectCTM = container->defineProperty("respectCTM"); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h index cfbb0bf687096..b3d97160963dc 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h @@ -7,21 +7,22 @@ namespace RNSkia { -class JsiBoxShadowNode : public JsiBaseDomDeclarationNode, +class JsiBoxShadowNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiBoxShadowNode(std::shared_ptr context) - : JsiBaseDomDeclarationNode(context, "skBoxShadow") {} + : JsiDomDeclarationNode(context, "skBoxShadow", + DeclarationType::Unknown) {} BoxShadowProps *getBoxShadowProps() { return _boxShadowProps; } -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { // Do nothing, we are just a container for properties } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _boxShadowProps = container->defineProperty(); } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h index 61cae14ce2178..bef1c97472bc9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h @@ -11,45 +11,26 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkColorFilter.h" #pragma clang diagnostic pop namespace RNSkia { -class JsiBaseColorFilterNode - : public JsiDomDeclarationNode> { +class JsiBaseColorFilterNode : public JsiDomDeclarationNode { public: JsiBaseColorFilterNode(std::shared_ptr context, const char *type) - : JsiDomDeclarationNode>( - context, type) {} + : JsiDomDeclarationNode(context, type, DeclarationType::ColorFilter) {} protected: - sk_sp resolve(std::shared_ptr child) override { - auto ptr = std::dynamic_pointer_cast(child); - if (ptr) { - return ptr->getCurrent(); - } - return nullptr; - } - - void setColorFilter(DrawingContext *context, sk_sp f) { - set(context, f); - } - - void set(DrawingContext *context, sk_sp ColorFilter) override { - auto paint = context->getMutablePaint(); - if (paint->getColorFilter() != nullptr && - paint->getColorFilter() != getCurrent().get()) { - paint->setColorFilter( - SkColorFilters::Compose(ColorFilter, paint->refColorFilter())); - } else { - paint->setColorFilter(ColorFilter); - } - - setCurrent(ColorFilter); + void composeAndPush(DeclarationContext *context, sk_sp cf1) { + context->save(); + decorateChildren(context); + auto cf2 = context->getColorFilters()->popAsOne(); + context->restore(); + auto cf = cf2 ? SkColorFilters::Compose(cf1, cf2) : cf1; + context->getColorFilters()->push(cf); } }; @@ -61,22 +42,20 @@ class JsiMatrixColorFilterNode std::shared_ptr context) : JsiBaseColorFilterNode(context, "skMatrixColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto array = _matrixProp->value().getAsArray(); - float matrix[20]; - for (int i = 0; i < 20; i++) { - if (array.size() > i) { - matrix[i] = array[i].getAsNumber(); - } + void decorate(DeclarationContext *context) override { + auto array = _matrixProp->value().getAsArray(); + float matrix[20]; + for (int i = 0; i < 20; i++) { + if (array.size() > i) { + matrix[i] = array[i].getAsNumber(); } - setColorFilter(context, SkColorFilters::Matrix(matrix)); } + composeAndPush(context, SkColorFilters::Matrix(matrix)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _matrixProp = container->defineProperty("matrix"); _matrixProp->require(); } @@ -91,17 +70,15 @@ class JsiBlendColorFilterNode : public JsiBaseColorFilterNode, explicit JsiBlendColorFilterNode(std::shared_ptr context) : JsiBaseColorFilterNode(context, "skBlendColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - setColorFilter(context, - SkColorFilters::Blend(*_colorProp->getDerivedValue(), - *_blendModeProp->getDerivedValue())); - } + void decorate(DeclarationContext *context) override { + auto color = _colorProp->getDerivedValue(); + auto mode = _blendModeProp->getDerivedValue(); + composeAndPush(context, SkColorFilters::Blend(*color, *mode)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _blendModeProp = container->defineProperty("mode"); _colorProp = container->defineProperty("color"); @@ -122,11 +99,8 @@ class JsiLinearToSRGBGammaColorFilterNode std::shared_ptr context) : JsiBaseColorFilterNode(context, "skLinearToSRGBGammaColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - setColorFilter(context, SkColorFilters::LinearToSRGBGamma()); - } + void decorate(DeclarationContext *context) override { + composeAndPush(context, SkColorFilters::LinearToSRGBGamma()); } }; @@ -138,11 +112,8 @@ class JsiSRGBToLinearGammaColorFilterNode std::shared_ptr context) : JsiBaseColorFilterNode(context, "skSRGBToLinearGammaColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - setColorFilter(context, SkColorFilters::SRGBToLinearGamma()); - } + void decorate(DeclarationContext *context) override { + composeAndPush(context, SkColorFilters::SRGBToLinearGamma()); } }; @@ -152,11 +123,8 @@ class JsiLumaColorFilterNode : public JsiBaseColorFilterNode, explicit JsiLumaColorFilterNode(std::shared_ptr context) : JsiBaseColorFilterNode(context, "skLumaColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - setColorFilter(context, SkLumaColorFilter::Make()); - } + void decorate(DeclarationContext *context) override { + composeAndPush(context, SkLumaColorFilter::Make()); } }; @@ -166,17 +134,25 @@ class JsiLerpColorFilterNode : public JsiBaseColorFilterNode, explicit JsiLerpColorFilterNode(std::shared_ptr context) : JsiBaseColorFilterNode(context, "skLerpColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - setColorFilter(context, - SkColorFilters::Lerp(_tProp->value().getAsNumber(), - requireChild(0), requireChild(1))); + void decorate(DeclarationContext *context) override { + context->save(); + decorateChildren(context); + auto second = context->getColorFilters()->pop(); + auto first = context->getColorFilters()->pop(); + context->restore(); + + if (first == nullptr || second == nullptr) { + throw std::runtime_error( + "LerpColorFilterNode: missing two color filters as children"); } + + auto t = _tProp->value().getAsNumber(); + context->getColorFilters()->push(SkColorFilters::Lerp(t, first, second)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _tProp = container->defineProperty("t"); _tProp->require(); } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGlyphsNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGlyphsNode.h index 5397d6b4048b9..a54a6e3840789 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGlyphsNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGlyphsNode.h @@ -20,12 +20,14 @@ class JsiGlyphsNode : public JsiDomDrawingNode, auto x = _xProp->value().getAsNumber(); auto y = _yProp->value().getAsNumber(); auto font = _fontProp->getDerivedValue(); - auto glyphInfo = _glyphsProp->getDerivedValue(); - - context->getCanvas()->drawGlyphs( - static_cast(glyphInfo->glyphIds.size()), - glyphInfo->glyphIds.data(), glyphInfo->positions.data(), - SkPoint::Make(x, y), *font, *context->getPaint()); + if (font != nullptr) { + auto glyphInfo = _glyphsProp->getDerivedValue(); + + context->getCanvas()->drawGlyphs( + static_cast(glyphInfo->glyphIds.size()), + glyphInfo->glyphIds.data(), glyphInfo->positions.data(), + SkPoint::Make(x, y), *font, *context->getPaint()); + } } void defineProperties(NodePropsContainer *container) override { @@ -36,7 +38,6 @@ class JsiGlyphsNode : public JsiDomDrawingNode, _xProp = container->defineProperty("x"); _yProp = container->defineProperty("y"); - _fontProp->require(); _glyphsProp->require(); _xProp->require(); _yProp->require(); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGroupNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGroupNode.h index 55e4249c60ccf..0d42adb0a7e11 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGroupNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGroupNode.h @@ -15,7 +15,7 @@ class JsiGroupNode : public JsiDomRenderNode, void renderNode(DrawingContext *context) override { for (auto &child : getChildren()) { - if (child->getNodeClass() == JsiDomNodeClass::RenderNode) { + if (child->getNodeClass() == NodeClass::RenderNode) { std::static_pointer_cast(child)->render(context); } } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h index 8a29549617878..7273a5b7987da 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h @@ -16,55 +16,33 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkImageFilter.h" #pragma clang diagnostic pop namespace RNSkia { -class JsiBaseImageFilterNode - : public JsiDomDeclarationNode> { +class JsiBaseImageFilterNode : public JsiDomDeclarationNode { public: JsiBaseImageFilterNode(std::shared_ptr context, const char *type) - : JsiDomDeclarationNode>( - context, type) {} + : JsiDomDeclarationNode(context, type, DeclarationType::ImageFilter) {} protected: - sk_sp resolve(std::shared_ptr child) override { - auto imageFilterPtr = - std::dynamic_pointer_cast(child); - if (imageFilterPtr) { - return imageFilterPtr->getCurrent(); + void composeAndPush(DeclarationContext *context, sk_sp imgf1) { + context->save(); + decorateChildren(context); + auto imgf2 = context->getImageFilters()->popAsOne(); + auto cf = context->getColorFilters()->popAsOne(); + context->restore(); + if (cf != nullptr) { + imgf2 = SkImageFilters::Compose(imgf2, + SkImageFilters::ColorFilter(cf, nullptr)); } - auto shaderPtr = std::dynamic_pointer_cast(child); - if (shaderPtr) { - return SkImageFilters::Shader(shaderPtr->getCurrent()); - } - auto colorFilterPtr = - std::dynamic_pointer_cast(child); - if (colorFilterPtr) { - return SkImageFilters::ColorFilter(colorFilterPtr->getCurrent(), nullptr); - } - return nullptr; - } + auto imgf = + imgf2 != nullptr ? SkImageFilters::Compose(imgf1, imgf2) : imgf1; - void setImageFilter(DrawingContext *context, sk_sp f) { - set(context, f); - } - - void set(DrawingContext *context, sk_sp imageFilter) override { - auto paint = context->getMutablePaint(); - if (paint->getImageFilter() != nullptr && - paint->getImageFilter() != getCurrent().get()) { - paint->setImageFilter( - SkImageFilters::Compose(paint->refImageFilter(), imageFilter)); - } else { - paint->setImageFilter(imageFilter); - } - - setCurrent(imageFilter); + context->getImageFilters()->push(imgf); } }; @@ -74,26 +52,23 @@ class JsiBlendImageFilterNode : public JsiBaseImageFilterNode, explicit JsiBlendImageFilterNode(std::shared_ptr context) : JsiBaseImageFilterNode(context, "skBlendImageFilter") {} -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { - if (isChanged(context)) { - - if (getChildren().size() != 2) { - throw std::runtime_error("Blend image filter needs two child nodes."); - } + if (getChildren().size() != 2) { + throw std::runtime_error("Blend image filter needs two child nodes."); + } - auto background = requireChild(0); - auto foreground = requireChild(1); + auto background = context->getImageFilters()->pop(); + auto foreground = context->getImageFilters()->pop(); - SkBlendMode blendMode = *_blendModeProp->getDerivedValue(); - setImageFilter(context, - SkImageFilters::Blend(blendMode, background, foreground)); - } + SkBlendMode blendMode = *_blendModeProp->getDerivedValue(); + composeAndPush(context, + SkImageFilters::Blend(blendMode, background, foreground)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _blendModeProp = container->defineProperty("mode"); _blendModeProp->require(); } @@ -110,49 +85,50 @@ class JsiDropShadowImageFilterNode std::shared_ptr context) : JsiBaseImageFilterNode(context, "skDropShadowImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto color = _colorProp->getDerivedValue(); - auto dx = _dxProp->value().getAsNumber(); - auto dy = _dxProp->value().getAsNumber(); - auto blur = _blurProp->value().getAsNumber(); - auto input = optionalChild(0); - - auto inner = _innerProp->isSet() && _innerProp->value().getAsBool(); - auto shadowOnly = - _shadowOnlyProp->isSet() && _shadowOnlyProp->value().getAsBool(); - - if (inner) { - auto srcGraphic = SkImageFilters::ColorFilter( - SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kDst), nullptr); - auto srcAlpha = SkImageFilters::ColorFilter( - SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kSrcIn), nullptr); - auto f1 = SkImageFilters::ColorFilter( - SkColorFilters::Blend(*color, SkBlendMode::kSrcOut), nullptr); - auto f2 = SkImageFilters::Offset(dx, dy, f1); - auto f3 = SkImageFilters::Blur(blur, blur, SkTileMode::kDecal, f2); - auto f4 = SkImageFilters::Blend(SkBlendMode::kSrcIn, srcAlpha, f3); - - setImageFilter(context, SkImageFilters::Compose( + void decorate(DeclarationContext *context) override { + + auto color = _colorProp->getDerivedValue(); + auto dx = _dxProp->value().getAsNumber(); + auto dy = _dyProp->value().getAsNumber(); + auto blur = _blurProp->value().getAsNumber(); + auto input = context->getImageFilters()->pop(); + + auto inner = _innerProp->isSet() && _innerProp->value().getAsBool(); + auto shadowOnly = + _shadowOnlyProp->isSet() && _shadowOnlyProp->value().getAsBool(); + + if (inner) { + auto srcGraphic = SkImageFilters::ColorFilter( + SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kDst), nullptr); + auto srcAlpha = SkImageFilters::ColorFilter( + SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kSrcIn), nullptr); + auto f1 = SkImageFilters::ColorFilter( + SkColorFilters::Blend(*color, SkBlendMode::kSrcOut), nullptr); + auto f2 = SkImageFilters::Offset(dx, dy, f1); + auto f3 = SkImageFilters::Blur(blur, blur, SkTileMode::kDecal, f2); + auto f4 = SkImageFilters::Blend(SkBlendMode::kSrcIn, srcAlpha, f3); + if (shadowOnly) { + composeAndPush(context, f4); + } else { + composeAndPush(context, SkImageFilters::Compose( input ? input : nullptr, SkImageFilters::Blend(SkBlendMode::kSrcOver, srcGraphic, f4))); - - } else { - setImageFilter( - context, - shadowOnly - ? SkImageFilters::DropShadowOnly(dx, dy, blur, blur, *color, - input ? input : nullptr) - : SkImageFilters::DropShadow(dx, dy, blur, blur, *color, - input ? input : nullptr)); } + + } else { + composeAndPush( + context, + shadowOnly ? SkImageFilters::DropShadowOnly( + dx, dy, blur, blur, *color, input ? input : nullptr) + : SkImageFilters::DropShadow(dx, dy, blur, blur, *color, + input ? input : nullptr)); } } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _dxProp = container->defineProperty("dx"); _dyProp = container->defineProperty("dy"); _blurProp = container->defineProperty("blur"); @@ -184,27 +160,27 @@ class JsiDisplacementMapImageFilterNode std::shared_ptr context) : JsiBaseImageFilterNode(context, "skDisplacementMapImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - - auto channelX = - getColorChannelFromStringValue(_channelXProp->value().getAsString()); - auto channelY = - getColorChannelFromStringValue(_channelYProp->value().getAsString()); - auto scale = _scaleProp->value().getAsNumber(); - - auto displacement = requireChild(0); - auto color = optionalChild(1); - - setImageFilter(context, SkImageFilters::DisplacementMap( - channelX, channelY, scale, displacement, - color ? color : nullptr)); + void decorate(DeclarationContext *context) override { + decorateChildren(context); + auto channelX = + getColorChannelFromStringValue(_channelXProp->value().getAsString()); + auto channelY = + getColorChannelFromStringValue(_channelYProp->value().getAsString()); + auto scale = _scaleProp->value().getAsNumber(); + auto shader = context->getShaders()->pop(); + if (!shader) { + throw std::runtime_error("DisplacementMap expects a shader as child"); } + auto map = SkImageFilters::Shader(shader); + auto input = context->getImageFilters()->pop(); + auto imgf = SkImageFilters::DisplacementMap(channelX, channelY, scale, map, + input ? input : nullptr); + context->getImageFilters()->push(imgf); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _channelXProp = container->defineProperty("channelX"); _channelYProp = container->defineProperty("channelY"); _scaleProp = container->defineProperty("scale"); @@ -240,22 +216,19 @@ class JsiBlurImageFilterNode : public JsiBaseImageFilterNode, explicit JsiBlurImageFilterNode(std::shared_ptr context) : JsiBaseImageFilterNode(context, "skBlurImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto input = optionalChild(0); - setImageFilter( - context, SkImageFilters::Blur(_blurProp->getDerivedValue()->x(), - _blurProp->getDerivedValue()->y(), - _tileModeProp->isSet() - ? *_tileModeProp->getDerivedValue() - : SkTileMode::kDecal, - input ? input : nullptr)); - } + void decorate(DeclarationContext *context) override { + auto input = context->getImageFilters()->pop(); + auto imageFilter = SkImageFilters::Blur( + _blurProp->getDerivedValue()->x(), _blurProp->getDerivedValue()->y(), + _tileModeProp->isSet() ? *_tileModeProp->getDerivedValue() + : SkTileMode::kDecal, + input); + composeAndPush(context, imageFilter); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _blurProp = container->defineProperty("blur"); _tileModeProp = container->defineProperty("mode"); @@ -275,21 +248,18 @@ class JsiOffsetImageFilterNode std::shared_ptr context) : JsiBaseImageFilterNode(context, "skOffsetImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto input = optionalChild(0); - if (getPropsContainer()->isChanged()) { - setImageFilter(context, - SkImageFilters::Offset(_xProp->value().getAsNumber(), - _yProp->value().getAsNumber(), - input ? input : nullptr)); - } - } + void decorate(DeclarationContext *context) override { + decorateChildren(context); + auto input = context->getImageFilters()->pop(); + composeAndPush(context, + SkImageFilters::Offset(_xProp->value().getAsNumber(), + _yProp->value().getAsNumber(), + input ? input : nullptr)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _xProp = container->defineProperty("x"); _yProp = container->defineProperty("y"); @@ -312,26 +282,23 @@ class JsiMorphologyImageFilterNode std::shared_ptr context) : JsiBaseImageFilterNode(context, "skMorphologyImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto op = getTypeFromStringValue(_operatorProp->value().getAsString()); - auto radius = _radiusProp->getDerivedValue(); - auto input = optionalChild(0); - - if (op == Type::Dilate) { - setImageFilter(context, - SkImageFilters::Dilate(radius->x(), radius->y(), - input ? input : nullptr)); - } else { - setImageFilter(context, SkImageFilters::Erode(radius->x(), radius->y(), - input ? input : nullptr)); - } + void decorate(DeclarationContext *context) override { + auto op = getTypeFromStringValue(_operatorProp->value().getAsString()); + auto radius = _radiusProp->getDerivedValue(); + auto input = context->getImageFilters()->pop(); + + if (op == Type::Dilate) { + composeAndPush(context, SkImageFilters::Dilate(radius->x(), radius->y(), + input ? input : nullptr)); + } else { + composeAndPush(context, SkImageFilters::Erode(radius->x(), radius->y(), + input ? input : nullptr)); } } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _operatorProp = container->defineProperty("operator"); _radiusProp = container->defineProperty("radius"); @@ -362,26 +329,23 @@ class JsiRuntimeShaderImageFilterNode std::shared_ptr context) : JsiBaseImageFilterNode(context, "skRuntimeShaderImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto source = _sourceProp->value().getAs(); - if (source == nullptr) { - throw std::runtime_error("Expected runtime effect when reading source " - "property of RuntimeEffectImageFilter."); - } + void decorate(DeclarationContext *context) override { + auto source = _sourceProp->value().getAs(); + if (source == nullptr) { + throw std::runtime_error("Expected runtime effect when reading source " + "property of RuntimeEffectImageFilter."); + } - auto builder = SkRuntimeShaderBuilder(source->getObject()); - auto input = optionalChild(0); - _uniformsProp->processUniforms(builder); + auto builder = SkRuntimeShaderBuilder(source->getObject()); + auto input = context->getImageFilters()->pop(); + _uniformsProp->processUniforms(builder); - setImageFilter(context, - SkImageFilters::RuntimeShader(builder, "", input)); - } + composeAndPush(context, SkImageFilters::RuntimeShader(builder, "", input)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _sourceProp = container->defineProperty("source"); _uniformsProp = container->defineProperty("uniforms", _sourceProp); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageNode.h index cf18ce1fc93a0..46d6a2943fd1d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageNode.h @@ -16,15 +16,19 @@ class JsiImageNode : public JsiDomDrawingNode, protected: void draw(DrawingContext *context) override { auto rects = _imageProps->getDerivedValue(); + auto image = _imageProps->getImage(); + if (image == nullptr) { + return; + } + context->getCanvas()->drawImageRect( - _imageProps->getImage(), rects->src, rects->dst, SkSamplingOptions(), + image, rects->src, rects->dst, SkSamplingOptions(), context->getPaint().get(), SkCanvas::kStrict_SrcRectConstraint); } void defineProperties(NodePropsContainer *container) override { JsiDomDrawingNode::defineProperties(container); _imageProps = container->defineProperty(); - _imageProps->require(); } private: diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageSvgNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageSvgNode.h index 4589c63457fbb..1b207807263ff 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageSvgNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageSvgNode.h @@ -17,26 +17,47 @@ class JsiImageSvgNode : public JsiDomDrawingNode, protected: void draw(DrawingContext *context) override { auto svgDom = _svgDomProp->getDerivedValue(); - auto rect = _rectProp->getDerivedValue(); - - context->getCanvas()->save(); - context->getCanvas()->translate(rect->x(), rect->y()); - svgDom->setContainerSize(SkSize::Make(rect->width(), rect->height())); - svgDom->render(context->getCanvas()); - context->getCanvas()->restore(); + if (svgDom != nullptr) { + auto rect = _rectProp->getDerivedValue(); + auto x = _xProp->isSet() ? _xProp->value().getAsNumber() : -1; + auto y = _yProp->isSet() ? _yProp->value().getAsNumber() : -1; + auto width = _widthProp->isSet() ? _widthProp->value().getAsNumber() : -1; + auto height = + _widthProp->isSet() ? _heightProp->value().getAsNumber() : -1; + context->getCanvas()->save(); + if (rect != nullptr) { + context->getCanvas()->translate(rect->x(), rect->y()); + svgDom->setContainerSize(SkSize::Make(rect->width(), rect->height())); + } else { + if (x != -1 && y != -1) { + context->getCanvas()->translate(x, y); + } + if (width != -1 && height != -1) { + svgDom->setContainerSize(SkSize::Make(width, height)); + } + } + svgDom->render(context->getCanvas()); + context->getCanvas()->restore(); + } } void defineProperties(NodePropsContainer *container) override { JsiDomDrawingNode::defineProperties(container); _svgDomProp = container->defineProperty("svg"); _rectProp = container->defineProperty("rect"); - - _svgDomProp->require(); + _xProp = container->defineProperty("x"); + _yProp = container->defineProperty("y"); + _widthProp = container->defineProperty("width"); + _heightProp = container->defineProperty("height"); } private: SvgProp *_svgDomProp; RectProps *_rectProp; + NodeProp *_xProp; + NodeProp *_yProp; + NodeProp *_widthProp; + NodeProp *_heightProp; }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiLayerNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiLayerNode.h index 3405062e7c717..adc44060743ce 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiLayerNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiLayerNode.h @@ -18,38 +18,48 @@ class JsiLayerNode : public JsiDomRenderNode, protected: void renderNode(DrawingContext *context) override { - bool isLayer = false; + auto hasLayer = false; auto children = getChildren(); - auto size = children.size(); // Is the first children a layer? - for (size_t i = 0; i < size; ++i) { + for (size_t i = 0; i < children.size(); ++i) { if (i == 0) { // Check for paint node as layer - auto paintNode = - std::dynamic_pointer_cast(children.at(i)); + if (children.at(i)->getNodeClass() == NodeClass::DeclarationNode) { + auto declarationNode = + std::static_pointer_cast(children.at(i)); - if (paintNode != nullptr) { - // Yes, it is a paint node - which we can use as a layer. - isLayer = true; - // Save canvas with the paint node's paint! - context->getCanvas()->saveLayer(SkCanvas::SaveLayerRec( - nullptr, paintNode->getPaint().get(), nullptr, 0)); + if (declarationNode->getDeclarationType() == DeclarationType::Paint) { + // Yes, it is a paint node - which we can use as a layer. + auto declarationContext = context->getDeclarationContext(); + auto layerNode = + std::static_pointer_cast(children.at(i)); - continue; + // Save canvas with the paint node's paint! + declarationContext->save(); + layerNode->decorate(declarationContext); + auto paint = declarationContext->getPaints()->pop(); + declarationContext->restore(); + + if (paint) { + hasLayer = true; + context->getCanvas()->saveLayer( + SkCanvas::SaveLayerRec(nullptr, paint.get(), nullptr, 0)); + } + + continue; + } } } // Render rest of the children - auto renderNode = - std::dynamic_pointer_cast(children.at(i)); - - if (renderNode != nullptr) { - renderNode->render(context); + if (children.at(i)->getNodeClass() == NodeClass::RenderNode) { + std::static_pointer_cast(children.at(i)) + ->render(context); } } - if (isLayer) { + if (hasLayer) { context->getCanvas()->restore(); } } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPaintNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPaintNode.h index c40bbcdd9f40a..d967b7515c8b2 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPaintNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPaintNode.h @@ -7,72 +7,109 @@ namespace RNSkia { -// TODO: implement feature: A paint node has its own paint not inherited, -// and when found the drawing node should render an extra time for -// each paint node in its children. - -class JsiPaintNode : public JsiBaseDomDeclarationNode, +class JsiPaintNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiPaintNode(std::shared_ptr context) - : JsiBaseDomDeclarationNode(context, "skPaint") {} - - /** - Returns a pointer to the local paint context in the paint node. This is a - special case for declaration nodes since the Paint node has a bit different - semantic than other declaration nodes. - */ - DrawingContext *getDrawingContext() { return _localContext.get(); } - - /** - We need to override the decorate node call to avoid letting children - decorate before we have created our child context. - */ - void decorateContext(DrawingContext *context) override { - // A paint node should have its own local paint - if (_localContext == nullptr) { - _localContext = context->inheritContext("PaintNode"); + : JsiDomDeclarationNode(context, "skPaint", DeclarationType::Paint) {} + + void decorate(DeclarationContext *context) override { + auto paint = std::make_shared(); + paint->setAntiAlias(true); + + if (_paintProps->getOpacity()->isSet()) { + paint->setAlphaf(paint->getAlphaf() * + _paintProps->getOpacity()->value().getAsNumber()); + } + + if (_paintProps->getColor()->isSet()) { + auto currentOpacity = paint->getAlphaf(); + paint->setShader(nullptr); + paint->setColor(*_paintProps->getColor()->getDerivedValue()); + paint->setAlphaf(paint->getAlphaf() * currentOpacity); } - // ...and it should be a totally new paint, not inheriting from parent - // paint. - if (_localContext->isChanged()) { - auto paint = std::make_shared(); - paint->setAntiAlias(true); - _localContext->setMutablePaint(paint); + if (_paintProps->getStrokeWidth()->isSet()) { + paint->setStrokeWidth( + _paintProps->getStrokeWidth()->value().getAsNumber()); } - // Let's decorate paint props - _paintProps->decorate(_localContext.get()); + if (_paintProps->getBlendMode()->isSet()) { + paint->setBlendMode(*_paintProps->getBlendMode()->getDerivedValue()); + } - // Materialize children who will now only change the paint node's paint - for (auto &child : getChildren()) { - auto decl = std::dynamic_pointer_cast(child); - if (decl != nullptr) { - decl->decorateContext(_localContext.get()); + if (_paintProps->getStyle()->isSet()) { + auto styleValue = _paintProps->getStyle()->value().getAsString(); + if (styleValue == "stroke") { + paint->setStyle(SkPaint::Style::kStroke_Style); + } else if (styleValue == "fill") { + paint->setStyle(SkPaint::Style::kFill_Style); + } else { + throw std::runtime_error( + styleValue + " is not a valud value for the style property."); } } - } - std::shared_ptr getPaint() { - return _localContext->getPaint(); + if (_paintProps->getStrokeJoin()->isSet()) { + paint->setStrokeJoin(*_paintProps->getStrokeJoin()->getDerivedValue()); + } + + if (_paintProps->getStrokeCap()->isSet()) { + paint->setStrokeCap(*_paintProps->getStrokeCap()->getDerivedValue()); + } + + if (_paintProps->getStrokeMiter()->isSet()) { + paint->setStrokeMiter( + _paintProps->getStrokeMiter()->value().getAsNumber()); + } + + if (_paintProps->getAntiAlias()->isSet()) { + paint->setAntiAlias(_paintProps->getAntiAlias()->value().getAsBool()); + } + + context->save(); + decorateChildren(context); + + auto imageFilter = context->getImageFilters()->popAsOne(); + auto colorFilter = context->getColorFilters()->popAsOne(); + auto shader = context->getShaders()->pop(); + auto maskFilter = context->getMaskFilters()->pop(); + auto pathEffect = context->getPathEffects()->popAsOne(); + + context->restore(); + + if (imageFilter) { + paint->setImageFilter(imageFilter); + } + + if (colorFilter) { + paint->setColorFilter(colorFilter); + } + + if (shader) { + paint->setShader(shader); + } + + if (maskFilter) { + paint->setMaskFilter(maskFilter); + } + + if (pathEffect) { + paint->setPathEffect(pathEffect); + } + + context->getPaints()->push(paint); } protected: - void decorate(DrawingContext *context) override {} - void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _paintProps = container->defineProperty(); - _opacityProp = container->defineProperty("opacity"); } private: - NodeProp *_opacityProp; PaintProps *_paintProps; - - std::shared_ptr _localContext; }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h index 2de7d2b6c6ae1..d9d8b249c8a03 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h @@ -11,46 +11,26 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPathEffect.h" #pragma clang diagnostic pop namespace RNSkia { -class JsiBasePathEffectNode - : public JsiDomDeclarationNode> { +class JsiBasePathEffectNode : public JsiDomDeclarationNode { public: JsiBasePathEffectNode(std::shared_ptr context, const char *type) - : JsiDomDeclarationNode>( - context, type) {} + : JsiDomDeclarationNode(context, type, DeclarationType::PathEffect) {} protected: - void setPathEffect(DrawingContext *context, sk_sp f) { - set(context, f); - } - - sk_sp resolve(std::shared_ptr child) override { - auto ptr = std::dynamic_pointer_cast(child); - if (ptr) { - return ptr->getCurrent(); - } - return nullptr; - } - - /** - Sets or composes the path effect - */ - void set(DrawingContext *context, sk_sp pathEffect) override { - auto paint = context->getMutablePaint(); - if (paint->getPathEffect() != nullptr && - paint->getPathEffect() != getCurrent().get()) { - paint->setPathEffect( - SkPathEffect::MakeCompose(paint->refPathEffect(), pathEffect)); - } else { - paint->setPathEffect(pathEffect); - } - setCurrent(pathEffect); + void composeAndPush(DeclarationContext *context, sk_sp pe1) { + context->save(); + decorateChildren(context); + auto pe2 = context->getPathEffects()->popAsOne(); + context->restore(); + auto pe = pe2 ? SkPathEffect::MakeCompose(pe1, pe2) : pe1; + context->getPathEffects()->push(pe); } }; @@ -60,30 +40,28 @@ class JsiDashPathEffectNode : public JsiBasePathEffectNode, explicit JsiDashPathEffectNode(std::shared_ptr context) : JsiBasePathEffectNode(context, "skDashPathEffect") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { + void decorate(DeclarationContext *context) override { - // Phase - auto phase = _phase->isSet() ? _phase->value().getAsNumber() : 0; + // Phase + auto phase = _phase->isSet() ? _phase->value().getAsNumber() : 0; - // Copy intervals - std::vector intervals; - auto intervalsArray = _intervals->value().getAsArray(); - for (size_t i = 0; i < intervalsArray.size(); ++i) { - intervals.push_back(intervalsArray[i].getAsNumber()); - } + // Copy intervals + std::vector intervals; + auto intervalsArray = _intervals->value().getAsArray(); + for (size_t i = 0; i < intervalsArray.size(); ++i) { + intervals.push_back(intervalsArray[i].getAsNumber()); + } - // Create effect - auto pathEffect = SkDashPathEffect::Make( - intervals.data(), static_cast(intervals.size()), phase); + // Create effect + auto pathEffect = SkDashPathEffect::Make( + intervals.data(), static_cast(intervals.size()), phase); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _intervals = container->defineProperty("intervals"); _phase = container->defineProperty("phase"); @@ -104,22 +82,19 @@ class JsiDiscretePathEffectNode std::shared_ptr context) : JsiBasePathEffectNode(context, "skDiscretePathEffect") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - - // Create effect - auto pathEffect = - SkDiscretePathEffect::Make(_lengthProp->value().getAsNumber(), - _deviationProp->value().getAsNumber(), - _seedProp->value().getAsNumber()); + void decorate(DeclarationContext *context) override { + // Create effect + auto pathEffect = + SkDiscretePathEffect::Make(_lengthProp->value().getAsNumber(), + _deviationProp->value().getAsNumber(), + _seedProp->value().getAsNumber()); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _lengthProp = container->defineProperty("length"); _deviationProp = container->defineProperty("deviation"); @@ -142,19 +117,16 @@ class JsiCornerPathEffectNode : public JsiBasePathEffectNode, explicit JsiCornerPathEffectNode(std::shared_ptr context) : JsiBasePathEffectNode(context, "skCornerPathEffect") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - - // Create effect - auto pathEffect = SkCornerPathEffect::Make(_rProp->value().getAsNumber()); + void decorate(DeclarationContext *context) override { + // Create effect + auto pathEffect = SkCornerPathEffect::Make(_rProp->value().getAsNumber()); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _rProp = container->defineProperty("r"); _rProp->require(); @@ -170,22 +142,19 @@ class JsiPath1DPathEffectNode : public JsiBasePathEffectNode, explicit JsiPath1DPathEffectNode(std::shared_ptr context) : JsiBasePathEffectNode(context, "skPath1DPathEffect") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - - // Create effect - auto pathEffect = SkPath1DPathEffect::Make( - *_pathProp->getDerivedValue(), _advanceProp->value().getAsNumber(), - _phaseProp->value().getAsNumber(), - getStyleFromStringValue(_styleProp->value().getAsString())); + void decorate(DeclarationContext *context) override { + // Create effect + auto pathEffect = SkPath1DPathEffect::Make( + *_pathProp->getDerivedValue(), _advanceProp->value().getAsNumber(), + _phaseProp->value().getAsNumber(), + getStyleFromStringValue(_styleProp->value().getAsString())); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _phaseProp = container->defineProperty("phase"); _advanceProp = container->defineProperty("advance"); @@ -224,19 +193,17 @@ class JsiPath2DPathEffectNode : public JsiBasePathEffectNode, : JsiBasePathEffectNode(context, "skPath2DPathEffect") {} protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { + void decorate(DeclarationContext *context) override { - // Create effect - auto pathEffect = SkPath2DPathEffect::Make( - *_matrixProp->getDerivedValue(), *_pathProp->getDerivedValue()); + // Create effect + auto pathEffect = SkPath2DPathEffect::Make(*_matrixProp->getDerivedValue(), + *_pathProp->getDerivedValue()); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _matrixProp = container->defineProperty("matrix"); _pathProp = container->defineProperty("path"); @@ -257,19 +224,17 @@ class JsiLine2DPathEffectNode : public JsiBasePathEffectNode, : JsiBasePathEffectNode(context, "skLine2DPathEffect") {} protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { + void decorate(DeclarationContext *context) override { - // Create effect - auto pathEffect = SkLine2DPathEffect::Make( - _widthProp->value().getAsNumber(), *_matrixProp->getDerivedValue()); + // Create effect + auto pathEffect = SkLine2DPathEffect::Make( + _widthProp->value().getAsNumber(), *_matrixProp->getDerivedValue()); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _matrixProp = container->defineProperty("matrix"); _widthProp = container->defineProperty("width"); @@ -290,12 +255,14 @@ class JsiSumPathEffectNode : public JsiBasePathEffectNode, : JsiBasePathEffectNode(context, "skSumPathEffect") {} protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto inner = requireChild(0); - auto outer = requireChild(1); - setPathEffect(context, SkPathEffect::MakeSum(inner, outer)); - } + void decorate(DeclarationContext *context) override { + decorateChildren(context); + auto pe = + context->getPathEffects()->Declaration>::popAsOne( + [=](sk_sp inner, sk_sp outer) { + return SkPathEffect::MakeSum(inner, outer); + }); + context->getPathEffects()->push(pe); } }; } // namespace RNSkia diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h index aa185aa48b4f4..e98ec8f13bcd9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h @@ -3,13 +3,14 @@ #include "JsiDomDrawingNode.h" #include "PathProp.h" +#include #include #include #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkTrimPathEffect.h" #pragma clang diagnostic pop @@ -27,12 +28,14 @@ class JsiPathNode : public JsiDomDrawingNode, protected: void draw(DrawingContext *context) override { if (getPropsContainer()->isChanged()) { + auto start = saturate( + _startProp->isSet() ? _startProp->value().getAsNumber() : 0.0); + auto end = + saturate(_endProp->isSet() ? _endProp->value().getAsNumber() : 1.0); // Can we use the path directly, or do we need to copy to // mutate / modify the path? - auto hasStartOffset = - _startProp->isSet() && _startProp->value().getAsNumber() != 0.0; - auto hasEndOffset = - _endProp->isSet() && _endProp->value().getAsNumber() != 1.0; + auto hasStartOffset = start != 0.0; + auto hasEndOffset = end != 1.0; auto hasFillStyle = _fillTypeProp->isSet(); auto hasStrokeOptions = _strokeOptsProp->isSet() && @@ -44,9 +47,6 @@ class JsiPathNode : public JsiDomDrawingNode, if (willMutatePath) { // We'll trim the path SkPath filteredPath(*_pathProp->getDerivedValue()); - auto start = - _startProp->isSet() ? _startProp->value().getAsNumber() : 0.0; - auto end = _endProp->isSet() ? _endProp->value().getAsNumber() : 1.0; auto pe = SkTrimPathEffect::Make(start, end, SkTrimPathEffect::Mode::kNormal); @@ -55,16 +55,14 @@ class JsiPathNode : public JsiDomDrawingNode, if (!pe->filterPath(&filteredPath, filteredPath, &rec, nullptr)) { throw std::runtime_error( "Failed trimming path with parameters start: " + - std::to_string(_startProp->value().getAsNumber()) + - ", end: " + std::to_string(_endProp->value().getAsNumber())); + std::to_string(start) + ", end: " + std::to_string(end)); } filteredPath.swap(filteredPath); _path = std::make_shared(filteredPath); } else if (hasStartOffset || hasEndOffset) { throw std::runtime_error( "Failed trimming path with parameters start: " + - std::to_string(_startProp->value().getAsNumber()) + - ", end: " + std::to_string(_endProp->value().getAsNumber())); + std::to_string(start) + ", end: " + std::to_string(end)); } else { _path = std::make_shared(filteredPath); } @@ -110,8 +108,8 @@ class JsiPathNode : public JsiDomDrawingNode, // _path is const so we can't mutate it directly, let's replace the // path like this: auto p = std::make_shared(*_path.get()); - if (!strokePaint.getFillPath(*_path.get(), p.get(), nullptr, - precision)) { + if (!skpathutils::FillPathWithPaint(*_path.get(), strokePaint, + p.get(), nullptr, precision)) { _path = nullptr; } else { _path = std::const_pointer_cast(p); @@ -144,6 +142,8 @@ class JsiPathNode : public JsiDomDrawingNode, } private: + float saturate(float x) { return std::max(0.0f, std::min(1.0f, x)); } + SkPathFillType getFillTypeFromStringValue(const std::string &value) { if (value == "winding") { return SkPathFillType::kWinding; @@ -169,8 +169,9 @@ class JsiPathNode : public JsiDomDrawingNode, class StrokeOptsProps : public BaseDerivedProp { public: - StrokeOptsProps() : BaseDerivedProp() { - _strokeProp = addProperty(std::make_shared("stroke")); + explicit StrokeOptsProps(const std::function &onChange) + : BaseDerivedProp(onChange) { + _strokeProp = defineProperty("stroke"); } private: diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPointsNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPointsNode.h index 90dc4c2947ac4..25eb21c23da86 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPointsNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPointsNode.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkCanvas.h" #pragma clang diagnostic pop diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiShaderNodes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiShaderNodes.h index 97361d5da7355..6a4e3069d522e 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiShaderNodes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiShaderNodes.h @@ -17,90 +17,54 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkShader.h" #pragma clang diagnostic pop namespace RNSkia { -class JsiBaseShaderNode - : public JsiDomDeclarationNode> { -public: - JsiBaseShaderNode(std::shared_ptr context, - const char *type) - : JsiDomDeclarationNode>(context, - type) {} - -protected: - sk_sp resolve(std::shared_ptr child) override { - auto ptr = std::dynamic_pointer_cast(child); - if (ptr) { - return ptr->getCurrent(); - } - return nullptr; - } - - void setShader(DrawingContext *context, sk_sp f) { - set(context, f); - } - - void set(DrawingContext *context, sk_sp shader) override { - auto paint = context->getMutablePaint(); - paint->setShader(shader); - setCurrent(shader); - } -}; - -class JsiShaderNode : public JsiBaseShaderNode, +class JsiShaderNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiShaderNode(std::shared_ptr context) - : JsiBaseShaderNode(context, "skShader") {} - -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto source = _sourceProp->value().getAs(); - if (source == nullptr) { - throw std::runtime_error("Expected runtime effect when reading source " - "property of RuntimeEffectImageFilter."); - } - auto uniforms = - _uniformsProp->isSet() ? _uniformsProp->getDerivedValue() : nullptr; - - SkMatrix lm; - auto tm = - _transformProp->isSet() ? _transformProp->getDerivedValue() : nullptr; - - if (tm != nullptr) { - if (_originProp->isSet()) { - auto tr = _originProp->getDerivedValue(); - lm.preTranslate(tr->x(), tr->y()); - lm.preConcat(*tm); - lm.preTranslate(-tr->x(), -tr->y()); - } else { - lm.preConcat(*tm); - } + : JsiDomDeclarationNode(context, "skShader", DeclarationType::Shader) {} + + void decorate(DeclarationContext *context) override { + decorateChildren(context); + auto source = _sourceProp->value().getAs(); + if (source == nullptr) { + throw std::runtime_error("Expected runtime effect when reading source " + "property of RuntimeEffectImageFilter."); + } + auto uniforms = + _uniformsProp->isSet() ? _uniformsProp->getDerivedValue() : nullptr; + + SkMatrix lm; + auto tm = + _transformProp->isSet() ? _transformProp->getDerivedValue() : nullptr; + + if (tm != nullptr) { + if (_originProp->isSet()) { + auto tr = _originProp->getDerivedValue(); + lm.preTranslate(tr->x(), tr->y()); + lm.preConcat(*tm); + lm.preTranslate(-tr->x(), -tr->y()); + } else { + lm.preConcat(*tm); } + } - // get all children that are shader nodes - std::vector> children; - children.reserve(getChildren().size()); - for (auto &child : getChildren()) { - auto ptr = std::dynamic_pointer_cast(child); - if (ptr != nullptr) { - children.push_back(ptr->getCurrent()); - } - } + // get all children that are shader nodes + auto children = context->getShaders()->popAll(); - // Update shader - setShader(context, source->getObject()->makeShader( - uniforms, children.data(), children.size(), &lm)); - } + // Update shader + context->getShaders()->push(source->getObject()->makeShader( + uniforms, children.data(), children.size(), &lm)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _sourceProp = container->defineProperty("source"); _uniformsProp = container->defineProperty("uniforms", _sourceProp); @@ -117,55 +81,56 @@ class JsiShaderNode : public JsiBaseShaderNode, PointProp *_originProp; }; -class JsiImageShaderNode : public JsiBaseShaderNode, +class JsiImageShaderNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiImageShaderNode(std::shared_ptr context) - : JsiBaseShaderNode(context, "skImageShader") {} + : JsiDomDeclarationNode(context, "skImageShader", + DeclarationType::Shader) {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto image = _imageProps->getImage(); - auto rect = _imageProps->getRect(); - auto lm = - _transformProp->isSet() ? _transformProp->getDerivedValue() : nullptr; - - if (rect != nullptr && lm != nullptr) { - auto rc = _imageProps->getDerivedValue(); - auto m3 = _imageProps->rect2rect(rc->src, rc->dst); - if (_transformProp->isChanged()) { - // To modify the matrix we need to copy it since we're not allowed to - // modify values contained in properties - this would have caused the - // matrix to be translated and scaled more and more for each render - // even thought the matrix prop did not change. - _matrix.reset(); - _matrix.preConcat(m3); - if (_originProp->isSet()) { - auto tr = _originProp->getDerivedValue(); - _matrix.preTranslate(tr->x(), tr->y()); - _matrix.preConcat(*lm); - _matrix.preTranslate(-tr->x(), -tr->y()); - } else { - _matrix.preConcat(*lm); - } + void decorate(DeclarationContext *context) override { + + auto image = _imageProps->getImage(); + if (image == nullptr) { + return; + } + + auto rect = _imageProps->getRect(); + auto lm = + _transformProp->isSet() ? _transformProp->getDerivedValue() : nullptr; + + if (rect != nullptr && lm != nullptr) { + auto rc = _imageProps->getDerivedValue(); + auto m3 = _imageProps->rect2rect(rc->src, rc->dst); + if (_transformProp->isChanged() || _imageProps->isChanged()) { + // To modify the matrix we need to copy it since we're not allowed to + // modify values contained in properties - this would have caused the + // matrix to be translated and scaled more and more for each render + // even thought the matrix prop did not change. + _matrix.reset(); + _matrix.preConcat(m3); + if (_originProp->isSet()) { + auto tr = _originProp->getDerivedValue(); + _matrix.preTranslate(tr->x(), tr->y()); + _matrix.preConcat(*lm); + _matrix.preTranslate(-tr->x(), -tr->y()); + } else { + _matrix.preConcat(*lm); } } - - setShader( - context, - image->makeShader( - *_txProp->getDerivedValue(), *_tyProp->getDerivedValue(), - SkSamplingOptions(getFilterModeFromString( - _filterModeProp->value().getAsString()), - getMipmapModeFromString( - _mipmapModeProp->value().getAsString())), - &_matrix)); } + + context->getShaders()->push(image->makeShader( + *_txProp->getDerivedValue(), *_tyProp->getDerivedValue(), + SkSamplingOptions( + getFilterModeFromString(_filterModeProp->value().getAsString()), + getMipmapModeFromString(_mipmapModeProp->value().getAsString())), + &_matrix)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _txProp = container->defineProperty("tx"); _tyProp = container->defineProperty("ty"); _filterModeProp = container->defineProperty("fm"); @@ -183,7 +148,7 @@ class JsiImageShaderNode : public JsiBaseShaderNode, _transformProp->require(); // Add and require the image - container->defineProperty("image")->require(); + container->defineProperty("image"); } private: @@ -224,25 +189,23 @@ class JsiImageShaderNode : public JsiBaseShaderNode, PointProp *_originProp; }; -class JsiColorShaderNode : public JsiBaseShaderNode, +class JsiColorShaderNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiColorShaderNode(std::shared_ptr context) - : JsiBaseShaderNode(context, "skColorShader") {} + : JsiDomDeclarationNode(context, "skColorShader", + DeclarationType::Shader) {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - if (_colorProp->isSet()) { - setShader(context, SkShaders::Color(*_colorProp->getDerivedValue())); - } else { - setShader(context, nullptr); - } + void decorate(DeclarationContext *context) override { + if (_colorProp->isSet()) { + context->getShaders()->push( + SkShaders::Color(*_colorProp->getDerivedValue())); } } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _colorProp = container->defineProperty("color"); _colorProp->require(); } @@ -251,15 +214,14 @@ class JsiColorShaderNode : public JsiBaseShaderNode, ColorProp *_colorProp; }; -class JsiBasePerlinNoiseNode : public JsiBaseShaderNode { +class JsiBasePerlinNoiseNode : public JsiDomDeclarationNode { public: JsiBasePerlinNoiseNode(std::shared_ptr context, PropId type) - : JsiBaseShaderNode(context, type) {} + : JsiDomDeclarationNode(context, type, DeclarationType::Shader) {} -protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _freqXProp = container->defineProperty("freqX"); _freqYProp = container->defineProperty("freqY"); _octavesProp = container->defineProperty("octaves"); @@ -289,18 +251,15 @@ class JsiTurbulenceNode : public JsiBasePerlinNoiseNode, explicit JsiTurbulenceNode(std::shared_ptr context) : JsiBasePerlinNoiseNode(context, "skTurbulence") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - SkISize size = SkISize::Make(_tileWidthProp->value().getAsNumber(), - _tileHeightProp->value().getAsNumber()); - - setShader(context, SkPerlinNoiseShader::MakeTurbulence( - _freqXProp->value().getAsNumber(), - _freqYProp->value().getAsNumber(), - _octavesProp->value().getAsNumber(), - _seedProp->value().getAsNumber(), &size)); - } + void decorate(DeclarationContext *context) override { + + SkISize size = SkISize::Make(_tileWidthProp->value().getAsNumber(), + _tileHeightProp->value().getAsNumber()); + + context->getShaders()->push(SkPerlinNoiseShader::MakeTurbulence( + _freqXProp->value().getAsNumber(), _freqYProp->value().getAsNumber(), + _octavesProp->value().getAsNumber(), _seedProp->value().getAsNumber(), + &size)); } }; @@ -310,28 +269,41 @@ class JsiFractalNoiseNode : public JsiBasePerlinNoiseNode, explicit JsiFractalNoiseNode(std::shared_ptr context) : JsiBasePerlinNoiseNode(context, "skFractalNoise") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - SkISize size = SkISize::Make(_tileWidthProp->value().getAsNumber(), - _tileHeightProp->value().getAsNumber()); - - setShader(context, SkPerlinNoiseShader::MakeFractalNoise( - _freqXProp->value().getAsNumber(), - _freqYProp->value().getAsNumber(), - _octavesProp->value().getAsNumber(), - _seedProp->value().getAsNumber(), &size)); - } + void decorate(DeclarationContext *context) override { + + SkISize size = SkISize::Make(_tileWidthProp->value().getAsNumber(), + _tileHeightProp->value().getAsNumber()); + + context->getShaders()->push(SkPerlinNoiseShader::MakeFractalNoise( + _freqXProp->value().getAsNumber(), _freqYProp->value().getAsNumber(), + _octavesProp->value().getAsNumber(), _seedProp->value().getAsNumber(), + &size)); } }; -class JsiBaseGradientNode : public JsiBaseShaderNode { +class JsiBaseGradientNode : public JsiDomDeclarationNode { public: JsiBaseGradientNode(std::shared_ptr context, PropId type) - : JsiBaseShaderNode(context, type) {} + : JsiDomDeclarationNode(context, type, DeclarationType::Shader) {} + + void decorate(DeclarationContext *context) override { + + _colors = _colorsProp->getDerivedValue()->data(); + _colorCount = static_cast(_colorsProp->getDerivedValue()->size()); + _flags = _flagsProp->isSet() ? _flagsProp->value().getAsNumber() : 0; + _mode = + _modeProp->isSet() ? *_modeProp->getDerivedValue() : SkTileMode::kClamp; + _positions = _positionsProp->isSet() + ? _positionsProp->getDerivedValue()->data() + : nullptr; + _matrix = _transformsProps->isSet() + ? _transformsProps->getDerivedValue().get() + : nullptr; + } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _transformsProps = container->defineProperty(); _colorsProp = container->defineProperty("colors"); @@ -342,23 +314,6 @@ class JsiBaseGradientNode : public JsiBaseShaderNode { _colorsProp->require(); } -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - _colors = _colorsProp->getDerivedValue()->data(); - _colorCount = static_cast(_colorsProp->getDerivedValue()->size()); - _flags = _flagsProp->isSet() ? _flagsProp->value().getAsNumber() : 0; - _mode = _modeProp->isSet() ? *_modeProp->getDerivedValue() - : SkTileMode::kClamp; - _positions = _positionsProp->isSet() - ? _positionsProp->getDerivedValue()->data() - : nullptr; - _matrix = _transformsProps->isSet() - ? _transformsProps->getDerivedValue().get() - : nullptr; - } - } - const SkColor *_colors; double _flags; int _colorCount; @@ -380,19 +335,17 @@ class JsiLinearGradientNode : public JsiBaseGradientNode, explicit JsiLinearGradientNode(std::shared_ptr context) : JsiBaseGradientNode(context, "skLinearGradient") {} -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { JsiBaseGradientNode::decorate(context); - if (isChanged(context)) { - SkPoint pts[] = {*_startProp->getDerivedValue(), - *_endProp->getDerivedValue()}; - setShader(context, SkGradientShader::MakeLinear(pts, _colors, _positions, - _colorCount, _mode, - _flags, _matrix)); - } + SkPoint pts[] = {*_startProp->getDerivedValue(), + *_endProp->getDerivedValue()}; + auto shader = SkGradientShader::MakeLinear( + pts, _colors, _positions, _colorCount, _mode, _flags, _matrix); + context->getShaders()->push(shader); } +protected: void defineProperties(NodePropsContainer *container) override { JsiBaseGradientNode::defineProperties(container); _startProp = container->defineProperty("start"); @@ -413,19 +366,17 @@ class JsiRadialGradientNode : public JsiBaseGradientNode, explicit JsiRadialGradientNode(std::shared_ptr context) : JsiBaseGradientNode(context, "skRadialGradient") {} -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { JsiBaseGradientNode::decorate(context); - if (isChanged(context)) { - auto c = _centerProp->getDerivedValue(); - auto r = _radiusProp->value().getAsNumber(); - setShader(context, SkGradientShader::MakeRadial(*c, r, _colors, - _positions, _colorCount, - _mode, _flags, _matrix)); - } + auto c = _centerProp->getDerivedValue(); + auto r = _radiusProp->value().getAsNumber(); + auto shader = SkGradientShader::MakeRadial( + *c, r, _colors, _positions, _colorCount, _mode, _flags, _matrix); + context->getShaders()->push(shader); } +protected: void defineProperties(NodePropsContainer *container) override { JsiBaseGradientNode::defineProperties(container); _centerProp = container->defineProperty("c"); @@ -446,21 +397,19 @@ class JsiSweepGradientNode : public JsiBaseGradientNode, explicit JsiSweepGradientNode(std::shared_ptr context) : JsiBaseGradientNode(context, "skSweepGradient") {} -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { JsiBaseGradientNode::decorate(context); - if (isChanged(context)) { - auto start = _startProp->isSet() ? _startProp->value().getAsNumber() : 0; - auto end = _endProp->isSet() ? _endProp->value().getAsNumber() : 360; - auto c = _centerProp->getDerivedValue(); + auto start = _startProp->isSet() ? _startProp->value().getAsNumber() : 0; + auto end = _endProp->isSet() ? _endProp->value().getAsNumber() : 360; + auto c = _centerProp->getDerivedValue(); - setShader(context, SkGradientShader::MakeSweep( - c->x(), c->y(), _colors, _positions, _colorCount, - _mode, start, end, _flags, _matrix)); - } + context->getShaders()->push(SkGradientShader::MakeSweep( + c->x(), c->y(), _colors, _positions, _colorCount, _mode, start, end, + _flags, _matrix)); } +protected: void defineProperties(NodePropsContainer *container) override { JsiBaseGradientNode::defineProperties(container); _startProp = container->defineProperty("start"); @@ -482,22 +431,20 @@ class JsiTwoPointConicalGradientNode std::shared_ptr context) : JsiBaseGradientNode(context, "skTwoPointConicalGradient") {} -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { JsiBaseGradientNode::decorate(context); - if (isChanged(context)) { - auto start = _startProp->getDerivedValue(); - auto end = _endProp->getDerivedValue(); - auto startR = _startRProp->value().getAsNumber(); - auto endR = _endRProp->value().getAsNumber(); + auto start = _startProp->getDerivedValue(); + auto end = _endProp->getDerivedValue(); + auto startR = _startRProp->value().getAsNumber(); + auto endR = _endRProp->value().getAsNumber(); - setShader(context, SkGradientShader::MakeTwoPointConical( - *start, startR, *end, endR, _colors, _positions, - _colorCount, _mode, _flags, _matrix)); - } + context->getShaders()->push(SkGradientShader::MakeTwoPointConical( + *start, startR, *end, endR, _colors, _positions, _colorCount, _mode, + _flags, _matrix)); } +protected: void defineProperties(NodePropsContainer *container) override { JsiBaseGradientNode::defineProperties(container); _startProp = container->defineProperty("start"); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextNode.h index 6c78e83941d56..71a26b8179400 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextNode.h @@ -21,9 +21,11 @@ class JsiTextNode : public JsiDomDrawingNode, auto y = _yProp->value().getAsNumber(); auto font = _fontProp->getDerivedValue(); - context->getCanvas()->drawSimpleText(text, strlen(text), - SkTextEncoding::kUTF8, x, y, *font, - *context->getPaint()); + if (font != nullptr) { + context->getCanvas()->drawSimpleText(text, strlen(text), + SkTextEncoding::kUTF8, x, y, *font, + *context->getPaint()); + } } void defineProperties(NodePropsContainer *container) override { @@ -34,7 +36,6 @@ class JsiTextNode : public JsiDomDrawingNode, _xProp = container->defineProperty("x"); _yProp = container->defineProperty("y"); - _fontProp->require(); _textProp->require(); _xProp->require(); _yProp->require(); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextPathNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextPathNode.h index 90d11b960de8a..ec08389fbb934 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextPathNode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextPathNode.h @@ -16,7 +16,9 @@ class JsiTextPathNode : public JsiDomDrawingNode, protected: void draw(DrawingContext *context) override { auto blob = _textBlobProp->getDerivedValue(); - context->getCanvas()->drawTextBlob(blob, 0, 0, *context->getPaint()); + if (blob != nullptr) { + context->getCanvas()->drawTextBlob(blob, 0, 0, *context->getPaint()); + } } void defineProperties(NodePropsContainer *container) override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BezierProps.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BezierProps.h index c230905bcf5ea..4829ebe489917 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BezierProps.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BezierProps.h @@ -12,8 +12,10 @@ namespace RNSkia { class BezierProp : public DerivedProp> { public: - explicit BezierProp(PropId name) : DerivedProp>() { - _bezierProp = addProperty(std::make_shared(name)); + explicit BezierProp(PropId name, + const std::function &onChange) + : DerivedProp>(onChange) { + _bezierProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BlendModeProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BlendModeProp.h index 654d8eeea713d..6b95b5e72ce7b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BlendModeProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BlendModeProp.h @@ -10,7 +10,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkBlendMode.h" #pragma clang diagnostic pop @@ -18,8 +18,10 @@ namespace RNSkia { class BlendModeProp : public DerivedProp { public: - explicit BlendModeProp(PropId name) : DerivedProp() { - _blendMode = addProperty(std::make_shared(name)); + explicit BlendModeProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _blendMode = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h index 6c438604d6f0b..fa43c8613df08 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h @@ -5,20 +5,20 @@ #include #include +#include "SkBlurTypes.h" + namespace RNSkia { class BoxShadowProps : public DerivedProp { public: - BoxShadowProps() : DerivedProp() { - _dxProp = addProperty(std::make_shared(JsiPropId::get("dx"))); - _dyProp = addProperty(std::make_shared(JsiPropId::get("dy"))); - _spreadProp = - addProperty(std::make_shared(JsiPropId::get("spread"))); - _blurProp = addProperty(std::make_shared(JsiPropId::get("blur"))); - _colorProp = - addProperty(std::make_shared(JsiPropId::get("color"))); - _innerProp = - addProperty(std::make_shared(JsiPropId::get("inner"))); + explicit BoxShadowProps(const std::function &onChange) + : DerivedProp(onChange) { + _dxProp = defineProperty("dx"); + _dyProp = defineProperty("dy"); + _spreadProp = defineProperty("spread"); + _blurProp = defineProperty("blur"); + _colorProp = defineProperty("color"); + _innerProp = defineProperty("inner"); _blurProp->require(); } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/CircleProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/CircleProp.h index cc40267c9ec07..bdbdf59607881 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/CircleProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/CircleProp.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPoint.h" #pragma clang diagnostic pop @@ -20,10 +20,11 @@ static PropId PropNameC = JsiPropId::get("c"); class CircleProp : public DerivedProp { public: - CircleProp() : DerivedProp() { - _c = addProperty(std::make_shared(PropNameC)); - _cx = addProperty(std::make_shared(PropNameCx)); - _cy = addProperty(std::make_shared(PropNameCy)); + explicit CircleProp(const std::function &onChange) + : DerivedProp(onChange) { + _c = defineProperty("c"); + _cx = defineProperty("cx"); + _cy = defineProperty("cy"); } void updateDerivedValue() override { @@ -33,7 +34,7 @@ class CircleProp : public DerivedProp { setDerivedValue(SkPoint::Make(_cx->value().getAsNumber(), _cy->value().getAsNumber())); } else if (_c->isSet()) { - setDerivedValue(_c->getDerivedValue()); + setDerivedValue(_c->getUnsafeDerivedValue()); } else { setDerivedValue(SkPoint::Make(0.0, 0.0)); } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ClipProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ClipProp.h index cab59cdbdb469..d7e8806102942 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ClipProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ClipProp.h @@ -11,7 +11,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPath.h" #pragma clang diagnostic pop @@ -19,44 +19,39 @@ namespace RNSkia { class ClipProp : public BaseDerivedProp { public: - explicit ClipProp(PropId name) : BaseDerivedProp() { - _pathProp = addProperty(std::make_shared(name)); - _rectProp = addProperty(std::make_shared(name)); - _rrectProp = addProperty(std::make_shared(name)); + explicit ClipProp(PropId name, + const std::function &onChange) + : BaseDerivedProp(onChange) { + _clipProp = defineProperty(name); } void updateDerivedValue() override { - if (_pathProp->isSet()) { - _rect = nullptr; - _rrect = nullptr; - _path = _pathProp->getDerivedValue(); - } else if (_rrectProp->isSet()) { - _rect = nullptr; - _rrect = _rrectProp->getDerivedValue(); - _path = nullptr; - } else if (_rectProp->isSet()) { - _rect = _rectProp->getDerivedValue(); + if (_clipProp->isSet()) { + auto value = _clipProp->value(); + _rect = RectProp::processRect(value); _rrect = nullptr; _path = nullptr; + if (!_rect) { + _path = PathProp::processPath(value); + if (!_path) { + _rrect = RRectProp::processRRect(value); + } + } } } - bool isSet() override { - return _pathProp->isSet() || _rectProp->isSet() || _rrectProp->isSet(); - } + bool isSet() override { return _clipProp->isSet(); } const SkPath *getPath() { return _path.get(); } const SkRect *getRect() { return _rect.get(); } const SkRRect *getRRect() { return _rrect.get(); } private: - PathProp *_pathProp; - RectProp *_rectProp; - RRectProp *_rrectProp; + NodeProp *_clipProp; std::shared_ptr _path; std::shared_ptr _rect; std::shared_ptr _rrect; }; -} // namespace RNSkia +} // namespace RNSkia \ No newline at end of file diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ColorProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ColorProp.h index 50f45b9530823..4a391fad65426 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ColorProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ColorProp.h @@ -16,8 +16,10 @@ static PropId PropName3 = JsiPropId::get("3"); class ColorProp : public DerivedProp { public: - explicit ColorProp(PropId name) : DerivedProp() { - _colorProp = addProperty(std::make_shared(name)); + explicit ColorProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _colorProp = defineProperty(name); } void updateDerivedValue() override { @@ -40,6 +42,13 @@ class ColorProp : public DerivedProp { return SkColorSetARGB(a.getAsNumber() * 255.0f, r.getAsNumber() * 255.0f, g.getAsNumber() * 255.0f, b.getAsNumber() * 255.0f); + } else if (color.getType() == PropType::Array) { + auto r = color.getAsArray().at(0); + auto g = color.getAsArray().at(1); + auto b = color.getAsArray().at(2); + auto a = color.getAsArray().at(3); + return SkColorSetARGB(a.getAsNumber() * 255.0f, r.getAsNumber() * 255.0f, + g.getAsNumber() * 255.0f, b.getAsNumber() * 255.0f); } else if (color.getType() == PropType::Number) { return static_cast(color.getAsNumber()); } else { @@ -59,8 +68,10 @@ class ColorProp : public DerivedProp { class ColorsProp : public DerivedProp> { public: - explicit ColorsProp(PropId name) : DerivedProp>() { - _colorsProp = addProperty(std::make_shared(name)); + explicit ColorsProp(PropId name, + const std::function &onChange) + : DerivedProp>(onChange) { + _colorsProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/DrawingProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/DrawingProp.h index 384269e21e4bc..bfd6e756827e2 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/DrawingProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/DrawingProp.h @@ -13,9 +13,11 @@ using NotifyNeedRenderCallback = class DrawingProp : public DerivedSkProp { public: - DrawingProp(PropId name, NotifyNeedRenderCallback notifyPictureNeeded) - : _notifyPictureNeeded(notifyPictureNeeded), DerivedSkProp() { - _drawingProp = addProperty(std::make_shared(name)); + DrawingProp(PropId name, NotifyNeedRenderCallback notifyPictureNeeded, + const std::function &onChange) + : _notifyPictureNeeded(notifyPictureNeeded), DerivedSkProp( + onChange) { + _drawingProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/FontProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/FontProp.h index 99ea73b82b30a..72af25df73eb7 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/FontProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/FontProp.h @@ -10,22 +10,29 @@ namespace RNSkia { class FontProp : public DerivedProp { public: - explicit FontProp(PropId name) : DerivedProp() { - _fontProp = addProperty(std::make_shared(name)); + explicit FontProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _fontProp = defineProperty(name); } void updateDerivedValue() override { - if (!_fontProp->isSet() || - _fontProp->value().getType() != PropType::HostObject) { - throw std::runtime_error("Expected SkFont object for the Font property."); + if (_fontProp->isSet()) { + if (_fontProp->value().getType() == PropType::HostObject) { + auto ptr = _fontProp->value().getAs(); + if (ptr == nullptr) { + throw std::runtime_error( + "Expected SkFont object for the Font property."); + } + setDerivedValue(ptr->getObject()); + + } else { + throw std::runtime_error( + "Expected SkFont object or null/undefined for the Font property."); + } + } else { + setDerivedValue(nullptr); } - - auto ptr = _fontProp->value().getAs(); - if (ptr == nullptr) { - throw std::runtime_error("Expected SkFont object for the Font property."); - } - - setDerivedValue(ptr->getObject()); } private: diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/GlyphsProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/GlyphsProp.h index d35f561053589..414f4f6ff683c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/GlyphsProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/GlyphsProp.h @@ -19,8 +19,10 @@ struct GlyphInfo { class GlyphsProp : public DerivedProp { public: - explicit GlyphsProp(PropId name) : DerivedProp() { - _glyphsProp = addProperty(std::make_shared(name)); + explicit GlyphsProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _glyphsProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ImageProps.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ImageProps.h index a1337347f953d..bc2cfdf6d1fbb 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ImageProps.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ImageProps.h @@ -25,25 +25,39 @@ static PropId PropNameFit = JsiPropId::get("fit"); class ImageProp : public DerivedSkProp { public: - explicit ImageProp(PropId name) : DerivedSkProp() { - _imageProp = addProperty(std::make_shared(name)); + explicit ImageProp(PropId name, + const std::function &onChange) + : DerivedSkProp(onChange) { + _imageProp = defineProperty(name); } void updateDerivedValue() override { - if (!_imageProp->isSet() || - _imageProp->value().getType() != PropType::HostObject) { - throw std::runtime_error("Expected SkImage object for the " + - std::string(getName()) + " property."); - } - - auto ptr = std::dynamic_pointer_cast( - _imageProp->value().getAsHostObject()); - if (ptr == nullptr) { - throw std::runtime_error("Expected SkImage object for the " + - std::string(getName()) + " property."); + if (_imageProp->isSet()) { + // Check for host object + if (_imageProp->value().getType() == PropType::HostObject) { + // This should be an SkImage wrapper: + auto ptr = std::dynamic_pointer_cast( + _imageProp->value().getAsHostObject()); + if (ptr == nullptr) { + // If not - throw an exception + throw std::runtime_error("Expected SkImage object for the " + + std::string(getName()) + + " property. Got a " + + _imageProp->value().getTypeAsString( + _imageProp->value().getType()) + + "."); + } + setDerivedValue(ptr->getObject()); + } else { + // Should be a host object if set + throw std::runtime_error( + "Expected SkImage object or null/undefined for the " + + std::string(getName()) + " property."); + } + } else { + // Set to null + setDerivedValue(nullptr); } - - setDerivedValue(ptr->getObject()); } private: @@ -52,18 +66,20 @@ class ImageProp : public DerivedSkProp { class ImageProps : public DerivedProp { public: - ImageProps() : DerivedProp() { - _fitProp = addProperty(std::make_shared(PropNameFit)); - _imageProp = addProperty(std::make_shared(PropNameImage)); - _rectProp = addProperty(std::make_shared(PropNameRect)); + explicit ImageProps(const std::function &onChange) + : DerivedProp(onChange) { + _fitProp = defineProperty(PropNameFit); + _imageProp = defineProperty(PropNameImage); + _rectProp = defineProperty(PropNameRect); } void updateDerivedValue() override { - if (!_imageProp->isSet()) { - throw std::runtime_error("Image property is not set on the Image node."); + auto image = _imageProp->getDerivedValue(); + if (image == nullptr) { + setDerivedValue(nullptr); + return; } - auto image = _imageProp->getDerivedValue(); auto imageRect = SkRect::MakeXYWH(0, 0, image->width(), image->height()); auto rect = _rectProp->getDerivedValue() ? *_rectProp->getDerivedValue() @@ -74,6 +90,7 @@ class ImageProps : public DerivedProp { } sk_sp getImage() { return _imageProp->getDerivedValue(); } + std::shared_ptr getRect() { return _rectProp->getDerivedValue(); } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/LayerProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/LayerProp.h index 80779a124b039..ad013082d380a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/LayerProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/LayerProp.h @@ -10,9 +10,11 @@ namespace RNSkia { class LayerProp : public DerivedProp { public: - explicit LayerProp(PropId name) : DerivedProp() { - _layerPaintProp = addProperty(std::make_shared(name)); - _layerBoolProp = addProperty(std::make_shared(name)); + explicit LayerProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _layerPaintProp = defineProperty(name); + _layerBoolProp = defineProperty(name); } /** @@ -31,7 +33,7 @@ class LayerProp : public DerivedProp { if (_layerPaintProp->isSet()) { // We have a paint object for the layer property - setDerivedValue(_layerPaintProp->getDerivedValue()); + setDerivedValue(_layerPaintProp->getUnsafeDerivedValue()); _isBool = false; } else { _isBool = false; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/MatrixProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/MatrixProp.h index 527265d5d5f3e..f3d8b59d9f809 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/MatrixProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/MatrixProp.h @@ -11,8 +11,10 @@ static PropId PropNameMatrix = JsiPropId::get("matrix"); class MatrixProp : public DerivedProp { public: - explicit MatrixProp(PropId name) : DerivedProp() { - _matrixProp = addProperty(std::make_shared(name)); + explicit MatrixProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _matrixProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/NumbersProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/NumbersProp.h index 80c04f5a16862..90f2863d0bc70 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/NumbersProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/NumbersProp.h @@ -11,8 +11,10 @@ namespace RNSkia { class NumbersProp : public DerivedProp> { public: - explicit NumbersProp(PropId name) : DerivedProp>() { - _positionProp = addProperty(std::make_shared(name)); + explicit NumbersProp(PropId name, + const std::function &onChange) + : DerivedProp>(onChange) { + _positionProp = defineProperty(name); } void updateDerivedValue() override { @@ -36,8 +38,10 @@ class NumbersProp : public DerivedProp> { class Numbers16Prop : public DerivedProp> { public: - explicit Numbers16Prop(PropId name) : DerivedProp>() { - _prop = addProperty(std::make_shared(name)); + explicit Numbers16Prop(PropId name, + const std::function &onChange) + : DerivedProp>(onChange) { + _prop = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PaintProps.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PaintProps.h index ec318a94076af..f131b6a7149f7 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PaintProps.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PaintProps.h @@ -13,7 +13,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPaint.h" #pragma clang diagnostic pop @@ -21,11 +21,14 @@ namespace RNSkia { class PaintProp : public DerivedProp { public: - explicit PaintProp(PropId name) : DerivedProp() { - _paintProp = addProperty(std::make_shared(name)); + explicit PaintProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _paintProp = defineProperty(name); } - PaintProp() : PaintProp(JsiPropId::get("paint")) {} + explicit PaintProp(const std::function &onChange) + : PaintProp(JsiPropId::get("paint"), onChange) {} void updateDerivedValue() override { if (_paintProp->isSet()) { @@ -50,108 +53,68 @@ class PaintProp : public DerivedProp { NodeProp *_paintProp; }; -class PaintProps : public BaseDerivedProp { +class PaintDrawingContextProp : public DerivedProp { public: - PaintProps() : BaseDerivedProp() { - _color = addProperty(std::make_shared(JsiPropId::get("color"))); - _style = addProperty(std::make_shared(JsiPropId::get("style"))); - _strokeWidth = - addProperty(std::make_shared(JsiPropId::get("strokeWidth"))); - _blendMode = addProperty( - std::make_shared(JsiPropId::get("blendMode"))); - _strokeJoin = addProperty( - std::make_shared(JsiPropId::get("strokeJoin"))); - _strokeCap = addProperty( - std::make_shared(JsiPropId::get("strokeCap"))); - _strokeMiter = - addProperty(std::make_shared(JsiPropId::get("strokeMiter"))); - _antiAlias = - addProperty(std::make_shared(JsiPropId::get("antiAlias"))); - _opacity = - addProperty(std::make_shared(JsiPropId::get("opacity"))); + explicit PaintDrawingContextProp( + PropId name, const std::function &onChange) + : DerivedProp(onChange) { + _paintProp = defineProperty(name); } - void decorate(DrawingContext *context) { - // Now we can start updating the context - - // Opacity - if (_opacity->isChanged() || context->isChanged()) { - auto parent = context->getParent(); - auto paint = context->getMutablePaint(); - if (_opacity->isSet()) { - auto currentOpacity = _opacity->value().getAsNumber(); - auto parent = context->getParent(); - if (parent != nullptr) { - currentOpacity *= parent->getPaint()->getAlphaf(); - } - paint->setAlphaf(currentOpacity); - } else { - if (parent != nullptr) { - paint->setAlphaf(parent->getPaint()->getAlphaf()); + explicit PaintDrawingContextProp( + const std::function &onChange) + : PaintDrawingContextProp(JsiPropId::get("paint"), onChange) {} + + void updateDerivedValue() override { + if (_paintProp->isSet()) { + if (_paintProp->value().getType() == PropType::HostObject) { + // Read paint property as Host Object - JsiSkPaint + auto ptr = _paintProp->value().getAs(); + if (ptr != nullptr) { + setDerivedValue(std::make_shared(ptr->getObject())); } else { - paint->setAlphaf(1.0); + throw std::runtime_error("Expected SkPaint object, got unknown " + "object when reading paint property."); } + } else { + setDerivedValue(nullptr); } + } else { + setDerivedValue(nullptr); } + } - // COLOR - if (_color->isSet() && (_color->isChanged() || context->isChanged())) { - auto paint = context->getMutablePaint(); - auto opacity = paint->getAlphaf(); - paint->setShader(nullptr); - paint->setColor(*_color->getDerivedValue()); - paint->setAlphaf(opacity * paint->getColor4f().fA); - } +private: + NodeProp *_paintProp; +}; - // Style - if (_style->isSet() && (_style->isChanged() || context->isChanged())) { - auto styleValue = _style->value().getAsString(); - if (styleValue == "stroke") { - context->getMutablePaint()->setStyle(SkPaint::Style::kStroke_Style); - } else if (styleValue == "fill") { - context->getMutablePaint()->setStyle(SkPaint::Style::kFill_Style); - } else { - throw std::runtime_error( - styleValue + " is not a valud value for the style property."); - } - } - // Stroke Width - if (_strokeWidth->isSet() && - (_strokeWidth->isChanged() || context->isChanged())) { - context->getMutablePaint()->setStrokeWidth( - _strokeWidth->value().getAsNumber()); - } - // Blend mode - if (_blendMode->isSet() && - (_blendMode->isChanged() || context->isChanged())) { - context->getMutablePaint()->setBlendMode(*_blendMode->getDerivedValue()); - } - // Stroke Join - if (_strokeJoin->isSet() && - (_strokeJoin->isChanged() || context->isChanged())) { - context->getMutablePaint()->setStrokeJoin( - *_strokeJoin->getDerivedValue()); - } - // Stroke Cap - if (_strokeCap->isSet() && - (_strokeCap->isChanged() || context->isChanged())) { - context->getMutablePaint()->setStrokeCap(*_strokeCap->getDerivedValue()); - } - // Stroke Miter - if (_strokeMiter->isSet() && - (_strokeMiter->isChanged() || context->isChanged())) { - context->getMutablePaint()->setStrokeMiter( - _strokeMiter->value().getAsNumber()); - } - // AntiAlias - if (_antiAlias->isSet() && - (_antiAlias->isChanged() || context->isChanged())) { - context->getMutablePaint()->setAntiAlias(_antiAlias->value().getAsBool()); - } +class PaintProps : public BaseDerivedProp { +public: + explicit PaintProps(const std::function &onChange) + : BaseDerivedProp(onChange) { + _color = defineProperty("color"); + _style = defineProperty("style"); + _strokeWidth = defineProperty("strokeWidth"); + _blendMode = defineProperty("blendMode"); + _strokeJoin = defineProperty("strokeJoin"); + _strokeCap = defineProperty("strokeCap"); + _strokeMiter = defineProperty("strokeMiter"); + _antiAlias = defineProperty("antiAlias"); + _opacity = defineProperty("opacity"); } void updateDerivedValue() override {} + ColorProp *getColor() { return _color; } + NodeProp *getStyle() { return _style; } + NodeProp *getStrokeWidth() { return _strokeWidth; } + BlendModeProp *getBlendMode() { return _blendMode; } + StrokeJoinProp *getStrokeJoin() { return _strokeJoin; } + StrokeCapProp *getStrokeCap() { return _strokeCap; } + NodeProp *getStrokeMiter() { return _strokeMiter; } + NodeProp *getAntiAlias() { return _antiAlias; } + NodeProp *getOpacity() { return _opacity; } + private: ColorProp *_color; NodeProp *_style; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PathProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PathProp.h index d711e16ee0772..b4b0860fe39cd 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PathProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PathProp.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPath.h" #pragma clang diagnostic pop @@ -16,36 +16,40 @@ namespace RNSkia { class PathProp : public DerivedProp { public: - explicit PathProp(PropId name) : DerivedProp() { - _pathProp = addProperty(std::make_shared(name)); + explicit PathProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _pathProp = defineProperty(name); } - void updateDerivedValue() override { - if (!_pathProp->isSet()) { - setDerivedValue(nullptr); - return; - } - - if (_pathProp->value().getType() == PropType::HostObject) { + static std::shared_ptr processPath(const JsiValue &value) { + if (value.getType() == PropType::HostObject) { // Try reading as Path - auto ptr = std::dynamic_pointer_cast( - _pathProp->value().getAsHostObject()); + auto ptr = std::dynamic_pointer_cast(value.getAsHostObject()); if (ptr != nullptr) { - setDerivedValue(ptr->getObject()); + return ptr->getObject(); } - } else if (_pathProp->value().getType() == PropType::String) { + } else if (value.getType() == PropType::String) { // Read as string - auto pathString = _pathProp->value().getAsString(); + auto pathString = value.getAsString(); SkPath result; if (SkParsePath::FromSVGString(pathString.c_str(), &result)) { - setDerivedValue(std::make_shared(result)); + return std::make_shared(result); } else { throw std::runtime_error("Could not parse path from string."); } - } else { + } + return nullptr; + } + + void updateDerivedValue() override { + if (!_pathProp->isSet()) { setDerivedValue(nullptr); + return; } + auto value = _pathProp->value(); + setDerivedValue(PathProp::processPath(value)); } private: diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PictureProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PictureProp.h index c2da4f0ae8c26..e63f8f31c235f 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PictureProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PictureProp.h @@ -11,8 +11,10 @@ namespace RNSkia { class PictureProp : public DerivedSkProp { public: - explicit PictureProp(PropId name) : DerivedSkProp() { - _pictureProp = addProperty(std::make_shared(name)); + explicit PictureProp(PropId name, + const std::function &onChange) + : DerivedSkProp(onChange) { + _pictureProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointProp.h index 70a6cafc72d67..c6f3f5ba2a145 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointProp.h @@ -9,7 +9,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPoint.h" #pragma clang diagnostic pop @@ -20,14 +20,16 @@ static PropId PropNameY = JsiPropId::get("y"); class PointProp : public DerivedProp { public: - explicit PointProp(PropId name) : DerivedProp() { - _pointProp = addProperty(std::make_shared(name)); + explicit PointProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _pointProp = defineProperty(name); } void updateDerivedValue() override { if (_pointProp->isSet()) { // Check for JsiSkRect and JsiSkPoint - setDerivedValue(std::move(processValue(_pointProp->value()))); + setDerivedValue(processValue(_pointProp->value())); } else { setDerivedValue(nullptr); } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointsProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointsProp.h index d80fb5256a0a5..c45b938fc1fb2 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointsProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointsProp.h @@ -11,7 +11,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPoint.h" #pragma clang diagnostic pop @@ -19,8 +19,10 @@ namespace RNSkia { class PointModeProp : public DerivedProp { public: - explicit PointModeProp(PropId name) : DerivedProp() { - _pointModeProp = addProperty(std::make_shared(name)); + explicit PointModeProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _pointModeProp = defineProperty(name); } void updateDerivedValue() override { @@ -51,8 +53,10 @@ class PointModeProp : public DerivedProp { class PointsProp : public DerivedProp> { public: - explicit PointsProp(PropId name) : DerivedProp>() { - _pointsProp = addProperty(std::make_shared(name)); + explicit PointsProp(PropId name, + const std::function &onChange) + : DerivedProp>(onChange) { + _pointsProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RRectProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RRectProp.h index f221d0e5b5244..e38fbcd9bfaf4 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RRectProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RRectProp.h @@ -9,8 +9,8 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include -#include +#include "SkRRect.h" +#include "SkRect.h" #pragma clang diagnostic pop @@ -27,39 +27,39 @@ static PropId PropNameR = JsiPropId::get("r"); */ class RRectProp : public DerivedProp { public: - explicit RRectProp(PropId name) : DerivedProp() { - _prop = addProperty(std::make_shared(name)); + explicit RRectProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _prop = defineProperty(name); } - void updateDerivedValue() override { - if (_prop->isSet()) { - // Check for JsiSkRRect - if (_prop->value().getType() == PropType::HostObject) { - // Try reading as rect - auto rectPtr = std::dynamic_pointer_cast( - _prop->value().getAsHostObject()); - if (rectPtr != nullptr) { - auto rrect = rectPtr->getObject(); - setDerivedValue(SkRRect::MakeRectXY( - SkRect::MakeXYWH(rrect->rect().x(), rrect->rect().y(), - rrect->rect().width(), rrect->rect().height()), - rrect->getSimpleRadii().x(), rrect->getSimpleRadii().y())); - } - } else { - if (_prop->isSet() && _prop->value().getType() == PropType::Object) { - auto p = _prop->value(); - if (p.hasValue(PropNameX) && p.hasValue(PropNameY) && - p.hasValue(PropNameWidth) && p.hasValue(PropNameHeight) && - p.hasValue(PropNameRx) && p.hasValue(PropNameRy)) { - auto x = _prop->value().getValue(PropNameX); - auto y = _prop->value().getValue(PropNameY); - auto width = _prop->value().getValue(PropNameWidth); - auto height = _prop->value().getValue(PropNameHeight); - auto rx = _prop->value().getValue(PropNameRx); - auto ry = _prop->value().getValue(PropNameRy); + static std::shared_ptr processRRect(const JsiValue &value) { + if (value.getType() == PropType::HostObject) { + // Try reading as rect + auto rectPtr = + std::dynamic_pointer_cast(value.getAsHostObject()); + if (rectPtr != nullptr) { + auto rrect = rectPtr->getObject(); + return std::make_shared( + SkRRect::MakeRectXY(rrect->rect(), rrect->getSimpleRadii().x(), + rrect->getSimpleRadii().y())); + } + } else { + if (value.getType() == PropType::Object) { + if (value.hasValue(PropNameRect) && value.hasValue(PropNameRx) && + value.hasValue(PropNameRy)) { + auto rect = value.getValue(PropNameRect); + if (rect.hasValue(PropNameX) && rect.hasValue(PropNameY) && + rect.hasValue(PropNameWidth) && rect.hasValue(PropNameHeight)) { + auto x = rect.getValue(PropNameX); + auto y = rect.getValue(PropNameY); + auto width = rect.getValue(PropNameWidth); + auto height = rect.getValue(PropNameHeight); + auto rx = value.getValue(PropNameRx); + auto ry = value.getValue(PropNameRy); // Update cache from js object value - setDerivedValue(SkRRect::MakeRectXY( + return std::make_shared(SkRRect::MakeRectXY( SkRect::MakeXYWH(x.getAsNumber(), y.getAsNumber(), width.getAsNumber(), height.getAsNumber()), rx.getAsNumber(), ry.getAsNumber())); @@ -67,6 +67,14 @@ class RRectProp : public DerivedProp { } } } + return nullptr; + } + + void updateDerivedValue() override { + if (_prop->isSet()) { + auto value = _prop->value(); + setDerivedValue(RRectProp::processRRect(value)); + } } private: @@ -78,12 +86,14 @@ class RRectProp : public DerivedProp { */ class RRectPropFromProps : public DerivedProp { public: - RRectPropFromProps() : DerivedProp() { - _x = addProperty(std::make_shared(PropNameX)); - _y = addProperty(std::make_shared(PropNameY)); - _width = addProperty(std::make_shared(PropNameWidth)); - _height = addProperty(std::make_shared(PropNameHeight)); - _r = addProperty(std::make_shared(PropNameR)); + explicit RRectPropFromProps( + const std::function &onChange) + : DerivedProp(onChange) { + _x = defineProperty(PropNameX); + _y = defineProperty(PropNameY); + _width = defineProperty(PropNameWidth); + _height = defineProperty(PropNameHeight); + _r = defineProperty(PropNameR); } void updateDerivedValue() override { @@ -111,17 +121,18 @@ class RRectPropFromProps : public DerivedProp { */ class RRectProps : public DerivedProp { public: - explicit RRectProps(PropId name) : DerivedProp() { - _rectProp = addProperty(std::make_shared(name)); - _rectPropFromProps = - addProperty(std::make_shared()); + explicit RRectProps(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _rectProp = defineProperty(name); + _rectPropFromProps = defineProperty(); } void updateDerivedValue() override { if (_rectProp->isSet()) { - setDerivedValue(_rectProp->getDerivedValue()); + setDerivedValue(_rectProp->getUnsafeDerivedValue()); } else if (_rectPropFromProps->isSet()) { - setDerivedValue(_rectPropFromProps->getDerivedValue()); + setDerivedValue(_rectPropFromProps->getUnsafeDerivedValue()); } else { setDerivedValue(nullptr); } @@ -138,45 +149,19 @@ class RRectProps : public DerivedProp { */ class BoxProps : public DerivedProp { public: - explicit BoxProps(PropId name) : DerivedProp() { - _boxProp = addProperty(std::make_shared(name)); + explicit BoxProps(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _boxProp = defineProperty(name); } void updateDerivedValue() override { - if (_boxProp->value().getType() == PropType::HostObject) { - auto rectPtr = std::dynamic_pointer_cast( - _boxProp->value().getAsHostObject()); - auto rrectPtr = std::dynamic_pointer_cast( - _boxProp->value().getAsHostObject()); - // 1. box is SkRect - if (rectPtr != nullptr) { - auto rect = rectPtr->getObject(); - setDerivedValue(SkRRect::MakeRect(*rect)); - // 2. box is SkRRect - } else if (rrectPtr != nullptr) { - setDerivedValue(rrectPtr->getObject()); - } - } else if (_boxProp->value().getType() == PropType::Object) { - if (_boxProp->value().hasValue(PropNameRect)) { - // 3. box is { rect: { x, y, width, height }, rx, ry } - auto rectProp = _boxProp->value().getValue(PropNameRect); - auto x = rectProp.getValue(PropNameX).getAsNumber(); - auto y = rectProp.getValue(PropNameY).getAsNumber(); - auto width = rectProp.getValue(PropNameWidth).getAsNumber(); - auto height = rectProp.getValue(PropNameHeight).getAsNumber(); - auto rx = _boxProp->value().getValue(PropNameRx).getAsNumber(); - auto ry = _boxProp->value().getValue(PropNameRy).getAsNumber(); - setDerivedValue( - SkRRect::MakeRectXY(SkRect::MakeXYWH(x, y, width, height), rx, ry)); - } else { - // 4. box is { x, y, width, height } - auto x = _boxProp->value().getValue(PropNameX).getAsNumber(); - auto y = _boxProp->value().getValue(PropNameY).getAsNumber(); - auto width = _boxProp->value().getValue(PropNameWidth).getAsNumber(); - auto height = _boxProp->value().getValue(PropNameHeight).getAsNumber(); - setDerivedValue( - SkRRect::MakeRect(SkRect::MakeXYWH(x, y, width, height))); - } + auto value = _boxProp->value(); + auto rect = RectProp::processRect(value); + if (rect) { + setDerivedValue(SkRRect::MakeRect(*rect)); + } else { + setDerivedValue(RRectProp::processRRect(value)); } } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RadiusProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RadiusProp.h index 3639fc7bbaaa5..dd858b148e59a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RadiusProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RadiusProp.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPoint.h" #pragma clang diagnostic pop @@ -16,8 +16,10 @@ namespace RNSkia { class RadiusProp : public DerivedProp { public: - explicit RadiusProp(PropId name) : DerivedProp() { - _radiusProp = addProperty(std::make_shared(name)); + explicit RadiusProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _radiusProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RectProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RectProp.h index c32e73d7fad1d..dc9247985ef56 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RectProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RectProp.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkRect.h" #pragma clang diagnostic pop @@ -25,37 +25,41 @@ static PropId PropNameHeight = JsiPropId::get("height"); */ class RectProp : public DerivedProp { public: - explicit RectProp(PropId name) : DerivedProp() { - _prop = addProperty(std::make_shared(name)); + explicit RectProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _prop = defineProperty(name); + } + + static std::shared_ptr processRect(const JsiValue &value) { + if (value.getType() == PropType::HostObject) { + auto rectPtr = + std::dynamic_pointer_cast(value.getAsHostObject()); + if (rectPtr != nullptr) { + return std::make_shared(SkRect::MakeXYWH( + rectPtr->getObject()->x(), rectPtr->getObject()->y(), + rectPtr->getObject()->width(), rectPtr->getObject()->height())); + } + } else if (value.getType() == PropType::Object && + value.hasValue(PropNameX) && value.hasValue(PropNameY) && + value.hasValue(PropNameWidth) && + value.hasValue(PropNameHeight)) { + // Save props for fast access + auto x = value.getValue(PropNameX); + auto y = value.getValue(PropNameY); + auto width = value.getValue(PropNameWidth); + auto height = value.getValue(PropNameHeight); + // Update cache from js object value + return std::make_shared( + SkRect::MakeXYWH(x.getAsNumber(), y.getAsNumber(), + width.getAsNumber(), height.getAsNumber())); + } + return nullptr; } void updateDerivedValue() override { if (_prop->isSet()) { - // Check for JsiSkRect - if (_prop->value().getType() == PropType::HostObject) { - auto rectPtr = std::dynamic_pointer_cast( - _prop->value().getAsHostObject()); - if (rectPtr != nullptr) { - setDerivedValue(SkRect::MakeXYWH( - rectPtr->getObject()->x(), rectPtr->getObject()->y(), - rectPtr->getObject()->width(), rectPtr->getObject()->height())); - } - } else { - auto p = _prop->value(); - if (p.hasValue(PropNameX) && p.hasValue(PropNameY) && - p.hasValue(PropNameWidth) && p.hasValue(PropNameHeight)) { - // Save props for fast access - auto x = p.getValue(PropNameX); - auto y = p.getValue(PropNameY); - auto width = p.getValue(PropNameWidth); - auto height = p.getValue(PropNameHeight); - - // Update cache from js object value - setDerivedValue(SkRect::MakeXYWH(x.getAsNumber(), y.getAsNumber(), - width.getAsNumber(), - height.getAsNumber())); - } - } + setDerivedValue(RectProp::processRect(_prop->value())); } } @@ -68,11 +72,13 @@ class RectProp : public DerivedProp { */ class RectPropFromProps : public DerivedProp { public: - RectPropFromProps() : DerivedProp() { - _x = addProperty(std::make_shared(PropNameX)); - _y = addProperty(std::make_shared(PropNameY)); - _width = addProperty(std::make_shared(PropNameWidth)); - _height = addProperty(std::make_shared(PropNameHeight)); + explicit RectPropFromProps( + const std::function &onChange) + : DerivedProp(onChange) { + _x = defineProperty(PropNameX); + _y = defineProperty(PropNameY); + _width = defineProperty(PropNameWidth); + _height = defineProperty(PropNameHeight); } void updateDerivedValue() override { @@ -103,16 +109,18 @@ class RectPropFromProps : public DerivedProp { */ class RectProps : public DerivedProp { public: - explicit RectProps(PropId name) : DerivedProp() { - _rectProp = addProperty(std::make_shared(name)); - _rectPropFromProps = addProperty(std::make_shared()); + explicit RectProps(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _rectProp = defineProperty(name); + _rectPropFromProps = defineProperty(); } void updateDerivedValue() override { if (_rectProp->isSet()) { - setDerivedValue(_rectProp->getDerivedValue()); + setDerivedValue(_rectProp->getUnsafeDerivedValue()); } else if (_rectPropFromProps->isSet()) { - setDerivedValue(_rectPropFromProps->getDerivedValue()); + setDerivedValue(_rectPropFromProps->getUnsafeDerivedValue()); } else { setDerivedValue(nullptr); } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/StrokeProps.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/StrokeProps.h index 3868a707fda01..25bb3e76f7a88 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/StrokeProps.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/StrokeProps.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPaint.h" #pragma clang diagnostic pop @@ -16,8 +16,10 @@ namespace RNSkia { class StrokeCapProp : public DerivedProp { public: - explicit StrokeCapProp(PropId name) : DerivedProp() { - _strokeCap = addProperty(std::make_shared(name)); + explicit StrokeCapProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _strokeCap = defineProperty(name); } void updateDerivedValue() override { @@ -45,8 +47,10 @@ class StrokeCapProp : public DerivedProp { class StrokeJoinProp : public DerivedProp { public: - explicit StrokeJoinProp(PropId name) : DerivedProp() { - _strokeJoin = addProperty(std::make_shared(name)); + explicit StrokeJoinProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _strokeJoin = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/SvgProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/SvgProp.h index 3f928eb748d52..fedb1dde43f85 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/SvgProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/SvgProp.h @@ -10,24 +10,32 @@ namespace RNSkia { class SvgProp : public DerivedSkProp { public: - explicit SvgProp(PropId name) : DerivedSkProp() { - _imageSvgProp = addProperty(std::make_shared(name)); + explicit SvgProp(PropId name, + const std::function &onChange) + : DerivedSkProp(onChange) { + _imageSvgProp = defineProperty(name); } void updateDerivedValue() override { - if (_imageSvgProp->value().getType() != PropType::HostObject) { - throw std::runtime_error( - "Expected SkSvgDom object for the svg property."); + if (_imageSvgProp->isSet()) { + + if (_imageSvgProp->value().getType() == PropType::HostObject) { + + auto ptr = std::dynamic_pointer_cast( + _imageSvgProp->value().getAsHostObject()); + if (ptr == nullptr) { + throw std::runtime_error( + "Expected SkSvgDom object for the svg property."); + } + setDerivedValue(ptr->getObject()); + } else { + throw std::runtime_error( + "Expected SkSvgDom object or null/undefined for the svg property."); + } + + } else { + setDerivedValue(nullptr); } - - auto ptr = std::dynamic_pointer_cast( - _imageSvgProp->value().getAsHostObject()); - if (ptr == nullptr) { - throw std::runtime_error( - "Expected SkSvgDom object for the svg property."); - } - - setDerivedValue(ptr->getObject()); } private: diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TextBlobProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TextBlobProp.h index c084899f55ad5..5050baf1da47c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TextBlobProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TextBlobProp.h @@ -12,8 +12,10 @@ namespace RNSkia { class TextBlobProp : public DerivedSkProp { public: - explicit TextBlobProp(PropId name) : DerivedSkProp() { - _textBlobProp = addProperty(std::make_shared(name)); + explicit TextBlobProp(PropId name, + const std::function &onChange) + : DerivedSkProp(onChange) { + _textBlobProp = defineProperty(name); } void updateDerivedValue() override { @@ -37,14 +39,13 @@ class TextBlobProp : public DerivedSkProp { class TextPathBlobProp : public DerivedSkProp { public: - TextPathBlobProp() : DerivedSkProp() { - _fontProp = addProperty(std::make_shared(JsiPropId::get("font"))); - _textProp = addProperty(std::make_shared(JsiPropId::get("text"))); - _pathProp = addProperty(std::make_shared(JsiPropId::get("path"))); - _offsetProp = addProperty( - std::make_shared(JsiPropId::get("initialOffset"))); - - _fontProp->require(); + explicit TextPathBlobProp(const std::function &onChange) + : DerivedSkProp(onChange) { + _fontProp = defineProperty("font"); + _textProp = defineProperty("text"); + _pathProp = defineProperty("path"); + _offsetProp = defineProperty("initialOffset"); + _textProp->require(); _pathProp->require(); _offsetProp->require(); @@ -56,66 +57,70 @@ class TextPathBlobProp : public DerivedSkProp { auto path = _pathProp->getDerivedValue(); auto offset = _offsetProp->value().getAsNumber(); - // Get glyphs - auto numGlyphIds = - font->countText(text.c_str(), text.length(), SkTextEncoding::kUTF8); - - std::vector glyphIds; - glyphIds.reserve(numGlyphIds); - auto ids = font->textToGlyphs( - text.c_str(), text.length(), SkTextEncoding::kUTF8, - static_cast(glyphIds.data()), numGlyphIds); - - // Get glyph widths - int glyphsSize = static_cast(ids); - std::vector widthPtrs; - widthPtrs.resize(glyphsSize); - font->getWidthsBounds(glyphIds.data(), numGlyphIds, - static_cast(widthPtrs.data()), nullptr, - nullptr); // TODO: Should we use paint somehow here? - - std::vector rsx; - SkContourMeasureIter meas(*path, false, 1); - - auto cont = meas.next(); - auto dist = offset; - - for (size_t i = 0; i < text.length() && cont != nullptr; ++i) { - auto width = widthPtrs[i]; - dist += width / 2; - if (dist > cont->length()) { - // jump to next contour - cont = meas.next(); - if (cont == nullptr) { - // We have come to the end of the path - terminate the string - // right here. - text = text.substr(0, i); - break; + if (font != nullptr) { + // Get glyphs + auto numGlyphIds = + font->countText(text.c_str(), text.length(), SkTextEncoding::kUTF8); + + std::vector glyphIds; + glyphIds.reserve(numGlyphIds); + auto ids = font->textToGlyphs( + text.c_str(), text.length(), SkTextEncoding::kUTF8, + static_cast(glyphIds.data()), numGlyphIds); + + // Get glyph widths + int glyphsSize = static_cast(ids); + std::vector widthPtrs; + widthPtrs.resize(glyphsSize); + font->getWidthsBounds(glyphIds.data(), numGlyphIds, + static_cast(widthPtrs.data()), nullptr, + nullptr); // TODO: Should we use paint somehow here? + + std::vector rsx; + SkContourMeasureIter meas(*path, false, 1); + + auto cont = meas.next(); + auto dist = offset; + + for (size_t i = 0; i < text.length() && cont != nullptr; ++i) { + auto width = widthPtrs[i]; + dist += width / 2; + if (dist > cont->length()) { + // jump to next contour + cont = meas.next(); + if (cont == nullptr) { + // We have come to the end of the path - terminate the string + // right here. + text = text.substr(0, i); + break; + } + dist = width / 2; } - dist = width / 2; - } - // Gives us the (x, y) coordinates as well as the cos/sin of the tangent - // line at that position. - SkPoint pos; - SkVector tan; - if (!cont->getPosTan(dist, &pos, &tan)) { - throw std::runtime_error( - "Could not calculate distance when resolving text path"); - } - auto px = pos.x(); - auto py = pos.y(); - auto tx = tan.x(); - auto ty = tan.y(); + // Gives us the (x, y) coordinates as well as the cos/sin of the tangent + // line at that position. + SkPoint pos; + SkVector tan; + if (!cont->getPosTan(dist, &pos, &tan)) { + throw std::runtime_error( + "Could not calculate distance when resolving text path"); + } + auto px = pos.x(); + auto py = pos.y(); + auto tx = tan.x(); + auto ty = tan.y(); - auto adjustedX = px - (width / 2) * tx; - auto adjustedY = py - (width / 2) * ty; + auto adjustedX = px - (width / 2) * tx; + auto adjustedY = py - (width / 2) * ty; - rsx.push_back(SkRSXform::Make(tx, ty, adjustedX, adjustedY)); - dist += width / 2; - } + rsx.push_back(SkRSXform::Make(tx, ty, adjustedX, adjustedY)); + dist += width / 2; + } - setDerivedValue(SkTextBlob::MakeFromRSXform(text.c_str(), text.length(), - rsx.data(), *font)); + setDerivedValue(SkTextBlob::MakeFromRSXform(text.c_str(), text.length(), + rsx.data(), *font)); + } else { + setDerivedValue(nullptr); + } } private: diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TileModeProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TileModeProp.h index 50b9e0b3f7966..34a0a95e57239 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TileModeProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TileModeProp.h @@ -5,7 +5,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkTileMode.h" #include #include @@ -16,8 +16,10 @@ namespace RNSkia { class TileModeProp : public DerivedProp { public: - explicit TileModeProp(PropId name) : DerivedProp() { - _tileModeProp = addProperty(std::make_shared(name)); + explicit TileModeProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _tileModeProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformProp.h index 3d3bf8b2ff066..dfb30f842d867 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformProp.h @@ -20,8 +20,10 @@ static PropId PropNameRotateZ = JsiPropId::get("rotateZ"); class TransformProp : public DerivedProp { public: - explicit TransformProp(PropId name) : DerivedProp() { - _transformProp = addProperty(std::make_shared(name)); + explicit TransformProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _transformProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformsProps.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformsProps.h index 9189ef5151dbc..3173b8d32280f 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformsProps.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformsProps.h @@ -12,13 +12,11 @@ namespace RNSkia { class TransformsProps : public DerivedProp { public: - TransformsProps() : DerivedProp() { - _transformProp = addProperty( - std::make_shared(JsiPropId::get("transform"))); - _originProp = - addProperty(std::make_shared(JsiPropId::get("origin"))); - _matrixProp = - addProperty(std::make_shared(JsiPropId::get("matrix"))); + explicit TransformsProps(const std::function &onChange) + : DerivedProp(onChange) { + _transformProp = defineProperty("transform"); + _originProp = defineProperty("origin"); + _matrixProp = defineProperty("matrix"); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/UniformsProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/UniformsProp.h index a888ce46d81d5..8e222d6e1e2c8 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/UniformsProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/UniformsProp.h @@ -10,7 +10,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkRuntimeEffect.h" #pragma clang diagnostic pop @@ -80,8 +80,10 @@ void processUniform(std::vector &values, SkRuntimeEffect *source, class UniformsProp : public DerivedSkProp { public: - UniformsProp(PropId name, NodeProp *sourceProp) : DerivedSkProp() { - _uniformsProp = addProperty(std::make_shared(name)); + UniformsProp(PropId name, NodeProp *sourceProp, + const std::function &onChange) + : DerivedSkProp(onChange) { + _uniformsProp = defineProperty(name); _sourceProp = sourceProp; } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VertexModeProp.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VertexModeProp.h index 2158dbf6cb2c1..548ac48602759 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VertexModeProp.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VertexModeProp.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkVertices.h" #pragma clang diagnostic pop @@ -16,8 +16,10 @@ namespace RNSkia { class VertexModeProp : public DerivedProp { public: - explicit VertexModeProp(PropId name) : DerivedProp() { - _vertexModeProp = addProperty(std::make_shared(name)); + explicit VertexModeProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _vertexModeProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VerticesProps.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VerticesProps.h index be6e7a3176249..c0e23f3d22645 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VerticesProps.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VerticesProps.h @@ -13,7 +13,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkVertices.h" #pragma clang diagnostic pop @@ -21,17 +21,13 @@ namespace RNSkia { class VerticesProps : public DerivedSkProp { public: - VerticesProps() : DerivedSkProp() { - _vertexModeProp = - addProperty(std::make_shared(JsiPropId::get("mode"))); - _colorsProp = - addProperty(std::make_shared(JsiPropId::get("colors"))); - _verticesProp = - addProperty(std::make_shared(JsiPropId::get("vertices"))); - _texturesProp = - addProperty(std::make_shared(JsiPropId::get("textures"))); - _indicesProp = - addProperty(std::make_shared(JsiPropId::get("indices"))); + explicit VerticesProps(const std::function &onChange) + : DerivedSkProp(onChange) { + _vertexModeProp = defineProperty("mode"); + _colorsProp = defineProperty("colors"); + _verticesProp = defineProperty("vertices"); + _texturesProp = defineProperty("textures"); + _indicesProp = defineProperty("indices"); _vertexModeProp->require(); _verticesProp->require(); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkClockValue.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkClockValue.h index 7441c1d60d8d0..b65cb3b7997f0 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkClockValue.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkClockValue.h @@ -1,8 +1,8 @@ #pragma once -#include -#include +#include "RNSkPlatformContext.h" +#include "RNSkReadonlyValue.h" #include #include diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkComputedValue.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkComputedValue.h index d6cedf97224cd..d6071bffac2d1 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkComputedValue.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkComputedValue.h @@ -1,8 +1,8 @@ #pragma once +#include "RNSkPlatformContext.h" #include "RNSkReadonlyValue.h" -#include #include #include diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkReadonlyValue.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkReadonlyValue.h index f558918c8b75d..f8eb5aade6060 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkReadonlyValue.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkReadonlyValue.h @@ -10,9 +10,9 @@ #include -#include -#include -#include +#include "JsiSkHostObjects.h" +#include "JsiValueWrapper.h" +#include "RNSkPlatformContext.h" namespace RNSkia { namespace jsi = facebook::jsi; @@ -72,13 +72,13 @@ class RNSkReadonlyValue }); } - JSI_HOST_FUNCTION(__invalidate) { + JSI_HOST_FUNCTION(dispose) { invalidate(); return jsi::Value::undefined(); } JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkReadonlyValue, addListener), - JSI_EXPORT_FUNC(RNSkReadonlyValue, __invalidate)) + JSI_EXPORT_FUNC(RNSkReadonlyValue, dispose)) /** * Adds a callback that will be called whenever the value changes diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkValue.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkValue.h index 56879b3b870ca..381e0b8c4d7c4 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkValue.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkValue.h @@ -3,10 +3,10 @@ #include #include -#include -#include -#include -#include +#include "JsiHostObject.h" +#include "RNSkAnimation.h" +#include "RNSkPlatformContext.h" +#include "RNSkReadonlyValue.h" #include namespace RNSkia { @@ -70,7 +70,7 @@ class RNSkValue : public RNSkReadonlyValue { JSI_EXPORT_PROP_GET(RNSkValue, animation)) JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkValue, addListener), - JSI_EXPORT_FUNC(RNSkReadonlyValue, __invalidate)) + JSI_EXPORT_FUNC(RNSkReadonlyValue, dispose)) private: void subscribe(std::shared_ptr animation) { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h index 5c8059cd91ee7..3407cfd02c00d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h @@ -27,7 +27,7 @@ class SkShader; class SkAndroidFrameworkUtils { public: -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** * clipWithStencil draws the current clip into a stencil buffer with reference value and mask * set to 0x1. This function works only on a GPU canvas. @@ -37,7 +37,7 @@ class SkAndroidFrameworkUtils { * @return true on success or false if clip is empty or not a GPU canvas. */ static bool clipWithStencil(SkCanvas* canvas); -#endif //SK_SUPPORT_GPU +#endif //defined(SK_GANESH) static void SafetyNetLog(const char*); @@ -58,12 +58,6 @@ class SkAndroidFrameworkUtils { */ static SkCanvas* getBaseWrappedCanvas(SkCanvas* canvas); - /** - * Skia will change the order in which local matrices concatenate. In order to not break Android - * apps targeting older API levels we offer this function to use the legacy concatenation order. - */ - static void UseLegacyLocalMatrixConcatenation(); - /** * If the shader represents a linear gradient ShaderAsALinearGradient * returns true and if info is not null, ShaderAsALinearGradient populates diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h new file mode 100644 index 0000000000000..14ed009f8c400 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h @@ -0,0 +1,101 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkImageAndroid_DEFINED +#define SkImageAndroid_DEFINED + +#include "include/core/SkImage.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GrTypes.h" + +class SkColorSpace; +class GrDirectContext; +class SkPixmap; +struct AHardwareBuffer; + +namespace SkImages { + +/** (See Skia bug 7447) + Creates SkImage from Android hardware buffer. + Returned SkImage takes a reference on the buffer. + Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + @param hardwareBuffer AHardwareBuffer Android hardware buffer + @param colorSpace range of colors; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer, + SkAlphaType alphaType = kPremul_SkAlphaType); +SK_API sk_sp DeferredFromAHardwareBuffer( + AHardwareBuffer* hardwareBuffer, + SkAlphaType alphaType, + sk_sp colorSpace, + GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); + +/** Creates SkImage from Android hardware buffer and uploads the data from the SkPixmap to it. + Returned SkImage takes a reference on the buffer. + Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + @param context GPU context + @param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer + @param hardwareBuffer AHardwareBuffer Android hardware buffer + @param surfaceOrigin surface origin for resulting image + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromAHardwareBufferWithData( + GrDirectContext* context, + const SkPixmap& pixmap, + AHardwareBuffer* hardwareBuffer, + GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); + +/** + * Like SkImagePriv::SkMakeImageFromRasterBitmap, except this can be pinned using + * skgpu::ganesh::PinAsTexture and CopyPixelMode is never. + */ +SK_API sk_sp PinnableRasterFromBitmap(const SkBitmap&); + +} // namespace SkImages + +// TODO(kjlubick) remove this after Android has been ported. +namespace sk_image_factory { +inline sk_sp MakePinnableFromRasterBitmap(const SkBitmap& b) { + return SkImages::PinnableRasterFromBitmap(b); +} +} // namespace sk_image_factory + +namespace skgpu::ganesh { +/** + * Will attempt to upload and lock the contents of the image as a texture, so that subsequent + * draws to a gpu-target will come from that texture (and not by looking at the original image + * src). In particular this is intended to use the texture even if the image's original content + * changes subsequent to this call (i.e. the src is mutable!). + * + * Only compatible with SkImages created from SkImages::PinnableRasterFromBitmap. + * + * All successful calls must be balanced by an equal number of calls to UnpinTexture(). + * + * Once in this "pinned" state, the image has all of the same thread restrictions that exist + * for a natively created gpu image (e.g. SkImage::MakeFromTexture) + * - all drawing, pinning, unpinning must happen in the same thread as the GrContext. + * + * @return true if the image was successfully uploaded and locked into a texture + */ +bool PinAsTexture(GrRecordingContext*, SkImage*); + +/** + * The balancing call to a successful invocation of PinAsTexture. When a balanced + * number of calls have been made, then the "pinned" texture is free to be purged, etc. This + * also means that a subsequent "pin" call will look at the original content again, and if + * its uniqueID/generationID has changed, then a newer texture will be uploaded/pinned. + * + * Only compatible with SkImages created from SkImages::PinnableRasterFromBitmap. + * + * The context passed to unpin must match the one passed to pin. + */ +void UnpinTexture(GrRecordingContext*, SkImage*); + +} // namespace skgpu::ganesh + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h index 02625838308bd..2b8a79751cfd9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h @@ -9,24 +9,27 @@ #define SkAndroidCodec_DEFINED #include "include/codec/SkCodec.h" -#include "include/core/SkAlphaType.h" #include "include/core/SkColorSpace.h" -#include "include/core/SkColorType.h" -#include "include/core/SkEncodedImageFormat.h" #include "include/core/SkImageInfo.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" #include "include/private/SkEncodedInfo.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/skcms/skcms.h" +// TODO(kjlubick, bungeman) Replace these includes with forward declares +#include "include/codec/SkEncodedImageFormat.h" // IWYU pragma: keep +#include "include/core/SkAlphaType.h" // IWYU pragma: keep +#include "include/core/SkColorType.h" // IWYU pragma: keep + #include #include class SkData; class SkPngChunkReader; class SkStream; +struct SkGainmapInfo; struct SkIRect; /** @@ -118,10 +121,8 @@ class SK_API SkAndroidCodec : SkNoncopyable { /** * @param outputColorType Color type that the client will decode to. * @param prefColorSpace Preferred color space to decode to. - * This may not return |prefColorSpace| for a couple reasons. - * (1) Android Principles: 565 must be sRGB, F16 must be - * linear sRGB, transfer function must be parametric. - * (2) Codec Limitations: F16 requires a linear color space. + * This may not return |prefColorSpace| for + * specific color types. * * Returns the appropriate color space to decode to. */ @@ -262,6 +263,23 @@ class SK_API SkAndroidCodec : SkNoncopyable { SkCodec* codec() const { return fCodec.get(); } + /** + * Retrieve the gainmap for an image. + * + * @param outInfo On success, this is populated with the parameters for + * rendering this gainmap. This parameter must be non-nullptr. + * + * @param outGainmapImageStream On success, this is populated with a stream from which the + * gainmap image may be decoded. This parameter is optional, and + * may be set to nullptr. + * + * @return If this has a gainmap image and that gainmap image was + * successfully extracted then return true. Otherwise return + * false. + */ + bool getAndroidGainmap(SkGainmapInfo* outInfo, + std::unique_ptr* outGainmapImageStream); + protected: SkAndroidCodec(SkCodec*); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h index 5af847afcfe30..3ed1a95a800c9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h @@ -8,10 +8,7 @@ #ifndef SkCodec_DEFINED #define SkCodec_DEFINED -#include "include/codec/SkCodecAnimation.h" #include "include/codec/SkEncodedOrigin.h" -#include "include/core/SkAlphaType.h" -#include "include/core/SkEncodedImageFormat.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" #include "include/core/SkRect.h" @@ -20,21 +17,30 @@ #include "include/core/SkTypes.h" #include "include/core/SkYUVAPixmaps.h" #include "include/private/SkEncodedInfo.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/skcms/skcms.h" #include +#include #include #include #include -class SkAndroidCodec; class SkData; class SkFrameHolder; class SkImage; class SkPngChunkReader; class SkSampler; class SkStream; +struct SkGainmapInfo; +enum SkAlphaType : int; +enum class SkEncodedImageFormat; + +namespace SkCodecAnimation { +enum class Blend; +enum class DisposalMethod; +} + namespace DM { class CodecSrc; @@ -767,6 +773,8 @@ class SK_API SkCodec : SkNoncopyable { return fSrcXformFormat; } + virtual bool onGetGainmapInfo(SkGainmapInfo*, std::unique_ptr*) { return false; } + virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const { // By default, scaling is not supported. return this->dimensions(); @@ -887,8 +895,8 @@ class SK_API SkCodec : SkNoncopyable { const SkEncodedInfo fEncodedInfo; XformFormat fSrcXformFormat; std::unique_ptr fStream; - bool fNeedsRewind; - const SkEncodedOrigin fOrigin; + bool fNeedsRewind = false; + const SkEncodedOrigin fOrigin; SkImageInfo fDstInfo; Options fOptions; @@ -904,13 +912,13 @@ class SK_API SkCodec : SkNoncopyable { skcms_AlphaFormat fDstXformAlphaFormat; // Only meaningful during scanline decodes. - int fCurrScanline; + int fCurrScanline = -1; - bool fStartedIncrementalDecode; + bool fStartedIncrementalDecode = false; // Allows SkAndroidCodec to call handleFrameIndex (potentially decoding a prior frame and - // clearing to transparent) without SkCodec calling it, too. - bool fAndroidCodecHandlesFrameIndex; + // clearing to transparent) without SkCodec itself calling it, too. + bool fUsingCallbackForHandleFrameIndex = false; bool initializeColorXform(const SkImageInfo& dstInfo, SkEncodedInfo::Alpha, bool srcIsOpaque); @@ -934,17 +942,23 @@ class SK_API SkCodec : SkNoncopyable { return nullptr; } + // Callback for decoding a prior frame. The `Options::fFrameIndex` is ignored, + // being replaced by frameIndex. This allows opts to actually be a subclass of + // SkCodec::Options which SkCodec itself does not know how to copy or modify, + // but just passes through to the caller (where it can be reinterpret_cast'd). + using GetPixelsCallback = std::function; + /** * Check for a valid Options.fFrameIndex, and decode prior frames if necessary. * - * If androidCodec is not null, that means this SkCodec is owned by an SkAndroidCodec. In that - * case, the Options will be treated as an AndroidOptions, and SkAndroidCodec will be used to - * decode a prior frame, if a prior frame is needed. When such an owned SkCodec calls - * handleFrameIndex, it will immediately return kSuccess, since SkAndroidCodec already handled - * it. + * If GetPixelsCallback is not null, it will be used to decode a prior frame instead + * of using this SkCodec directly. It may also be used recursively, if that in turn + * depends on a prior frame. This is used by SkAndroidCodec. */ Result handleFrameIndex(const SkImageInfo&, void* pixels, size_t rowBytes, const Options&, - SkAndroidCodec* androidCodec = nullptr); + GetPixelsCallback = nullptr); // Methods for scanline decoding. virtual Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/, diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h new file mode 100644 index 0000000000000..99ca44e765c53 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h @@ -0,0 +1,36 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkEncodedImageFormat_DEFINED +#define SkEncodedImageFormat_DEFINED + +#include + +/** + * Enum describing format of encoded data. + */ +enum class SkEncodedImageFormat { +#ifdef SK_BUILD_FOR_GOOGLE3 + kUnknown, +#endif + kBMP, + kGIF, + kICO, + kJPEG, + kPNG, + kWBMP, + kWEBP, + kPKM, + kKTX, + kASTC, + kDNG, + kHEIF, + kAVIF, + kJPEGXL, +}; + +#endif // SkEncodedImageFormat_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h new file mode 100644 index 0000000000000..0df4a36f0c247 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h @@ -0,0 +1,31 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkPixmapUtils_DEFINED +#define SkPixmapUtils_DEFINED + +#include "include/codec/SkEncodedOrigin.h" +#include "include/core/SkImageInfo.h" +#include "include/private/base/SkAPI.h" + +class SkPixmap; + +namespace SkPixmapUtils { +/** + * Copy the pixels in src into dst, applying the orientation transformations specified + * by origin. If the inputs are invalid, this returns false and no copy is made. + */ +SK_API bool Orient(const SkPixmap& dst, const SkPixmap& src, SkEncodedOrigin origin); + +/** + * Return a copy of the provided ImageInfo with the width and height swapped. + */ +SK_API SkImageInfo SwapWidthHeight(const SkImageInfo& info); + +} // namespace SkPixmapUtils + +#endif // SkPixmapUtils_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPngChunkReader.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPngChunkReader.h similarity index 100% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPngChunkReader.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPngChunkReader.h diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h index 313d324e405b8..74c21f9438b9e 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h @@ -1,4 +1,3 @@ - /* * Copyright 2006 The Android Open Source Project * @@ -6,7 +5,6 @@ * found in the LICENSE file. */ - #ifndef SkUserConfig_DEFINED #define SkUserConfig_DEFINED @@ -16,9 +14,9 @@ Below are optional defines that add, subtract, or change default behavior in Skia. Your port can locally edit this file to enable/disable flags as - you choose, or these can be delared on your command line (i.e. -Dfoo). + you choose, or these can be declared on your command line (i.e. -Dfoo). - By default, this include file will always default to having all of the flags + By default, this #include file will always default to having all the flags commented out, so including it will have no effect. */ @@ -32,58 +30,92 @@ By default, these mutually exclusive flags are defined in SkTypes.h, based on the presence or absence of NDEBUG, but that decision can be changed here. - */ +*/ //#define SK_DEBUG //#define SK_RELEASE /* To write debug messages to a console, skia will call SkDebugf(...) following printf conventions (e.g. const char* format, ...). If you want to redirect this to something other than printf, define yours here - */ +*/ //#define SkDebugf(...) MyFunction(__VA_ARGS__) -/* - * To specify a different default font cache limit, define this. If this is - * undefined, skia will use a built-in value. - */ +/* Skia has both debug and release asserts. When an assert fails SK_ABORT will + be used to report an abort message. SK_ABORT is expected not to return. Skia + provides a default implementation which will print the message with SkDebugf + and then call sk_abort_no_print. +*/ +//#define SK_ABORT(message, ...) + +/* To specify a different default font strike cache memory limit, define this. If this is + undefined, skia will use a built-in value. +*/ //#define SK_DEFAULT_FONT_CACHE_LIMIT (1024 * 1024) -/* - * To specify the default size of the image cache, undefine this and set it to - * the desired value (in bytes). SkGraphics.h as a runtime API to set this - * value as well. If this is undefined, a built-in value will be used. - */ +/* To specify a different default font strike cache count limit, define this. If this is + undefined, skia will use a built-in value. +*/ +// #define SK_DEFAULT_FONT_CACHE_COUNT_LIMIT 2048 + +/* To specify the default size of the image cache, undefine this and set it to + the desired value (in bytes). SkGraphics.h as a runtime API to set this + value as well. If this is undefined, a built-in value will be used. +*/ //#define SK_DEFAULT_IMAGE_CACHE_LIMIT (1024 * 1024) /* Define this to set the upper limit for text to support LCD. Values that are very large increase the cost in the font cache and draw slower, without improving readability. If this is undefined, Skia will use its default value (e.g. 48) - */ +*/ //#define SK_MAX_SIZE_FOR_LCDTEXT 48 /* Change the kN32_SkColorType ordering to BGRA to work in X windows. - */ +*/ //#define SK_R32_SHIFT 16 - -/* Determines whether to build code that supports the GPU backend. Some classes +/* Determines whether to build code that supports the Ganesh GPU backend. Some classes that are not GPU-specific, such as SkShader subclasses, have optional code - that is used allows them to interact with the GPU backend. If you'd like to - omit this code set SK_SUPPORT_GPU to 0. This also allows you to omit the gpu - directories from your include search path when you're not building the GPU - backend. Defaults to 1 (build the GPU code). - */ -//#define SK_SUPPORT_GPU 1 + that is used allows them to interact with this GPU backend. If you'd like to + include this code, include -DSK_GANESH in your cflags or uncomment below. + Defaults to not set (No Ganesh GPU backend). + This define affects the ABI of Skia, so make sure it matches the client which uses + the compiled version of Skia. +*/ +//#define SK_GANESH /* Skia makes use of histogram logging macros to trace the frequency of - * events. By default, Skia provides no-op versions of these macros. - * Skia consumers can provide their own definitions of these macros to - * integrate with their histogram collection backend. - */ + events. By default, Skia provides no-op versions of these macros. + Skia consumers can provide their own definitions of these macros to + integrate with their histogram collection backend. +*/ //#define SK_HISTOGRAM_BOOLEAN(name, sample) //#define SK_HISTOGRAM_ENUMERATION(name, sample, enum_size) //#define SK_HISTOGRAM_EXACT_LINEAR(name, sample, value_max) //#define SK_HISTOGRAM_MEMORY_KB(name, sample) +/* Skia tries to make use of some non-standard C++ language extensions. + By default, Skia provides msvc and clang/gcc versions of these macros. + Skia consumers can provide their own definitions of these macros to + integrate with their own compilers and build system. +*/ +//#define SK_UNUSED [[maybe_unused]] +//#define SK_WARN_UNUSED_RESULT [[nodiscard]] +//#define SK_ALWAYS_INLINE inline __attribute__((always_inline)) +//#define SK_NEVER_INLINE __attribute__((noinline)) +//#define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) +//#define SK_NO_SANITIZE(A) __attribute__((no_sanitize(A))) +//#define SK_TRIVIAL_ABI [[clang::trivial_abi]] + +/* + * If compiling Skia as a DLL, public APIs should be exported. Skia will set + * SK_API to something sensible for Clang and MSVC, but if clients need to + * customize it for their build system or compiler, they may. + * If a client needs to use SK_API (e.g. overriding SK_ABORT), then they + * *must* define their own, the default will not be defined prior to loading + * this file. + */ +//#define SK_API __declspec(dllexport) + + #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h index 658f20716e7e5..d4ed7a6000b7a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h @@ -8,24 +8,32 @@ #ifndef SkBitmap_DEFINED #define SkBitmap_DEFINED +#include "include/core/SkAlphaType.h" #include "include/core/SkColor.h" #include "include/core/SkImageInfo.h" -#include "include/core/SkMatrix.h" #include "include/core/SkPixmap.h" #include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/core/SkShader.h" -#include "include/core/SkTileMode.h" +#include "include/core/SkSamplingOptions.h" +#include "include/core/SkSize.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkDebug.h" + +#include +#include -class SkBitmap; class SkColorSpace; -struct SkMask; +class SkImage; +class SkMatrix; class SkMipmap; -struct SkIRect; -struct SkRect; class SkPaint; class SkPixelRef; class SkShader; +enum SkColorType : int; +enum class SkTileMode; +struct SkMask; /** \class SkBitmap SkBitmap describes a two-dimensional raster pixel array. SkBitmap is built on @@ -766,11 +774,10 @@ class SK_API SkBitmap { treated as opaque. If colorType() is kAlpha_8_SkColorType, then RGB is ignored. @param c unpremultiplied color - @param colorSpace SkColorSpace of c example: https://fiddle.skia.org/c/@Bitmap_eraseColor */ - void eraseColor(SkColor4f c, SkColorSpace* colorSpace = nullptr) const; + void eraseColor(SkColor4f) const; /** Replaces pixel values with c, interpreted as being in the sRGB SkColorSpace. All pixels contained by bounds() are affected. If the colorType() is @@ -810,11 +817,9 @@ class SK_API SkBitmap { @param c unpremultiplied color @param area rectangle to fill - @param colorSpace SkColorSpace of c example: https://fiddle.skia.org/c/@Bitmap_erase */ - void erase(SkColor4f c, SkColorSpace* colorSpace, const SkIRect& area) const; void erase(SkColor4f c, const SkIRect& area) const; /** Replaces pixel values inside area with c. interpreted as being in the sRGB @@ -1168,23 +1173,18 @@ class SK_API SkBitmap { example: https://fiddle.skia.org/c/@Bitmap_peekPixels */ bool peekPixels(SkPixmap* pixmap) const; - sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, - const SkMatrix* = nullptr) const; + /** + * Make a shader with the specified tiling, matrix and sampling. + */ + sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, + const SkMatrix* localMatrix = nullptr) const; sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& localMatrix) const { - return this->makeShader(tmx, tmy, sampling, &localMatrix); - } - - sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix* localMatrix = nullptr) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, localMatrix); - } - + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix& localMatrix) const { - return this->makeShader(sampling, &localMatrix); - } + const SkMatrix* lm = nullptr) const; /** * Returns a new image from the bitmap. If the bitmap is marked immutable, this will diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h index aec37b6e686de..f0dde10f25c6b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h @@ -8,8 +8,6 @@ #ifndef SkBlurTypes_DEFINED #define SkBlurTypes_DEFINED -#include "include/core/SkTypes.h" - enum SkBlurStyle : int { kNormal_SkBlurStyle, //!< fuzzy inside and outside kSolid_SkBlurStyle, //!< solid inside, fuzzy outside diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h index b16872809e322..225b733a6b717 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h @@ -12,6 +12,7 @@ #include "include/core/SkClipOp.h" #include "include/core/SkColor.h" #include "include/core/SkFontTypes.h" +#include "include/core/SkImageFilter.h" #include "include/core/SkImageInfo.h" #include "include/core/SkM44.h" #include "include/core/SkMatrix.h" @@ -26,13 +27,13 @@ #include "include/core/SkString.h" #include "include/core/SkSurfaceProps.h" #include "include/core/SkTypes.h" -#include "include/private/SkDeque.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkDeque.h" +#include #include #include #include -#include #ifndef SK_SUPPORT_LEGACY_GETTOTALMATRIX #define SK_SUPPORT_LEGACY_GETTOTALMATRIX @@ -44,34 +45,39 @@ class GlyphRunList; } class AutoLayerForImageFilter; -class GrBackendRenderTarget; class GrRecordingContext; + class SkBaseDevice; class SkBitmap; +class SkBlender; class SkData; class SkDrawable; -struct SkDrawShadowRec; class SkFont; class SkImage; -class SkImageFilter; +class SkMesh; class SkPaintFilterCanvas; class SkPath; class SkPicture; class SkPixmap; -class SkRegion; class SkRRect; -struct SkRSXform; -class SkMesh; +class SkRegion; +class SkShader; class SkSpecialImage; class SkSurface; class SkSurface_Base; class SkTextBlob; class SkVertices; +struct SkDrawShadowRec; +struct SkRSXform; namespace skgpu::graphite { class Recorder; } namespace sktext::gpu { class Slug; } namespace SkRecords { class Draw; } +#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_GANESH) +class GrBackendRenderTarget; +#endif + // TODO: // This is not ideal but Chrome is depending on a forward decl of GrSlug here. // It should be removed once Chrome has migrated to sktext::gpu::Slug. @@ -650,7 +656,7 @@ class SK_API SkCanvas { SkRect bounds suggests but does not define layer size. To clip drawing to a specific rectangle, use clipRect(). - alpha of zero is fully transparent, 255 is fully opaque. + alpha of zero is fully transparent, 1.0f is fully opaque. Call restoreToCount() with returned value to restore this and subsequent saves. @@ -660,7 +666,11 @@ class SK_API SkCanvas { example: https://fiddle.skia.org/c/@Canvas_saveLayerAlpha */ - int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); + int saveLayerAlphaf(const SkRect* bounds, float alpha); + // Helper that accepts an int between 0 and 255, and divides it by 255.0 + int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { + return this->saveLayerAlphaf(bounds, alpha * (1.0f / 255)); + } /** \enum SkCanvas::SaveLayerFlagsSet SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, @@ -2173,7 +2183,7 @@ class SK_API SkCanvas { /////////////////////////////////////////////////////////////////////////// -#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && SK_SUPPORT_GPU +#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_GANESH) // These methods exist to support WebView in Android Framework. SkIRect topLayerBounds() const; GrBackendRenderTarget topLayerBackendRenderTarget() const; @@ -2290,7 +2300,7 @@ class SK_API SkCanvas { virtual void onDiscard(); -#if (SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED)) +#if (defined(SK_GANESH) || defined(SK_GRAPHITE)) /** Experimental */ virtual sk_sp onConvertGlyphRunListToSlug( @@ -2352,6 +2362,13 @@ class SK_API SkCanvas { // Encapsulate state needed to restore from saveBehind() struct BackImage { + // Out of line to avoid including SkSpecialImage.h + BackImage(sk_sp, SkIPoint); + BackImage(const BackImage&); + BackImage(BackImage&&); + BackImage& operator=(const BackImage&); + ~BackImage(); + sk_sp fImage; SkIPoint fLoc; }; @@ -2406,7 +2423,7 @@ class SK_API SkCanvas { fSurfaceBase = sb; } friend class SkSurface_Base; - friend class SkSurface_Gpu; + friend class SkSurface_Ganesh; SkIRect fClipRestrictionRect = SkIRect::MakeEmpty(); int fClipRestrictionSaveCount = -1; @@ -2440,7 +2457,7 @@ class SK_API SkCanvas { SkCanvas& operator=(SkCanvas&&) = delete; SkCanvas& operator=(const SkCanvas&) = delete; -#if (SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED)) +#if (defined(SK_GANESH) || defined(SK_GRAPHITE)) friend class sktext::gpu::Slug; /** Experimental * Convert a SkTextBlob to a sktext::gpu::Slug using the current canvas state. diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h index ef15c1670823d..214b5138f0b71 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h @@ -15,7 +15,7 @@ namespace SkSL { struct ShaderCaps; } #endif -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) namespace skgpu::graphite { class Caps; } #endif @@ -28,7 +28,7 @@ class SK_API SkCapabilities : public SkRefCnt { #endif protected: -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) friend class skgpu::graphite::Caps; // for ctor #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h index 6a920e93fddb4..3b46be030f224 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h @@ -11,8 +11,10 @@ #include "include/core/SkAlphaType.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" #include +#include /** \file SkColor.h diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h index 29f64339baaac..f89de9db72fcb 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h @@ -9,9 +9,11 @@ #define SkColorPriv_DEFINED #include "include/core/SkColor.h" -#include "include/core/SkMath.h" -#include "include/private/SkTPin.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkTPin.h" +#include "include/private/base/SkTo.h" + +#include /** Turn 0..255 into 0..256 by adding 1 at the half-way point. Used to turn a byte into a scale value, so that we can say scale * value >> 8 instead of @@ -146,7 +148,20 @@ static SK_ALWAYS_INLINE uint32_t SkAlphaMulQ(uint32_t c, unsigned scale) { } static inline SkPMColor SkPMSrcOver(SkPMColor src, SkPMColor dst) { - return src + SkAlphaMulQ(dst, SkAlpha255To256(255 - SkGetPackedA32(src))); + uint32_t scale = SkAlpha255To256(255 - SkGetPackedA32(src)); + + uint32_t mask = 0xFF00FF; + uint32_t rb = (((dst & mask) * scale) >> 8) & mask; + uint32_t ag = (((dst >> 8) & mask) * scale) & ~mask; + + rb += (src & mask); + ag += (src & ~mask); + + // Color channels (but not alpha) can overflow, so we have to saturate to 0xFF in each lane. + return std::min(rb & 0x000001FF, 0x000000FFU) | + std::min(ag & 0x0001FF00, 0x0000FF00U) | + std::min(rb & 0x01FF0000, 0x00FF0000U) | + (ag & 0xFF000000); } #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h index a09758645b161..57c29e222a43b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h @@ -9,10 +9,13 @@ #define SkColorSpace_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkFixed.h" -#include "include/private/SkOnce.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkFixed.h" +#include "include/private/base/SkOnce.h" #include "modules/skcms/skcms.h" -#include + +#include +#include class SkData; @@ -147,8 +150,7 @@ class SK_API SkColorSpace : public SkNVRefCnt { bool isNumericalTransferFn(skcms_TransferFunction* fn) const; /** - * Returns true and sets |toXYZD50| if the color gamut can be described as a matrix. - * Returns false otherwise. + * Returns true and sets |toXYZD50|. */ bool toXYZD50(skcms_Matrix3x3* toXYZD50) const; @@ -160,23 +162,19 @@ class SK_API SkColorSpace : public SkNVRefCnt { /** * Returns a color space with the same gamut as this one, but with a linear gamma. - * For color spaces whose gamut can not be described in terms of XYZ D50, returns - * linear sRGB. */ sk_sp makeLinearGamma() const; /** - * Returns a color space with the same gamut as this one, with with the sRGB transfer - * function. For color spaces whose gamut can not be described in terms of XYZ D50, returns - * sRGB. + * Returns a color space with the same gamut as this one, but with the sRGB transfer + * function. */ sk_sp makeSRGBGamma() const; /** * Returns a color space with the same transfer function as this one, but with the primary - * colors rotated. For any XYZ space, this produces a new color space that maps RGB to GBR - * (when applied to a source), and maps RGB to BRG (when applied to a destination). For other - * types of color spaces, returns nullptr. + * colors rotated. In other words, this produces a new color space that maps RGB to GBR + * (when applied to a source), and maps RGB to BRG (when applied to a destination). * * This is used for testing, to construct color spaces that have severe and testable behavior. */ @@ -190,15 +188,14 @@ class SK_API SkColorSpace : public SkNVRefCnt { * in some cases: converting ICC fixed point to float, converting white point to D50, * rounding decisions on transfer function and matrix. * - * This does not consider a 2.2f exponential transfer function to be sRGB. While these + * This does not consider a 2.2f exponential transfer function to be sRGB. While these * functions are similar (and it is sometimes useful to consider them together), this * function checks for logical equality. */ bool isSRGB() const; /** - * Returns nullptr on failure. Fails when we fallback to serializing ICC data and - * the data is too large to serialize. + * Returns a serialized representation of this color space. */ sk_sp serialize() const; @@ -211,7 +208,7 @@ class SK_API SkColorSpace : public SkNVRefCnt { static sk_sp Deserialize(const void* data, size_t length); /** - * If both are null, we return true. If one is null and the other is not, we return false. + * If both are null, we return true. If one is null and the other is not, we return false. * If both are non-null, we do a deeper compare. */ static bool Equals(const SkColorSpace*, const SkColorSpace*); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h index b51aa7b96f96b..a68dc833b49b5 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h @@ -28,6 +28,7 @@ enum SkColorType : int { kBGRA_1010102_SkColorType, //!< 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word kRGB_101010x_SkColorType, //!< pixel with 10 bits each for red, green, blue; in 32-bit word kBGR_101010x_SkColorType, //!< pixel with 10 bits each for blue, green, red; in 32-bit word + kBGR_101010x_XR_SkColorType, //!< pixel with 10 bits each for blue, green, red; in 32-bit word, extended range kGray_8_SkColorType, //!< pixel with grayscale level in 8-bit byte kRGBA_F16Norm_SkColorType, //!< pixel with half floats in [0,1] for red, green, blue, alpha; // in 64-bit word diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h index 08a50b11054c8..7090deaaed22a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h @@ -10,7 +10,7 @@ #include "include/core/SkPath.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" struct SkConic; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h index ea5b73d1a4776..aaae60c41920d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h @@ -8,8 +8,6 @@ #ifndef SkCoverageMode_DEFINED #define SkCoverageMode_DEFINED -#include "include/core/SkTypes.h" - /** * Describes geometric operations (ala SkRegion::Op) that can be applied to coverage bytes. * These can be thought of as variants of porter-duff (SkBlendMode) modes, but only applied diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h index 7389b92afd099..863c9333f6e1e 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h @@ -9,6 +9,8 @@ #define SkCubicMap_DEFINED #include "include/core/SkPoint.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" /** * Fast evaluation of a cubic ease-in / ease-out curve. This is defined as a parametric cubic diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkData.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkData.h index 2a4b40d5f614a..2b50cebc81b6a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkData.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkData.h @@ -8,9 +8,12 @@ #ifndef SkData_DEFINED #define SkData_DEFINED -#include - #include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" + +#include +#include class SkStream; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h index a6a510b7b221e..3aa48d5f33ea0 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h @@ -8,8 +8,12 @@ #ifndef SkDataTable_DEFINED #define SkDataTable_DEFINED -#include "include/core/SkData.h" -#include "include/private/SkTDArray.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" + +#include +#include /** * Like SkData, SkDataTable holds an immutable data buffer. The data buffer is diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h index 28e460fa8b050..e5511beea3aea 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h @@ -13,10 +13,11 @@ #include "include/core/SkTypes.h" class SkDeferredDisplayListPriv; +class SkPromiseImageTexture; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrRecordingContext.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include class GrRenderTask; class GrRenderTargetProxy; @@ -36,7 +37,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { return fCharacterization; } -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** * Iterate through the programs required by the DDL. */ @@ -52,7 +53,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { private: GrDirectContext* fDContext; - const SkTArray& fProgramData; + const skia_private::TArray& fProgramData; int fIndex; }; #endif @@ -70,7 +71,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { // texture when the DDL is replayed. It has to be separately ref counted bc the lazy proxy // can outlive the DDL. class LazyProxyData : public SkRefCnt { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) public: // Upon being replayed - this field will be filled in (by the DrawingManager) with the // proxy backing the destination SkSurface. Note that, since there is no good place to @@ -87,21 +88,21 @@ class SkDeferredDisplayList : public SkNVRefCnt { sk_sp fTargetProxy, sk_sp); -#if SK_SUPPORT_GPU - const SkTArray& programData() const { +#if defined(SK_GANESH) + const skia_private::TArray& programData() const { return fProgramData; } #endif const SkSurfaceCharacterization fCharacterization; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) // These are ordered such that the destructor cleans op tasks up first (which may refer back // to the arena and memory pool in their destructors). GrRecordingContext::OwnedArenas fArenas; - SkTArray> fRenderTasks; + skia_private::TArray> fRenderTasks; - SkTArray fProgramData; + skia_private::TArray fProgramData; sk_sp fTargetProxy; sk_sp fLazyProxyData; #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h index 8103485597fcf..cd91798513bdf 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h @@ -50,13 +50,14 @@ class SK_API SkDeferredDisplayListRecorder { sk_sp detach(); -#if SK_SUPPORT_GPU - using PromiseImageTextureContext = SkImage::PromiseImageTextureContext; - using PromiseImageTextureFulfillProc = SkImage::PromiseImageTextureFulfillProc; - using PromiseImageTextureReleaseProc = SkImage::PromiseImageTextureReleaseProc; +#if defined(SK_GANESH) + using PromiseImageTextureContext = void*; + using PromiseImageTextureFulfillProc = + sk_sp (*)(PromiseImageTextureContext); + using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); #ifndef SK_MAKE_PROMISE_TEXTURE_DISABLE_LEGACY_API - /** Deprecated: Use SkImage::MakePromiseTexture instead. */ + /** Deprecated: Use SkImages::PromiseTextureFrom instead. */ sk_sp makePromiseTexture(const GrBackendFormat& backendFormat, int width, int height, @@ -69,14 +70,14 @@ class SK_API SkDeferredDisplayListRecorder { PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContext); - /** Deprecated: Use SkImage::MakePromiseYUVATexture instead. */ + /** Deprecated: Use SkImages::PromiseTextureFromYUVA instead. */ sk_sp makeYUVAPromiseTexture(const GrYUVABackendTextureInfo& yuvaBackendTextureInfo, sk_sp imageColorSpace, PromiseImageTextureFulfillProc textureFulfillProc, PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContexts[]); #endif // SK_MAKE_PROMISE_TEXTURE_DISABLE_LEGACY_API -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) private: SkDeferredDisplayListRecorder(const SkDeferredDisplayListRecorder&) = delete; @@ -86,7 +87,7 @@ class SK_API SkDeferredDisplayListRecorder { const SkSurfaceCharacterization fCharacterization; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) sk_sp fContext; sk_sp fTargetProxy; sk_sp fLazyProxyData; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h index c86543dc6b367..316bf058bcf5a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h @@ -9,14 +9,22 @@ #define SkDrawable_DEFINED #include "include/core/SkFlattenable.h" -#include "include/core/SkImageInfo.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" +#include "include/private/base/SkAPI.h" + +#include +#include +#include class GrBackendDrawableInfo; class SkCanvas; class SkMatrix; class SkPicture; -enum class GrBackendApi : unsigned; +enum class GrBackendApi : unsigned int; +struct SkDeserialProcs; +struct SkIRect; +struct SkImageInfo; struct SkRect; /** diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h index 99ca44e765c53..0db3830b9ac71 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h @@ -1,36 +1,9 @@ /* - * Copyright 2015 Google Inc. + * Copyright 2023 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#ifndef SkEncodedImageFormat_DEFINED -#define SkEncodedImageFormat_DEFINED - -#include - -/** - * Enum describing format of encoded data. - */ -enum class SkEncodedImageFormat { -#ifdef SK_BUILD_FOR_GOOGLE3 - kUnknown, -#endif - kBMP, - kGIF, - kICO, - kJPEG, - kPNG, - kWBMP, - kWEBP, - kPKM, - kKTX, - kASTC, - kDNG, - kHEIF, - kAVIF, - kJPEGXL, -}; - -#endif // SkEncodedImageFormat_DEFINED +// TODO(kjlubick) remove this shim after clients have been moved to the new location +#include "include/codec/SkEncodedImageFormat.h" // IWYU pragma: export diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h index 916ee174f4828..3585e845b5489 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h @@ -9,13 +9,15 @@ #define SkFlattenable_DEFINED #include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +#include class SkData; class SkReadBuffer; class SkWriteBuffer; - -struct SkSerialProcs; struct SkDeserialProcs; +struct SkSerialProcs; /** \class SkFlattenable diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h index 05fb7db414887..88e92694bd455 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h @@ -11,6 +11,7 @@ #include "include/core/SkFontTypes.h" #include "include/core/SkScalar.h" #include "include/core/SkTypeface.h" +#include "include/private/base/SkTemplates.h" #include diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h index 717a87f056f38..f4960393113cb 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h @@ -9,6 +9,7 @@ #define SkFontMetrics_DEFINED #include "include/core/SkScalar.h" +#include "include/private/base/SkTo.h" /** \class SkFontMetrics The metrics of an SkFont. diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h index 125262b466753..eccb0a729cba0 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h @@ -13,6 +13,8 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkTypes.h" +#include + class SkData; class SkFontData; class SkStreamAsset; @@ -23,23 +25,20 @@ class SK_API SkFontStyleSet : public SkRefCnt { public: virtual int count() = 0; virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0; - virtual SkTypeface* createTypeface(int index) = 0; - virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0; + virtual sk_sp createTypeface(int index) = 0; + virtual sk_sp matchStyle(const SkFontStyle& pattern) = 0; - static SkFontStyleSet* CreateEmpty(); + static sk_sp CreateEmpty(); protected: - SkTypeface* matchStyleCSS3(const SkFontStyle& pattern); - -private: - using INHERITED = SkRefCnt; + sk_sp matchStyleCSS3(const SkFontStyle& pattern); }; class SK_API SkFontMgr : public SkRefCnt { public: int countFamilies() const; void getFamilyName(int index, SkString* familyName) const; - SkFontStyleSet* createStyleSet(int index) const; + sk_sp createStyleSet(int index) const; /** * The caller must call unref() on the returned object. @@ -52,7 +51,7 @@ class SK_API SkFontMgr : public SkRefCnt { * It is possible that this will return a style set not accessible from * createStyleSet(int) due to hidden or auto-activated fonts. */ - SkFontStyleSet* matchFamily(const char familyName[]) const; + sk_sp matchFamily(const char familyName[]) const; /** * Find the closest matching typeface to the specified familyName and style @@ -66,7 +65,7 @@ class SK_API SkFontMgr : public SkRefCnt { * createStyleSet(int) or matchFamily(const char[]) due to hidden or * auto-activated fonts. */ - SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&) const; + sk_sp matchFamilyStyle(const char familyName[], const SkFontStyle&) const; /** * Use the system fallback to find a typeface for the given character. @@ -83,9 +82,9 @@ class SK_API SkFontMgr : public SkRefCnt { * most significant. If no specified bcp47 codes match, any font with the * requested character will be matched. */ - SkTypeface* matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const; + sk_sp matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const; /** * Create a typeface for the specified data and TTC index (pass 0 for none) @@ -123,16 +122,17 @@ class SK_API SkFontMgr : public SkRefCnt { protected: virtual int onCountFamilies() const = 0; virtual void onGetFamilyName(int index, SkString* familyName) const = 0; - virtual SkFontStyleSet* onCreateStyleSet(int index)const = 0; + virtual sk_sp onCreateStyleSet(int index)const = 0; /** May return NULL if the name is not found. */ - virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const = 0; + virtual sk_sp onMatchFamily(const char familyName[]) const = 0; - virtual SkTypeface* onMatchFamilyStyle(const char familyName[], - const SkFontStyle&) const = 0; - virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const = 0; + virtual sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle&) const = 0; + virtual sk_sp onMatchFamilyStyleCharacter(const char familyName[], + const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const = 0; virtual sk_sp onMakeFromData(sk_sp, int ttcIndex) const = 0; virtual sk_sp onMakeFromStreamIndex(std::unique_ptr, @@ -143,18 +143,9 @@ class SK_API SkFontMgr : public SkRefCnt { virtual sk_sp onLegacyMakeTypeface(const char familyName[], SkFontStyle) const = 0; - // this method is never called -- will be removed - virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, - const SkFontStyle&) const { - return nullptr; - } - private: - /** Implemented by porting layer to return the default factory. */ static sk_sp Factory(); - - using INHERITED = SkRefCnt; }; #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h index 04893ef2fdc59..be46b53bb2852 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h @@ -9,7 +9,9 @@ #define SkFontStyle_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkTPin.h" +#include "include/private/base/SkTPin.h" + +#include class SK_API SkFontStyle { public: @@ -75,6 +77,7 @@ class SK_API SkFontStyle { } private: + friend class SkTypefaceProxyPrototype; // To serialize fValue int32_t fValue; }; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h index c24bb742e71df..6ce9175d1e091 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h @@ -10,9 +10,12 @@ #include "include/core/SkRefCnt.h" +#include + class SkData; class SkImageGenerator; class SkOpenTypeSVGDecoder; +class SkPath; class SkTraceMemoryDump; class SK_API SkGraphics { @@ -115,16 +118,6 @@ class SK_API SkGraphics { */ static void PurgeAllCaches(); - /** - * Applications with command line options may pass optional state, such - * as cache sizes, here, for instance: - * font-cache-limit=12345678 - * - * The flags format is name=value[;name=value...] with no spaces. - * This format is subject to change. - */ - static void SetFlags(const char* flags); - typedef std::unique_ptr (*ImageGeneratorFromEncodedDataFactory)(sk_sp); @@ -151,18 +144,28 @@ class SK_API SkGraphics { static OpenTypeSVGDecoderFactory GetOpenTypeSVGDecoderFactory(); /** - * Temporarily (until variable COLRv1 is released) pass a feature switch function for whether - * variable COLRv1 is enabled. Needed for initializing FreeType with a property setting so that - * variable COLRv1 can be enabled in Chrome Canaries during development. + * Call early in main() to allow Skia to use a JIT to accelerate CPU-bound operations. */ - using VariableColrV1EnabledFunc = bool (*)(); - static VariableColrV1EnabledFunc SetVariableColrV1EnabledFunc(VariableColrV1EnabledFunc); - static bool GetVariableColrV1Enabled(); + static void AllowJIT(); /** - * Call early in main() to allow Skia to use a JIT to accelerate CPU-bound operations. + * To override the default AA algorithm choice in the CPU backend, provide a function that + * returns whether to use analytic (true) or supersampled (false) for a given path. + * + * NOTE: This is a temporary API, intended for migration of all clients to one algorithm, + * and should not be used. */ - static void AllowJIT(); + typedef bool (*PathAnalyticAADeciderProc)(const SkPath&); + static void SetPathAnalyticAADecider(PathAnalyticAADeciderProc); + + /* + * Similar to above, but simply forces the CPU backend to always use analytic AA. + * + * NOTE: This is a temporary API, intended for migration of all clients to one algorithm. + * If the PathAnalyticAADeciderProc is *also* set, this setting has no effect. + * Unlike that API, this function is thread-safe. + */ + static void SetForceAnalyticAA(bool); }; class SkAutoGraphics { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h index cb84c1ffbc76d..c0b458100cf88 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h @@ -1,19 +1,9 @@ /* - * Copyright 2016 Google Inc. + * Copyright 2023 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#ifndef SkICC_DEFINED -#define SkICC_DEFINED - -#include "include/core/SkData.h" - -struct skcms_Matrix3x3; -struct skcms_TransferFunction; - -SK_API sk_sp SkWriteICCProfile(const skcms_TransferFunction&, - const skcms_Matrix3x3& toXYZD50); - -#endif//SkICC_DEFINED +// TODO(kjlubick) remove this shim after clients have been moved to the new location +#include "include/encode/SkICC.h" // IWYU pragma: export diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h index 4157eafa0b509..8f7d4a46bd9d9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h @@ -8,581 +8,252 @@ #ifndef SkImage_DEFINED #define SkImage_DEFINED +#include "include/core/SkAlphaType.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/core/SkSamplingOptions.h" -#include "include/core/SkScalar.h" -#include "include/core/SkShader.h" -#include "include/core/SkSurfaceProps.h" -#include "include/core/SkTileMode.h" -#if SK_SUPPORT_GPU -#include "include/gpu/GrTypes.h" -#endif -#if defined(SK_GRAPHITE_ENABLED) +#include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" + +#if defined(SK_GRAPHITE) #include "include/gpu/graphite/GraphiteTypes.h" +class SkYUVAPixmaps; #endif -#include // std::function -#include -#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 -#include -#endif +#include +#include +#include +#include -class GrBackendFormat; -class GrBackendTexture; -class GrContextThreadSafeProxy; class GrDirectContext; class GrRecordingContext; -class GrYUVABackendTextureInfo; -class GrYUVABackendTextures; -class SkCanvas; +class SkBitmap; +class SkColorSpace; class SkData; class SkImage; class SkImageFilter; class SkImageGenerator; +class SkMatrix; class SkMipmap; class SkPaint; class SkPicture; class SkPixmap; -class SkPromiseImageTexture; -class SkSurface; -class SkYUVAPixmaps; +class SkShader; +class SkSurfaceProps; +enum SkColorType : int; +enum class SkTextureCompressionType; +enum class SkTileMode; -enum class SkEncodedImageFormat; +struct SkIPoint; +struct SkSamplingOptions; -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) namespace skgpu::graphite { class BackendTexture; class Recorder; -}; +class TextureInfo; +enum class Volatile : bool; +class YUVABackendTextures; +} #endif -/** \class SkImage - SkImage describes a two dimensional array of pixels to draw. The pixels may be - decoded in a raster bitmap, encoded in a SkPicture or compressed data stream, - or located in GPU memory as a GPU texture. - - SkImage cannot be modified after it is created. SkImage may allocate additional - storage as needed; for instance, an encoded SkImage may decode when drawn. +namespace SkImages { - SkImage width and height are greater than zero. Creating an SkImage with zero width - or height returns SkImage equal to nullptr. - - SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams, - GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported - include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details - vary with platform. +/** Caller data passed to RasterReleaseProc; may be nullptr. */ +using ReleaseContext = void*; +/** Function called when SkImage no longer shares pixels. ReleaseContext is + provided by caller when SkImage is created, and may be nullptr. */ -class SK_API SkImage : public SkRefCnt { -public: - - /** Caller data passed to RasterReleaseProc; may be nullptr. - */ - typedef void* ReleaseContext; - - /** Creates SkImage from SkPixmap and copy of pixels. Since pixels are copied, SkPixmap - pixels may be modified or deleted without affecting SkImage. - - SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param pixmap SkImageInfo, pixel address, and row bytes - @return copy of SkPixmap pixels, or nullptr +using RasterReleaseProc = void(const void* pixels, ReleaseContext); - example: https://fiddle.skia.org/c/@Image_MakeRasterCopy - */ - static sk_sp MakeRasterCopy(const SkPixmap& pixmap); - - /** Creates SkImage from SkImageInfo, sharing pixels. +/** Creates a CPU-backed SkImage from bitmap, sharing or copying bitmap pixels. If the bitmap + is marked immutable, and its pixel memory is shareable, it may be shared + instead of copied. - SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - rowBytes are large enough to hold one row of pixels; - pixels is not nullptr, and contains enough data for SkImage. - - @param info contains width, height, SkAlphaType, SkColorType, SkColorSpace - @param pixels address or pixel storage - @param rowBytes size of pixel row or larger - @return SkImage sharing pixels, or nullptr - */ - static sk_sp MakeRasterData(const SkImageInfo& info, sk_sp pixels, - size_t rowBytes); + SkImage is returned if bitmap is valid. Valid SkBitmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. - /** Function called when SkImage no longer shares pixels. ReleaseContext is - provided by caller when SkImage is created, and may be nullptr. - */ - typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext); - - /** Creates SkImage from pixmap, sharing SkPixmap pixels. Pixels must remain valid and - unchanged until rasterReleaseProc is called. rasterReleaseProc is passed - releaseContext when SkImage is deleted or no longer refers to pixmap pixels. - - Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback - when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc - does not require state. - - SkImage is returned if pixmap is valid. Valid SkPixmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param pixmap SkImageInfo, pixel address, and row bytes - @param rasterReleaseProc function called when pixels can be released; or nullptr - @param releaseContext state passed to rasterReleaseProc; or nullptr - @return SkImage sharing pixmap - */ - static sk_sp MakeFromRaster(const SkPixmap& pixmap, - RasterReleaseProc rasterReleaseProc, - ReleaseContext releaseContext); - - /** Creates SkImage from bitmap, sharing or copying bitmap pixels. If the bitmap - is marked immutable, and its pixel memory is shareable, it may be shared - instead of copied. - - SkImage is returned if bitmap is valid. Valid SkBitmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param bitmap SkImageInfo, row bytes, and pixels - @return created SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_MakeFromBitmap - */ - static sk_sp MakeFromBitmap(const SkBitmap& bitmap); - - /** Creates SkImage from data returned by imageGenerator. Generated data is owned by SkImage and - may not be shared or accessed. - - SkImage is returned if generator data is valid. Valid data parameters vary by type of data - and platform. - - imageGenerator may wrap SkPicture data, codec data, or custom data. - - @param imageGenerator stock or custom routines to retrieve SkImage - @return created SkImage, or nullptr - */ - static sk_sp MakeFromGenerator(std::unique_ptr imageGenerator); - - /** - * Return an image backed by the encoded data, but attempt to defer decoding until the image - * is actually used/drawn. This deferral allows the system to cache the result, either on the - * CPU or on the GPU, depending on where the image is drawn. If memory is low, the cache may - * be purged, causing the next draw of the image to have to re-decode. - * - * If alphaType is nullopt, the image's alpha type will be chosen automatically based on the - * image format. Transparent images will default to kPremul_SkAlphaType. If alphaType contains - * kPremul_SkAlphaType or kUnpremul_SkAlphaType, that alpha type will be used. Forcing opaque - * (passing kOpaque_SkAlphaType) is not allowed, and will return nullptr. - * - * This is similar to DecodeTo[Raster,Texture], but this method will attempt to defer the - * actual decode, while the DecodeTo... method explicitly decode and allocate the backend - * when the call is made. - * - * If the encoded format is not supported, nullptr is returned. - * - * @param encoded the encoded data - * @return created SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_MakeFromEncoded - */ - static sk_sp MakeFromEncoded(sk_sp encoded, - std::optional alphaType = std::nullopt); - - /* - * Experimental: - * Skia | GL_COMPRESSED_* | MTLPixelFormat* | VK_FORMAT_*_BLOCK - * -------------------------------------------------------------------------------------- - * kETC2_RGB8_UNORM | ETC1_RGB8 | ETC2_RGB8 (iOS-only) | ETC2_R8G8B8_UNORM - * | RGB8_ETC2 | | - * -------------------------------------------------------------------------------------- - * kBC1_RGB8_UNORM | RGB_S3TC_DXT1_EXT | N/A | BC1_RGB_UNORM - * -------------------------------------------------------------------------------------- - * kBC1_RGBA8_UNORM | RGBA_S3TC_DXT1_EXT | BC1_RGBA (macOS-only)| BC1_RGBA_UNORM - */ - enum class CompressionType { - kNone, - kETC2_RGB8_UNORM, // the same as ETC1 - - kBC1_RGB8_UNORM, - kBC1_RGBA8_UNORM, - kLast = kBC1_RGBA8_UNORM, - }; + @param bitmap SkImageInfo, row bytes, and pixels + @return created SkImage, or nullptr +*/ +SK_API sk_sp RasterFromBitmap(const SkBitmap& bitmap); - static constexpr int kCompressionTypeCount = static_cast(CompressionType::kLast) + 1; +/** Creates a CPU-backed SkImage from compressed data. - static const CompressionType kETC1_CompressionType = CompressionType::kETC2_RGB8_UNORM; + This method will decompress the compressed data and create an image wrapping + it. Any mipmap levels present in the compressed data are discarded. - /** Creates a CPU-backed SkImage from compressed data. + @param data compressed data to store in SkImage + @param width width of full SkImage + @param height height of full SkImage + @param type type of compression used + @return created SkImage, or nullptr +*/ +SK_API sk_sp RasterFromCompressedTextureData(sk_sp data, + int width, + int height, + SkTextureCompressionType type); + +/** + * Return a SkImage using the encoded data, but attempts to defer decoding until the + * image is actually used/drawn. This deferral allows the system to cache the result, either on the + * CPU or on the GPU, depending on where the image is drawn. If memory is low, the cache may + * be purged, causing the next draw of the image to have to re-decode. + * + * If alphaType is nullopt, the image's alpha type will be chosen automatically based on the + * image format. Transparent images will default to kPremul_SkAlphaType. If alphaType contains + * kPremul_SkAlphaType or kUnpremul_SkAlphaType, that alpha type will be used. Forcing opaque + * (passing kOpaque_SkAlphaType) is not allowed, and will return nullptr. + * + * If the encoded format is not supported, nullptr is returned. + * + * @param encoded the encoded data + * @return created SkImage, or nullptr - This method will decompress the compressed data and create an image wrapping - it. Any mipmap levels present in the compressed data are discarded. + example: https://fiddle.skia.org/c/@Image_DeferredFromEncodedData +*/ +SK_API sk_sp DeferredFromEncodedData(sk_sp encoded, + std::optional alphaType = std::nullopt); - @param data compressed data to store in SkImage - @param width width of full SkImage - @param height height of full SkImage - @param type type of compression used - @return created SkImage, or nullptr - */ - static sk_sp MakeRasterFromCompressed(sk_sp data, - int width, int height, - CompressionType type); +/** Creates SkImage from data returned by imageGenerator. The image data will not be created + (on either the CPU or GPU) until the image is actually drawn. + Generated data is owned by SkImage and may not be shared or accessed. - enum class BitDepth { - kU8, //!< uses 8-bit unsigned int per color component - kF16, //!< uses 16-bit float per color component - }; + SkImage is returned if generator data is valid. Valid data parameters vary by type of data + and platform. - /** Creates SkImage from picture. Returned SkImage width and height are set by dimensions. - SkImage draws picture with matrix and paint, set to bitDepth and colorSpace. + imageGenerator may wrap SkPicture data, codec data, or custom data. - If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws - with default SkPaint. colorSpace may be nullptr. + @param imageGenerator stock or custom routines to retrieve SkImage + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromGenerator(std::unique_ptr imageGenerator); - @param picture stream of drawing commands - @param dimensions width and height - @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr - @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr - @param bitDepth 8-bit integer or 16-bit float: per component - @param colorSpace range of colors; may be nullptr - @param props props to use when rasterizing the picture - @return created SkImage, or nullptr - */ - static sk_sp MakeFromPicture(sk_sp picture, const SkISize& dimensions, - const SkMatrix* matrix, const SkPaint* paint, - BitDepth bitDepth, sk_sp colorSpace, - SkSurfaceProps props = {}); - -#if SK_SUPPORT_GPU - /** Creates a GPU-backed SkImage from compressed data. - - This method will return an SkImage representing the compressed data. - If the GPU doesn't support the specified compression method, the data - will be decompressed and then wrapped in a GPU-backed image. - - Note: one can query the supported compression formats via - GrRecordingContext::compressedBackendFormat. - - @param context GPU context - @param data compressed data to store in SkImage - @param width width of full SkImage - @param height height of full SkImage - @param type type of compression used - @param mipmapped does 'data' contain data for all the mipmap levels? - @param isProtected do the contents of 'data' require DRM protection (on Vulkan)? - @return created SkImage, or nullptr - */ - static sk_sp MakeTextureFromCompressed(GrDirectContext* direct, - sk_sp data, - int width, int height, - CompressionType type, - GrMipmapped mipmapped = GrMipmapped::kNo, - GrProtected isProtected = GrProtected::kNo); - - /** User function called when supplied texture may be deleted. - */ - typedef void (*TextureReleaseProc)(ReleaseContext releaseContext); +enum class BitDepth { + kU8, //!< uses 8-bit unsigned int per color component + kF16, //!< uses 16-bit float per color component +}; - /** Creates SkImage from GPU texture associated with context. GPU texture must stay - valid and unchanged until textureReleaseProc is called. textureReleaseProc is - passed releaseContext when SkImage is deleted or no longer refers to texture. +/** Creates SkImage from picture. Returned SkImage width and height are set by dimensions. + SkImage draws picture with matrix and paint, set to bitDepth and colorSpace. - SkImage is returned if format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. + The Picture data is not turned into an image (CPU or GPU) until it is drawn. - @note When using a DDL recording context, textureReleaseProc will be called on the - GPU thread after the DDL is played back on the direct context. + If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws + with default SkPaint. colorSpace may be nullptr. - @param context GPU context - @param backendTexture texture residing on GPU - @param colorSpace This describes the color space of this image's contents, as - seen after sampling. In general, if the format of the backend - texture is SRGB, some linear colorSpace should be supplied - (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the - backend texture is linear, then the colorSpace should include - a description of the transfer function as - well (e.g., SkColorSpace::MakeSRGB()). - @param textureReleaseProc function called when texture can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin origin, - SkColorType colorType, - SkAlphaType alphaType, + @param picture stream of drawing commands + @param dimensions width and height + @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr + @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr + @param bitDepth 8-bit integer or 16-bit float: per component + @param colorSpace range of colors; may be nullptr + @param props props to use when rasterizing the picture + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromPicture(sk_sp picture, + const SkISize& dimensions, + const SkMatrix* matrix, + const SkPaint* paint, + BitDepth bitDepth, sk_sp colorSpace, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates an SkImage from a GPU backend texture. The backend texture must stay - valid and unchanged until textureReleaseProc is called. The textureReleaseProc is - called when the SkImage is deleted or no longer refers to the texture and will be - passed the releaseContext. - - An SkImage is returned if the format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. - - @note When using a DDL recording context, textureReleaseProc will be called on the - GPU thread after the DDL is played back on the direct context. - - @param context the GPU context - @param backendTexture a texture already allocated by the GPU - @param alphaType This characterizes the nature of the alpha values in the - backend texture. For opaque compressed formats (e.g., ETC1) - this should usually be set to kOpaque_SkAlphaType. - @param colorSpace This describes the color space of this image's contents, as - seen after sampling. In general, if the format of the backend - texture is SRGB, some linear colorSpace should be supplied - (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the - backend texture is linear, then the colorSpace should include - a description of the transfer function as - well (e.g., SkColorSpace::MakeSRGB()). - @param textureReleaseProc function called when the backend texture can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromCompressedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin origin, - SkAlphaType alphaType, - sk_sp colorSpace, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates SkImage from pixmap. SkImage is uploaded to GPU back-end using context. - - Created SkImage is available to other GPU contexts, and is available across thread - boundaries. All contexts must be in the same GPU share group, or otherwise - share resources. - - When SkImage is no longer referenced, context releases texture memory - asynchronously. - - GrBackendTexture created from pixmap is uploaded to match SkSurface created with - dstColorSpace. SkColorSpace of SkImage is determined by pixmap.colorSpace(). - - SkImage is returned referring to GPU back-end if context is not nullptr, - format of data is recognized and supported, and if context supports moving - resources between contexts. Otherwise, pixmap pixel data is copied and SkImage - as returned in raster format if possible; nullptr may be returned. - Recognized GPU formats vary by platform and GPU back-end. - - @param context GPU context - @param pixmap SkImageInfo, pixel address, and row bytes - @param buildMips create SkImage as mip map if true - @param dstColorSpace range of colors of matching SkSurface on GPU - @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary - @return created SkImage, or nullptr - */ - static sk_sp MakeCrossContextFromPixmap(GrDirectContext* context, - const SkPixmap& pixmap, - bool buildMips, - bool limitToMaxTextureSize = false); - - /** Creates SkImage from backendTexture associated with context. backendTexture and - returned SkImage are managed internally, and are released when no longer needed. - - SkImage is returned if format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. - - @param context GPU context - @param backendTexture texture residing on GPU - @param textureOrigin origin of backendTexture - @param colorType color type of the resulting image - @param alphaType alpha type of the resulting image - @param colorSpace range of colors; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType); - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType, - SkAlphaType alphaType); - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace); - - /** Creates an SkImage from YUV[A] planar textures. This requires that the textures stay valid - for the lifetime of the image. The ReleaseContext can be used to know when it is safe to - either delete or overwrite the textures. If ReleaseProc is provided it is also called before - return on failure. - - @param context GPU context - @param yuvaTextures A set of textures containing YUVA data and a description of the - data and transformation to RGBA. - @param imageColorSpace range of colors of the resulting image after conversion to RGB; - may be nullptr - @param textureReleaseProc called when the backend textures can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromYUVATextures(GrRecordingContext* context, - const GrYUVABackendTextures& yuvaTextures, - sk_sp imageColorSpace = nullptr, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates SkImage from SkYUVAPixmaps. - - The image will remain planar with each plane converted to a texture using the passed - GrRecordingContext. - - SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. - The SkColorSpace of the resulting RGB values is specified by imageColorSpace. This will - be the SkColorSpace reported by the image and when drawn the RGB values will be converted - from this space into the destination space (if the destination is tagged). - - Currently, this is only supported using the GPU backend and will fail if context is nullptr. + SkSurfaceProps props); +SK_API sk_sp DeferredFromPicture(sk_sp picture, + const SkISize& dimensions, + const SkMatrix* matrix, + const SkPaint* paint, + BitDepth bitDepth, + sk_sp colorSpace); + +/** Creates a CPU-backed SkImage from pixmap, copying the pixel data. + As a result, pixmap pixels may be modified or deleted without affecting SkImage. + + SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. + + @param pixmap SkImageInfo, pixel address, and row bytes + @return copy of SkPixmap pixels, or nullptr + + example: https://fiddle.skia.org/c/@Image_RasterFromPixmapCopy +*/ +SK_API sk_sp RasterFromPixmapCopy(const SkPixmap& pixmap); + +/** Creates CPU-backed SkImage from pixmap, sharing SkPixmap pixels. Pixels must remain valid and + unchanged until rasterReleaseProc is called. rasterReleaseProc is passed + releaseContext when SkImage is deleted or no longer refers to pixmap pixels. + + Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback + when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc + does not require state. + + SkImage is returned if pixmap is valid. Valid SkPixmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. + + @param pixmap SkImageInfo, pixel address, and row bytes + @param rasterReleaseProc function called when pixels can be released; or nullptr + @param releaseContext state passed to rasterReleaseProc; or nullptr + @return SkImage sharing pixmap +*/ +SK_API sk_sp RasterFromPixmap(const SkPixmap& pixmap, + RasterReleaseProc rasterReleaseProc, + ReleaseContext releaseContext); + +/** Creates CPU-backed SkImage from pixel data described by info. + The pixels data will *not* be copied. + + SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + rowBytes are large enough to hold one row of pixels; + pixels is not nullptr, and contains enough data for SkImage. + + @param info contains width, height, SkAlphaType, SkColorType, SkColorSpace + @param pixels address or pixel storage + @param rowBytes size of pixel row or larger + @return SkImage sharing pixels, or nullptr +*/ +SK_API sk_sp RasterFromData(const SkImageInfo& info, + sk_sp pixels, + size_t rowBytes); - SkYUVAPixmaps does not need to remain valid after this returns. +} // namespace SkImages - @param context GPU context - @param pixmaps The planes as pixmaps with supported SkYUVAInfo that - specifies conversion to RGB. - @param buildMips create internal YUVA textures as mip map if kYes. This is - silently ignored if the context does not support mip maps. - @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary - @param imageColorSpace range of colors of the resulting image; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromYUVAPixmaps(GrRecordingContext* context, - const SkYUVAPixmaps& pixmaps, - GrMipmapped buildMips = GrMipmapped::kNo, - bool limitToMaxTextureSize = false, - sk_sp imageColorSpace = nullptr); - - using PromiseImageTextureContext = void*; - using PromiseImageTextureFulfillProc = - sk_sp (*)(PromiseImageTextureContext); - using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); - - /** Create a new SkImage that is very similar to an SkImage created by MakeFromTexture. The - difference is that the caller need not have created the texture nor populated it with the - image pixel data. Moreover, the SkImage may be created on a thread as the creation of the - image does not require access to the backend API or GrDirectContext. Instead of passing a - GrBackendTexture the client supplies a description of the texture consisting of - GrBackendFormat, width, height, and GrMipmapped state. The resulting SkImage can be drawn - to a SkDeferredDisplayListRecorder or directly to a GPU-backed SkSurface. - - When the actual texture is required to perform a backend API draw, textureFulfillProc will - be called to receive a GrBackendTexture. The properties of the GrBackendTexture must match - those set during the SkImage creation, and it must refer to a valid existing texture in the - backend API context/device, and be populated with the image pixel data. The texture cannot - be deleted until textureReleaseProc is called. - - There is at most one call to each of textureFulfillProc and textureReleaseProc. - textureReleaseProc is always called even if image creation fails or if the - image is never fulfilled (e.g. it is never drawn or all draws are clipped out) - - @param gpuContextProxy the thread-safe proxy of the gpu context. required. - @param backendFormat format of promised gpu texture - @param dimensions width & height of promised gpu texture - @param mipmapped mip mapped state of promised gpu texture - @param origin surface origin of promised gpu texture - @param colorType color type of promised gpu texture - @param alphaType alpha type of promised gpu texture - @param colorSpace range of colors; may be nullptr - @param textureFulfillProc function called to get actual gpu texture - @param textureReleaseProc function called when texture can be deleted - @param textureContext state passed to textureFulfillProc and textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakePromiseTexture(sk_sp gpuContextProxy, - const GrBackendFormat& backendFormat, - SkISize dimensions, - GrMipmapped mipmapped, - GrSurfaceOrigin origin, - SkColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace, - PromiseImageTextureFulfillProc textureFulfillProc, - PromiseImageTextureReleaseProc textureReleaseProc, - PromiseImageTextureContext textureContext); - - /** This entry point operates like 'MakePromiseTexture' but it is used to construct a SkImage - from YUV[A] data. The source data may be planar (i.e. spread across multiple textures). In - the extreme Y, U, V, and A are all in different planes and thus the image is specified by - four textures. 'backendTextureInfo' describes the planar arrangement, texture formats, - conversion to RGB, and origin of the textures. Separate 'textureFulfillProc' and - 'textureReleaseProc' calls are made for each texture. Each texture has its own - PromiseImageTextureContext. If 'backendTextureInfo' is not valid then no release proc - calls are made. Otherwise, the calls will be made even on failure. 'textureContexts' has one - entry for each of the up to four textures, as indicated by 'backendTextureInfo'. - - Currently the mip mapped property of 'backendTextureInfo' is ignored. However, in the - near future it will be required that if it is kYes then textureFulfillProc must return - a mip mapped texture for each plane in order to successfully draw the image. - - @param gpuContextProxy the thread-safe proxy of the gpu context. required. - @param backendTextureInfo info about the promised yuva gpu texture - @param imageColorSpace range of colors; may be nullptr - @param textureFulfillProc function called to get actual gpu texture - @param textureReleaseProc function called when texture can be deleted - @param textureContexts state passed to textureFulfillProc and textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakePromiseYUVATexture(sk_sp gpuContextProxy, - const GrYUVABackendTextureInfo& backendTextureInfo, - sk_sp imageColorSpace, - PromiseImageTextureFulfillProc textureFulfillProc, - PromiseImageTextureReleaseProc textureReleaseProc, - PromiseImageTextureContext textureContexts[]); +/** \class SkImage + SkImage describes a two dimensional array of pixels to draw. The pixels may be + decoded in a raster bitmap, encoded in a SkPicture or compressed data stream, + or located in GPU memory as a GPU texture. -#endif // SK_SUPPORT_GPU + SkImage cannot be modified after it is created. SkImage may allocate additional + storage as needed; for instance, an encoded SkImage may decode when drawn. -#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 - /** (See Skia bug 7447) - Creates SkImage from Android hardware buffer. - Returned SkImage takes a reference on the buffer. + SkImage width and height are greater than zero. Creating an SkImage with zero width + or height returns SkImage equal to nullptr. - Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams, + GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported + include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details + vary with platform. - @param hardwareBuffer AHardwareBuffer Android hardware buffer - @param colorSpace range of colors; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAHardwareBuffer( - AHardwareBuffer* hardwareBuffer, - SkAlphaType alphaType = kPremul_SkAlphaType, - sk_sp colorSpace = nullptr, - GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); - - /** Creates SkImage from Android hardware buffer and uploads the data from the SkPixmap to it. - Returned SkImage takes a reference on the buffer. - - Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. - - @param context GPU context - @param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer - @param hardwareBuffer AHardwareBuffer Android hardware buffer - @param surfaceOrigin surface origin for resulting image - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAHardwareBufferWithData( - GrDirectContext* context, - const SkPixmap& pixmap, - AHardwareBuffer* hardwareBuffer, - GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); -#endif + See SkImages namespace for the static factory methods to make SkImages. + Clients should *not* subclass SkImage as there is a lot of internal machinery that is + not publicly accessible. +*/ +class SK_API SkImage : public SkRefCnt { +public: /** Returns a SkImageInfo describing the width, height, color type, alpha type, and color space of the SkImage. @@ -691,18 +362,12 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, const SkMatrix* localMatrix = nullptr) const; - sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& lm) const { - return this->makeShader(tmx, tmy, sampling, &lm); - } - sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm); - } + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix* lm = nullptr) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm); - } + const SkMatrix* lm = nullptr) const; /** * makeRawShader functions like makeShader, but for images that contain non-color data. @@ -719,20 +384,12 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, const SkMatrix* localMatrix = nullptr) const; - sk_sp makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& lm) const { - return this->makeRawShader(tmx, tmy, sampling, &lm); - } - sk_sp makeRawShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const { - return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm); - } + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeRawShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeRawShader(const SkSamplingOptions& sampling, - const SkMatrix* lm = nullptr) const { - return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm); - } - - using CubicResampler = SkCubicResampler; + const SkMatrix* lm = nullptr) const; /** Copies SkImage pixel address, row bytes, and SkImageInfo to pixmap, if address is available, and returns true. If pixel address is not available, return @@ -752,12 +409,12 @@ class SK_API SkImage : public SkRefCnt { example: https://fiddle.skia.org/c/@Image_isTextureBacked */ - bool isTextureBacked() const; + virtual bool isTextureBacked() const = 0; /** Returns an approximation of the amount of texture memory used by the image. Returns zero if the image is not texture backed or if the texture has an external format. */ - size_t textureSize() const; + virtual size_t textureSize() const = 0; /** Returns true if SkImage can be drawn on either raster surface or GPU surface. If context is nullptr, tests if SkImage draws on raster surface; @@ -772,43 +429,7 @@ class SK_API SkImage : public SkRefCnt { example: https://fiddle.skia.org/c/@Image_isValid */ - bool isValid(GrRecordingContext* context) const; - -#if SK_SUPPORT_GPU - /** Flushes any pending uses of texture-backed images in the GPU backend. If the image is not - texture-backed (including promise texture images) or if the GrDirectContext does not - have the same context ID as the context backing the image then this is a no-op. - - If the image was not used in any non-culled draws in the current queue of work for the - passed GrDirectContext then this is a no-op unless the GrFlushInfo contains semaphores or - a finish proc. Those are respected even when the image has not been used. - - @param context the context on which to flush pending usages of the image. - @param info flush options - */ - GrSemaphoresSubmitted flush(GrDirectContext* context, const GrFlushInfo& flushInfo) const; - - void flush(GrDirectContext* context) const { this->flush(context, {}); } - - /** Version of flush() that uses a default GrFlushInfo. Also submits the flushed work to the - GPU. - */ - void flushAndSubmit(GrDirectContext*) const; - - /** Retrieves the back-end texture. If SkImage has no back-end texture, an invalid - object is returned. Call GrBackendTexture::isValid to determine if the result - is valid. - - If flushPendingGrContextIO is true, completes deferred I/O operations. - - If origin in not nullptr, copies location of content drawn into SkImage. - - @param flushPendingGrContextIO flag to flush outstanding requests - @return back-end API texture handle; invalid on failure - */ - GrBackendTexture getBackendTexture(bool flushPendingGrContextIO, - GrSurfaceOrigin* origin = nullptr) const; -#endif // SK_SUPPORT_GPU + virtual bool isValid(GrRecordingContext* context) const = 0; /** \enum SkImage::CachingHint CachingHint selects whether Skia may internally cache SkBitmap generated by @@ -941,40 +562,11 @@ class SK_API SkImage : public SkRefCnt { enum class RescaleMode { kNearest, + kLinear, kRepeatedLinear, kRepeatedCubic, }; - /** Makes image pixel data available to caller, possibly asynchronously. - - Currently asynchronous reads are only supported on the GPU backend and only when the - underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all - other cases this operates synchronously. - - Data is read from the source sub-rectangle, then converted to the color space, color type, - and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the image - causes failure. - - When the pixel data is ready the caller's ReadPixelsCallback is called with a - AsyncReadResult containing pixel data in the requested color type, alpha type, and color - space. The AsyncReadResult will have count() == 1. Upon failure the callback is called with - nullptr for AsyncReadResult. For a GPU image this flushes work but a submit must occur to - guarantee a finite time before the callback is called. - - The data is valid for the lifetime of AsyncReadResult with the exception that if the SkImage - is GPU-backed the data is immediately invalidated if the context is abandoned or - destroyed. - - @param info info of the requested pixels - @param srcRect subrectangle of image to read - @param callback function to call with result of the read - @param context passed to callback - */ - void asyncReadPixels(const SkImageInfo& info, - const SkIRect& srcRect, - ReadPixelsCallback callback, - ReadPixelsContext context) const; - /** Makes image pixel data available to caller, possibly asynchronously. It can also rescale the image pixels. @@ -1071,44 +663,6 @@ class SK_API SkImage : public SkRefCnt { bool scalePixels(const SkPixmap& dst, const SkSamplingOptions&, CachingHint cachingHint = kAllow_CachingHint) const; - /** Encodes SkImage pixels, returning result as SkData. - - Returns nullptr if encoding fails, or if encodedImageFormat is not supported. - - SkImage encoding in a format requires both building with one or more of: - SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP; and platform support - for the encoded format. - - If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encodedImageFormat can - additionally be one of: SkEncodedImageFormat::kICO, SkEncodedImageFormat::kBMP, - SkEncodedImageFormat::kGIF. - - quality is a platform and format specific metric trading off size and encoding - error. When used, quality equaling 100 encodes with the least error. quality may - be ignored by the encoder. - - @param encodedImageFormat one of: SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kPNG, - SkEncodedImageFormat::kWEBP - @param quality encoder specific metric with 100 equaling best - @return encoded SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_encodeToData - */ - sk_sp encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const; - - /** Encodes SkImage pixels, returning result as SkData. Returns existing encoded data - if present; otherwise, SkImage is encoded with SkEncodedImageFormat::kPNG. Skia - must be built with SK_ENCODE_PNG to encode SkImage. - - Returns nullptr if existing encoded data is missing or invalid, and - encoding fails. - - @return encoded SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_encodeToData_2 - */ - sk_sp encodeToData() const; - /** Returns encoded SkImage pixels as SkData, if SkImage was created from supported encoded stream format. Platform support for formats vary and may require building with one or more of: SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP. @@ -1151,33 +705,79 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp withDefaultMipmaps() const; -#if SK_SUPPORT_GPU - /** Returns SkImage backed by GPU texture associated with context. Returned SkImage is - compatible with SkSurface created with dstColorSpace. The returned SkImage respects - mipmapped setting; if mipmapped equals GrMipmapped::kYes, the backing texture - allocates mip map levels. - - The mipmapped parameter is effectively treated as kNo if MIP maps are not supported by the - GPU. - - Returns original SkImage if the image is already texture-backed, the context matches, and - mipmapped is compatible with the backing GPU texture. SkBudgeted is ignored in this case. - - Returns nullptr if context is nullptr, or if SkImage was created with another - GrDirectContext. +#if defined(SK_GANESH) || defined(SK_GRAPHITE) + using ReleaseContext = SkImages::ReleaseContext; + using TextureReleaseProc = void (*)(ReleaseContext); +#endif - @param GrDirectContext the GrDirectContext in play, if it exists - @param GrMipmapped whether created SkImage texture must allocate mip map levels - @param SkBudgeted whether to count a newly created texture for the returned image - counts against the context's budget. - @return created SkImage, or nullptr +#if defined(SK_GRAPHITE) + // Passed to both fulfill and imageRelease + using GraphitePromiseImageContext = void*; + // Returned from fulfill and passed into textureRelease + using GraphitePromiseTextureReleaseContext = void*; + + using GraphitePromiseImageFulfillProc = + std::tuple + (*)(GraphitePromiseImageContext); + using GraphitePromiseImageReleaseProc = void (*)(GraphitePromiseImageContext); + using GraphitePromiseTextureReleaseProc = void (*)(GraphitePromiseTextureReleaseContext); + + /** Create a new SkImage that is very similar to an SkImage created by + MakeGraphiteFromBackendTexture. The difference is that the caller need not have created the + backend texture nor populated it with data when creating the image. Instead of passing a + BackendTexture to the factory the client supplies a description of the texture consisting + of dimensions, TextureInfo, SkColorInfo and Volatility. + + In general, 'fulfill' must return a BackendTexture that matches the properties + provided at SkImage creation time. The BackendTexture must refer to a valid existing + texture in the backend API context/device, and already be populated with data. + The texture cannot be deleted until 'textureRelease' is called. 'textureRelease' will + be called with the textureReleaseContext returned by 'fulfill'. + + Wrt when and how often the fulfill, imageRelease, and textureRelease callbacks will + be called: + + For non-volatile promise images, 'fulfill' will be called at Context::insertRecording + time. Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' will always be + called only once - when Skia will no longer try calling 'fulfill' to get a backend + texture. If 'fulfill' failed (i.e., it didn't return a valid backend texture) then + 'textureRelease' will never be called. If 'fulfill' was successful then + 'textureRelease' will be called only once when the GPU is done with the contents of the + promise image. This will usually occur during a Context::submit call but it could occur + earlier due to error conditions. 'fulfill' can be called multiple times if the promise + image is used in multiple recordings. If 'fulfill' fails, the insertRecording itself will + fail. Subsequent insertRecording calls (with Recordings that use the promise image) will + keep calling 'fulfill' until it succeeds. + + For volatile promise images, 'fulfill' will be called each time the Recording is inserted + into a Context. Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' + will always be called only once just like the non-volatile case. If 'fulfill' fails at + insertRecording-time, 'textureRelease' will never be called. If 'fulfill' was successful + then a 'textureRelease' matching that 'fulfill' will be called when the GPU is done with + the contents of the promise image. This will usually occur during a Context::submit call + but it could occur earlier due to error conditions. + + @param recorder the recorder that will capture the commands creating the image + @param dimensions width & height of promised gpu texture + @param textureInfo structural information for the promised gpu texture + @param colorInfo color type, alpha type and colorSpace information for the image + @param isVolatile volatility of the promise image + @param fulfill function called to get the actual backend texture + @param imageRelease function called when any image-centric data can be deleted + @param textureRelease function called when the backend texture can be deleted + @param imageContext state passed to fulfill and imageRelease + @return created SkImage, or nullptr */ - sk_sp makeTextureImage(GrDirectContext*, - GrMipmapped = GrMipmapped::kNo, - SkBudgeted = SkBudgeted::kYes) const; -#endif + static sk_sp MakeGraphitePromiseTexture(skgpu::graphite::Recorder*, + SkISize dimensions, + const skgpu::graphite::TextureInfo&, + const SkColorInfo&, + skgpu::graphite::Volatile, + GraphitePromiseImageFulfillProc, + GraphitePromiseImageReleaseProc, + GraphitePromiseTextureReleaseProc, + GraphitePromiseImageContext); -#ifdef SK_GRAPHITE_ENABLED /** Creates an SkImage from a GPU texture associated with the recorder. SkImage is returned if the format of backendTexture is recognized and supported. @@ -1198,12 +798,60 @@ class SK_API SkImage : public SkRefCnt { const skgpu::graphite::BackendTexture&, SkColorType colorType, SkAlphaType alphaType, - sk_sp colorSpace); + sk_sp colorSpace, + TextureReleaseProc = nullptr, + ReleaseContext = nullptr); + + /** Creates an SkImage from YUV[A] planar textures associated with the recorder. + @param recorder The recorder. + @param yuvaBackendTextures A set of textures containing YUVA data and a description of the + data and transformation to RGBA. + @param imageColorSpace range of colors of the resulting image after conversion to RGB; + may be nullptr + @param TextureReleaseProc called when the backend textures can be released + @param ReleaseContext state passed to TextureReleaseProc + @return created SkImage, or nullptr + */ + static sk_sp MakeGraphiteFromYUVABackendTextures( + skgpu::graphite::Recorder* recorder, + const skgpu::graphite::YUVABackendTextures& yuvaBackendTextures, + sk_sp imageColorSpace, + TextureReleaseProc = nullptr, + ReleaseContext = nullptr); struct RequiredImageProperties { - skgpu::graphite::Mipmapped fMipmapped; + skgpu::Mipmapped fMipmapped; }; + /** Creates SkImage from SkYUVAPixmaps. + + The image will remain planar with each plane converted to a texture using the passed + Recorder. + + SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. + The SkColorSpace of the resulting RGB values is specified by imgColorSpace. This will + be the SkColorSpace reported by the image and when drawn the RGB values will be converted + from this space into the destination space (if the destination is tagged). + + This is only supported using the GPU backend and will fail if recorder is nullptr. + + SkYUVAPixmaps does not need to remain valid after this returns. + + @param Recorder The Recorder to use for storing commands + @param pixmaps The planes as pixmaps with supported SkYUVAInfo that + specifies conversion to RGB. + @param RequiredImageProperties Properties the returned SkImage must possess (e.g., + mipmaps) + @param limitToMaxTextureSize Downscale image to GPU maximum texture size, if necessary + @param imgColorSpace Range of colors of the resulting image; may be nullptr + @return Created SkImage, or nullptr + */ + static sk_sp MakeGraphiteFromYUVAPixmaps(skgpu::graphite::Recorder*, + const SkYUVAPixmaps& pixmaps, + RequiredImageProperties = {}, + bool limitToMaxTextureSize = false, + sk_sp imgColorSpace = nullptr); + /** Graphite version of makeTextureImage. Returns an SkImage backed by a Graphite texture, using the provided Recorder for creation @@ -1225,9 +873,70 @@ class SK_API SkImage : public SkRefCnt { mipmaps) @return created SkImage, or nullptr */ - sk_sp makeTextureImage(skgpu::graphite::Recorder*, - RequiredImageProperties = {}) const; -#endif + virtual sk_sp makeTextureImage(skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const = 0; + + /** Returns subset of this image. + + Returns nullptr if any of the following are true: + - Subset is empty + - Subset is not contained inside the image's bounds + - Pixels in the image could not be read or copied + + If this image is texture-backed, the recorder parameter is required. + If the recorder parameter is provided, and the image is raster-backed, the subset will + be converted to texture-backed. + + @param subset bounds of returned SkImage + @param recorder the recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return the subsetted image, or nullptr + */ + sk_sp makeSubset(const SkIRect& subset, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + + /** Creates SkImage in target SkColorSpace. + Returns nullptr if SkImage could not be created. + + Returns original SkImage if it is in target SkColorSpace. + Otherwise, converts pixels from SkImage SkColorSpace to target SkColorSpace. + If SkImage colorSpace() returns nullptr, SkImage SkColorSpace is assumed to be sRGB. + + If this image is graphite-backed, the recorder parameter is required. + + @param targetColorSpace SkColorSpace describing color range of returned SkImage + @param recorder The Recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return created SkImage in target SkColorSpace + */ + sk_sp makeColorSpace(sk_sp targetColorSpace, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + + /** Experimental. + Creates SkImage in target SkColorType and SkColorSpace. + Returns nullptr if SkImage could not be created. + + Returns original SkImage if it is in target SkColorType and SkColorSpace. + + If this image is graphite-backed, the recorder parameter is required. + + @param targetColorType SkColorType of returned SkImage + @param targetColorSpace SkColorSpace of returned SkImage + @param recorder The Recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return created SkImage in target SkColorType and SkColorSpace + */ + sk_sp makeColorTypeAndColorSpace(SkColorType targetColorType, + sk_sp targetColorSpace, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + +#endif // SK_GRAPHITE /** Returns raster image or lazy image. Copies SkImage backed by GPU texture into CPU memory if needed. Returns original SkImage if decoded in raster bitmap, @@ -1285,38 +994,6 @@ class SK_API SkImage : public SkRefCnt { const SkIRect& clipBounds, SkIRect* outSubset, SkIPoint* offset) const; - /** Defines a callback function, taking one parameter of type GrBackendTexture with - no return value. Function is called when back-end texture is to be released. - */ - typedef std::function BackendTextureReleaseProc; - -#if SK_SUPPORT_GPU - /** Creates a GrBackendTexture from the provided SkImage. Returns true and - stores result in backendTexture and backendTextureReleaseProc if - texture is created; otherwise, returns false and leaves - backendTexture and backendTextureReleaseProc unmodified. - - Call backendTextureReleaseProc after deleting backendTexture. - backendTextureReleaseProc cleans up auxiliary data related to returned - backendTexture. The caller must delete returned backendTexture after use. - - If SkImage is both texture backed and singly referenced, image is returned in - backendTexture without conversion or making a copy. SkImage is singly referenced - if its was transferred solely using std::move(). - - If SkImage is not texture backed, returns texture with SkImage contents. - - @param context GPU context - @param image SkImage used for texture - @param backendTexture storage for back-end texture - @param backendTextureReleaseProc storage for clean up function - @return true if back-end texture was created - */ - static bool MakeBackendTextureFromSkImage(GrDirectContext* context, - sk_sp image, - GrBackendTexture* backendTexture, - BackendTextureReleaseProc* backendTextureReleaseProc); -#endif /** Deprecated. */ enum LegacyBitmapMode { @@ -1393,7 +1070,8 @@ class SK_API SkImage : public SkRefCnt { SkImage(const SkImageInfo& info, uint32_t uniqueID); friend class SkBitmap; - friend class SkImage_Base; + friend class SkImage_Base; // for private ctor + friend class SkImage_Raster; // for withMipmaps friend class SkMipmapBuilder; SkImageInfo fInfo; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h deleted file mode 100644 index be0183c094cba..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkImageEncoder_DEFINED -#define SkImageEncoder_DEFINED - -#include "include/core/SkEncodedImageFormat.h" -#include "include/core/SkRefCnt.h" -#include "include/core/SkTypes.h" - -class SkBitmap; -class SkData; -class SkPixmap; -class SkWStream; - -/** - * Encode SkPixmap in the given binary image format. - * - * @param dst results are written to this stream. - * @param src source pixels. - * @param format image format, not all formats are supported. - * @param quality range from 0-100, this is supported by jpeg and webp. - * higher values correspond to improved visual quality, but less compression. - * - * @return false iff input is bad or format is unsupported. - * - * Will always return false if Skia is compiled without image - * encoders. - * - * For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise - * it will use lossy. - * - * For examples of encoding an image to a file or to a block of memory, - * see tools/ToolUtils.h. - */ -SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src, - SkEncodedImageFormat format, int quality); - -/** - * The following helper function wraps SkEncodeImage(). - */ -SK_API bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q); - -/** - * Encode SkPixmap in the given binary image format. - * - * @param src source pixels. - * @param format image format, not all formats are supported. - * @param quality range from 0-100, this is supported by jpeg and webp. - * higher values correspond to improved visual quality, but less compression. - * - * @return encoded data or nullptr if input is bad or format is unsupported. - * - * Will always return nullptr if Skia is compiled without image - * encoders. - * - * For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise - * it will use lossy. - */ -SK_API sk_sp SkEncodePixmap(const SkPixmap& src, SkEncodedImageFormat format, int quality); - -/** - * Helper that extracts the pixmap from the bitmap, and then calls SkEncodePixmap() - */ -SK_API sk_sp SkEncodeBitmap(const SkBitmap& src, SkEncodedImageFormat format, int quality); - -#endif // SkImageEncoder_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h index 42125214e7167..ba9ae09833066 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h @@ -8,32 +8,25 @@ #ifndef SkImageGenerator_DEFINED #define SkImageGenerator_DEFINED -#include "include/core/SkBitmap.h" -#include "include/core/SkColor.h" -#include "include/core/SkImage.h" +#include "include/core/SkData.h" #include "include/core/SkImageInfo.h" -#include "include/core/SkSurfaceProps.h" +#include "include/core/SkPixmap.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkYUVAPixmaps.h" +#include "include/private/base/SkAPI.h" +#if defined(SK_GRAPHITE) +#include "include/core/SkImage.h" +#include "include/gpu/graphite/Recorder.h" +#endif + +#include +#include +#include #include class GrRecordingContext; -class GrSurfaceProxyView; -class GrSamplerState; -class SkBitmap; -class SkData; -class SkMatrix; -class SkPaint; -class SkPicture; - -enum class GrImageTexGenPolicy : int; - -#if SK_GRAPHITE_ENABLED -namespace skgpu::graphite { -enum class Mipmapped : bool; -class Recorder; -} -#endif +enum SkAlphaType : int; class SK_API SkImageGenerator { public: @@ -121,36 +114,12 @@ class SK_API SkImageGenerator { */ bool getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps); -#if SK_SUPPORT_GPU - /** - * If the generator can natively/efficiently return its pixels as a GPU image (backed by a - * texture) this will return that image. If not, this will return NULL. - * - * Regarding the GrRecordingContext parameter: - * - * It must be non-NULL. The generator should only succeed if: - * - its internal context is the same - * - it can somehow convert its texture into one that is valid for the provided context. - * - * If the mipmapped parameter is kYes, the generator should try to create a TextureProxy that - * at least has the mip levels allocated and the base layer filled in. If this is not possible, - * the generator is allowed to return a non mipped proxy, but this will have some additional - * overhead in later allocating mips and copying of the base layer. - * - * GrImageTexGenPolicy determines whether or not a new texture must be created (and its budget - * status) or whether this may (but is not required to) return a pre-existing texture that is - * retained by the generator (kDraw). - */ - GrSurfaceProxyView generateTexture(GrRecordingContext*, - const SkImageInfo& info, - GrMipmapped mipmapped, - GrImageTexGenPolicy); -#endif + virtual bool isTextureGenerator() const { return false; } -#if SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) sk_sp makeTextureImage(skgpu::graphite::Recorder*, const SkImageInfo&, - skgpu::graphite::Mipmapped); + skgpu::Mipmapped); #endif /** @@ -164,17 +133,6 @@ class SK_API SkImageGenerator { static std::unique_ptr MakeFromEncoded( sk_sp, std::optional = std::nullopt); - /** Return a new image generator backed by the specified picture. If the size is empty or - * the picture is NULL, this returns NULL. - * The optional matrix and paint arguments are passed to drawPicture() at rasterization - * time. - */ - static std::unique_ptr MakeFromPicture(const SkISize&, sk_sp, - const SkMatrix*, const SkPaint*, - SkImage::BitDepth, - sk_sp, - SkSurfaceProps props = {}); - protected: static constexpr int kNeedNewImageUniqueID = 0; @@ -187,30 +145,17 @@ class SK_API SkImageGenerator { virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes&, SkYUVAPixmapInfo*) const { return false; } virtual bool onGetYUVAPlanes(const SkYUVAPixmaps&) { return false; } -#if SK_SUPPORT_GPU - // returns nullptr - virtual GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&, - GrMipmapped, GrImageTexGenPolicy); - - // Most internal SkImageGenerators produce textures and views that use kTopLeft_GrSurfaceOrigin. - // If the generator may produce textures with different origins (e.g. - // GrAHardwareBufferImageGenerator) it should override this function to return the correct - // origin. - virtual GrSurfaceOrigin origin() const { return kTopLeft_GrSurfaceOrigin; } -#endif -#if SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) virtual sk_sp onMakeTextureImage(skgpu::graphite::Recorder*, const SkImageInfo&, - skgpu::graphite::Mipmapped); + skgpu::Mipmapped); #endif + const SkImageInfo fInfo; private: - const SkImageInfo fInfo; const uint32_t fUniqueID; - friend class SkImage_Lazy; - // This is our default impl, which may be different on different platforms. // It is called from NewFromEncoded() after it has checked for any runtime factory. // The SkData will never be NULL, as that will have been checked by NewFromEncoded. diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h index 9befe3071fb2b..b5661719006ef 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h @@ -10,16 +10,18 @@ #include "include/core/SkAlphaType.h" #include "include/core/SkColorType.h" -#include "include/core/SkMath.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkTFitsIn.h" -#include "include/private/SkTFitsIn.h" -#include "include/private/SkTo.h" +#include +#include +#include -class SkReadBuffer; -class SkWriteBuffer; class SkColorSpace; /** Returns the number of bytes required to store a pixel, including unused padding. diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h index 7fdbcb8e820d3..11a06a15b1a6d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h @@ -99,6 +99,11 @@ struct SK_API SkV4 { } bool operator!=(const SkV4& v) const { return !(*this == v); } + static SkScalar Dot(const SkV4& a, const SkV4& b) { + return a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; + } + static SkV4 Normalize(const SkV4& v) { return v * (1.0f / v.length()); } + SkV4 operator-() const { return {-x, -y, -z, -w}; } SkV4 operator+(const SkV4& v) const { return { x + v.x, y + v.y, z + v.z, w + v.w }; } SkV4 operator-(const SkV4& v) const { return { x - v.x, y - v.y, z - v.z, w - v.w }; } @@ -111,6 +116,12 @@ struct SK_API SkV4 { } friend SkV4 operator*(SkScalar s, const SkV4& v) { return v*s; } + SkScalar lengthSquared() const { return Dot(*this, *this); } + SkScalar length() const { return SkScalarSqrt(Dot(*this, *this)); } + + SkScalar dot(const SkV4& v) const { return Dot(*this, v); } + SkV4 normalize() const { return Normalize(*this); } + const float* ptr() const { return &x; } float* ptr() { return &x; } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h index 3fde51b717e53..9d03e98c0c5f8 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h @@ -8,12 +8,15 @@ #ifndef SkMaskFilter_DEFINED #define SkMaskFilter_DEFINED -#include "include/core/SkBlurTypes.h" -#include "include/core/SkCoverageMode.h" #include "include/core/SkFlattenable.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" -class SkMatrix; +#include + +enum SkBlurStyle : int; +struct SkDeserialProcs; struct SkRect; /** \class SkMaskFilter diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h index 03140760d6f2b..cf84d26228b60 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h @@ -8,12 +8,19 @@ #ifndef SkMatrix_DEFINED #define SkMatrix_DEFINED +#include "include/core/SkPoint.h" #include "include/core/SkRect.h" -#include "include/private/SkMacros.h" -#include "include/private/SkTo.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkMacros.h" +#include "include/private/base/SkTo.h" + +#include +#include -struct SkRSXform; struct SkPoint3; +struct SkRSXform; +struct SkSize; // Remove when clients are updated to live without this #define SK_SUPPORT_LEGACY_MATRIX_RECTTORECT @@ -1812,7 +1819,10 @@ class SK_API SkMatrix { if (tx != 0.0f || ty != 0.0f) { mask |= kTranslate_Mask; } - this->setTypeMask(mask | kRectStaysRect_Mask); + if (sx != 0 && sy != 0) { + mask |= kRectStaysRect_Mask; + } + this->setTypeMask(mask); } /** Returns true if all elements of the matrix are finite. Returns false if any diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h index f34672e3ab05e..360a039e7f531 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h @@ -19,6 +19,7 @@ #include "include/effects/SkRuntimeEffect.h" #include +#include #include class GrDirectContext; @@ -29,22 +30,31 @@ namespace SkSL { struct Program; } /** * A specification for custom meshes. Specifies the vertex buffer attributes and stride, the - * vertex program that produces a user-defined set of varyings, a fragment program that ingests - * the interpolated varyings and produces local coordinates and optionally a color. + * vertex program that produces a user-defined set of varyings, and a fragment program that ingests + * the interpolated varyings and produces local coordinates for shading and optionally a color. + * + * The varyings must include a float2 named "position". If the passed varyings does not + * contain such a varying then one is implicitly added to the final specification and the SkSL + * Varyings struct described below. It is an error to have a varying named "position" that has a + * type other than float2. + * + * The provided attributes and varyings are used to create Attributes and Varyings structs in SkSL + * that are used by the shaders. Each attribute from the Attribute span becomes a member of the + * SkSL Attributes struct and likewise for the varyings. * * The signature of the vertex program must be: - * float2 main(Attributes, out Varyings) - * where the return value is a local position that will be transformed by SkCanvas's matrix. + * Varyings main(const Attributes). * * The signature of the fragment program must be either: - * (float2|void) main(Varyings) + * float2 main(const Varyings) * or - * (float2|void) main(Varyings, out (half4|float4) color) + * float2 main(const Varyings, out (half4|float4) color) * * where the return value is the local coordinates that will be used to access SkShader. If the - * return type is void then the interpolated position from vertex shader return is used as the local - * coordinate. If the color variant is used it will be blended with SkShader (or SkPaint color in - * absence of a shader) using the SkBlender provided to the SkCanvas draw call. + * color variant is used, the returned color will be blended with SkPaint's SkShader (or SkPaint + * color in absence of a SkShader) using the SkBlender passed to SkCanvas drawMesh(). To use + * interpolated local space positions as the shader coordinates, equivalent to how SkPaths are + * shaded, return the position field from the Varying struct as the coordinates. * * The vertex and fragment programs may both contain uniforms. Uniforms with the same name are * assumed to be shared between stages. It is an error to specify uniforms in the vertex and @@ -187,11 +197,12 @@ class SkMeshSpecification : public SkNVRefCnt { SkMeshSpecification(SkSpan, size_t, SkSpan, + int passthroughLocalCoordsVaryingIndex, + uint32_t deadVaryingMask, std::vector uniforms, std::unique_ptr, std::unique_ptr, ColorType, - bool hasLocalCoords, sk_sp, SkAlphaType); @@ -208,8 +219,9 @@ class SkMeshSpecification : public SkNVRefCnt { const std::unique_ptr fFS; const size_t fStride; uint32_t fHash; + const int fPassthroughLocalCoordsVaryingIndex; + const uint32_t fDeadVaryingMask; const ColorType fColorType; - const bool fHasLocalCoords; const sk_sp fColorSpace; const SkAlphaType fAlphaType; }; @@ -295,8 +307,11 @@ class SkMesh { */ static sk_sp MakeIndexBuffer(GrDirectContext*, const void* data, size_t size); - /** Deprecated in favor of const void* and size_t version above. */ - static sk_sp MakeIndexBuffer(GrDirectContext*, sk_sp); + /** + * Makes a copy of an index buffer. The implementation currently only supports a CPU-backed + * source buffer. + */ + static sk_sp CopyIndexBuffer(GrDirectContext*, sk_sp); /** * Makes a vertex buffer to be used with SkMeshes. The buffer may be CPU- or GPU-backed @@ -313,12 +328,23 @@ class SkMesh { */ static sk_sp MakeVertexBuffer(GrDirectContext*, const void*, size_t size); - /** Deprecated in favor of const void* and size_t version above. */ - static sk_sp MakeVertexBuffer(GrDirectContext*, sk_sp); + /** + * Makes a copy of a vertex buffer. The implementation currently only supports a CPU-backed + * source buffer. + */ + static sk_sp CopyVertexBuffer(GrDirectContext*, sk_sp); enum class Mode { kTriangles, kTriangleStrip }; - static SkMesh Make(sk_sp, + struct Result; + + /** + * Creates a non-indexed SkMesh. The returned SkMesh can be tested for validity using + * SkMesh::isValid(). An invalid mesh simply fails to draws if passed to SkCanvas::drawMesh(). + * If the mesh is invalid the returned string give contain the reason for the failure (e.g. the + * vertex buffer was null or uniform data too small). + */ + static Result Make(sk_sp, Mode, sk_sp, size_t vertexCount, @@ -326,7 +352,13 @@ class SkMesh { sk_sp uniforms, const SkRect& bounds); - static SkMesh MakeIndexed(sk_sp, + /** + * Creates an indexed SkMesh. The returned SkMesh can be tested for validity using + * SkMesh::isValid(). A invalid mesh simply fails to draw if passed to SkCanvas::drawMesh(). + * If the mesh is invalid the returned string give contain the reason for the failure (e.g. the + * index buffer was null or uniform data too small). + */ + static Result MakeIndexed(sk_sp, Mode, sk_sp, size_t vertexCount, @@ -364,7 +396,7 @@ class SkMesh { private: friend struct SkMeshPriv; - bool validate() const; + std::tuple validate() const; sk_sp fSpec; @@ -384,6 +416,8 @@ class SkMesh { SkRect fBounds = SkRect::MakeEmpty(); }; +struct SkMesh::Result { SkMesh mesh; SkString error; }; + #endif // SK_ENABLE_SKSL #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h index a6c6bdf195e1f..398de57d0c59f 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h @@ -5,5 +5,5 @@ * found in the LICENSE file. */ #ifndef SK_MILESTONE -#define SK_MILESTONE 108 +#define SK_MILESTONE 114 #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h index d6c1d830c7ed3..157dbb59d8d6c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h @@ -8,23 +8,28 @@ #ifndef SkPaint_DEFINED #define SkPaint_DEFINED -#include "include/core/SkBlendMode.h" #include "include/core/SkColor.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTo.h" - +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkFloatingPoint.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" + +#include #include +#include class SkBlender; class SkColorFilter; class SkColorSpace; -struct SkRect; class SkImageFilter; class SkMaskFilter; -class SkMatrix; -class SkPath; class SkPathEffect; class SkShader; +enum class SkBlendMode; +struct SkRect; /** \class SkPaint SkPaint controls options applied when drawing. SkPaint collects all @@ -383,34 +388,6 @@ class SK_API SkPaint { */ void setStrokeJoin(Join join); - /** Returns the filled equivalent of the stroked path. - - @param src SkPath read to create a filled version - @param dst resulting SkPath; may be the same as src, but may not be nullptr - @param cullRect optional limit passed to SkPathEffect - @param resScale if > 1, increase precision, else if (0 < resScale < 1) reduce precision - to favor speed and size - @return true if the path represents style fill, or false if it represents hairline - */ - bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect, - SkScalar resScale = 1) const; - - bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect, - const SkMatrix& ctm) const; - - /** Returns the filled equivalent of the stroked path. - - Replaces dst with the src path modified by SkPathEffect and style stroke. - SkPathEffect, if any, is not culled. stroke width is created with default precision. - - @param src SkPath read to create a filled version - @param dst resulting SkPath dst may be the same as src, but may not be nullptr - @return true if the path represents style fill, or false if it represents hairline - */ - bool getFillPath(const SkPath& src, SkPath* dst) const { - return this->getFillPath(src, dst, nullptr, 1); - } - /** Returns optional colors used when filling a path, such as a gradient. Does not alter SkShader SkRefCnt. diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h index fea6932e04035..0b69dd2b6fd95 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h @@ -10,20 +10,29 @@ #include "include/core/SkMatrix.h" #include "include/core/SkPathTypes.h" +#include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTo.h" - +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" + +#include +#include +#include #include #include +#include -class SkAutoPathBoundsUpdate; class SkData; class SkPathRef; class SkRRect; class SkWStream; - enum class SkPathConvexity; enum class SkPathFirstDirection; +struct SkPathVerbAnalysis; // WIP -- define this locally, and fix call-sites to use SkPathBuilder (skbug.com/9000) //#define SK_HIDE_PATH_EDIT_METHODS @@ -1866,6 +1875,16 @@ class SK_API SkPath { */ void shrinkToFit(); + // Creates a new Path after the supplied arguments have been validated by + // sk_path_analyze_verbs(). + static SkPath MakeInternal(const SkPathVerbAnalysis& analsis, + const SkPoint points[], + const uint8_t verbs[], + int verbCount, + const SkScalar conics[], + SkPathFillType fillType, + bool isVolatile); + friend class SkAutoPathBoundsUpdate; friend class SkAutoDisableOvalCheck; friend class SkAutoDisableDirectionCheck; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h index b52eaaaa96b0b..247c08624c554 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h @@ -8,11 +8,19 @@ #ifndef SkPathBuilder_DEFINED #define SkPathBuilder_DEFINED -#include "include/core/SkMatrix.h" #include "include/core/SkPath.h" #include "include/core/SkPathTypes.h" +#include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTDArray.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/SkPathRef.h" +#include "include/private/base/SkTo.h" + +#include + +class SkRRect; class SK_API SkPathBuilder { public: @@ -220,9 +228,9 @@ class SK_API SkPathBuilder { } private: - SkTDArray fPts; - SkTDArray fVerbs; - SkTDArray fConicWeights; + SkPathRef::PointsArray fPts; + SkPathRef::VerbsArray fVerbs; + SkPathRef::ConicWeightsArray fConicWeights; SkPathFillType fFillType; bool fIsVolatile; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h index 2335c7c23ce13..167b18278d923 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h @@ -10,7 +10,7 @@ #include "include/core/SkContourMeasure.h" #include "include/core/SkPath.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" class SK_API SkPathMeasure { public: diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h index f589ea46ce2e3..963a6bda00b00 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h @@ -8,8 +8,6 @@ #ifndef SkPathTypes_DEFINED #define SkPathTypes_DEFINED -#include "include/core/SkTypes.h" - enum class SkPathFillType { /** Specifies that "inside" is computed by a non-zero sum of signed edge crossings */ kWinding, diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h new file mode 100644 index 0000000000000..6285da7996033 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h @@ -0,0 +1,42 @@ +/* + * 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 SkPathUtils_DEFINED +#define SkPathUtils_DEFINED + +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" + +class SkMatrix; +class SkPaint; +class SkPath; +struct SkRect; + +namespace skpathutils { + +/** Returns the filled equivalent of the stroked path. + + @param src SkPath read to create a filled version + @param paint SkPaint, from which attributes such as stroke cap, width, miter, and join, + as well as pathEffect will be used. + @param dst resulting SkPath; may be the same as src, but may not be nullptr + @param cullRect optional limit passed to SkPathEffect + @param resScale if > 1, increase precision, else if (0 < resScale < 1) reduce precision + to favor speed and size + @return true if the dst path was updated, false if it was not (e.g. if the path + represents hairline and cannot be filled). +*/ +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, + const SkRect *cullRect, SkScalar resScale = 1); + +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, + const SkRect *cullRect, const SkMatrix &ctm); + +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst); + +} + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h index b6422dd56e3ee..bb384dfab1b8c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h @@ -243,8 +243,9 @@ class SK_API SkPicture : public SkRefCnt { void serialize(SkWStream*, const SkSerialProcs*, class SkRefCntSet* typefaces, bool textBlobsOnly=false) const; - static sk_sp MakeFromStream(SkStream*, const SkDeserialProcs*, - class SkTypefacePlayback*); + static sk_sp MakeFromStreamPriv(SkStream*, const SkDeserialProcs*, + class SkTypefacePlayback*, + int recursionLimit); friend class SkPictureData; /** Return true if the SkStream/Buffer represents a serialized picture, and diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h index af3926dd25f0f..d91d105000ef0 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h @@ -12,6 +12,8 @@ #include "include/core/SkPicture.h" #include "include/core/SkRefCnt.h" +#include + #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK namespace android { class Picture; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h index ce25665b01a6a..12779890f8859 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h @@ -8,20 +8,16 @@ #ifndef SkPixelRef_DEFINED #define SkPixelRef_DEFINED -#include "include/core/SkBitmap.h" -#include "include/core/SkImageInfo.h" -#include "include/core/SkPixmap.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/private/SkIDChangeListener.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkTo.h" #include +#include +#include -struct SkIRect; - -class GrTexture; class SkDiscardableMemory; /** \class SkPixelRef diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h index 7bc2aa05ac73e..ad4c7dd6d8464 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h @@ -9,11 +9,21 @@ #define SkPixmap_DEFINED #include "include/core/SkColor.h" +#include "include/core/SkColorType.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkRect.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkSamplingOptions.h" +#include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" + +#include +#include class SkColorSpace; -class SkData; +enum SkAlphaType : int; struct SkMask; /** \class SkPixmap @@ -702,39 +712,21 @@ class SK_API SkPixmap { */ bool erase(SkColor color) const { return this->erase(color, this->bounds()); } - /** Writes color to pixels bounded by subset; returns true on success. - if subset is nullptr, writes colors pixels inside bounds(). Returns false if - colorType() is kUnknown_SkColorType, if subset is not nullptr and does - not intersect bounds(), or if subset is nullptr and bounds() is empty. - - @param color sRGB unpremultiplied color to write - @param subset bounding integer SkRect of pixels to write; may be nullptr - @return true if pixels are changed - - example: https://fiddle.skia.org/c/@Pixmap_erase_3 - */ - bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const { - return this->erase(color, nullptr, subset); - } - /** Writes color to pixels bounded by subset; returns true on success. if subset is nullptr, writes colors pixels inside bounds(). Returns false if colorType() is kUnknown_SkColorType, if subset is not nullptr and does not intersect bounds(), or if subset is nullptr and bounds() is empty. @param color unpremultiplied color to write - @param cs SkColorSpace of color @param subset bounding integer SkRect of pixels to write; may be nullptr @return true if pixels are changed */ - bool erase(const SkColor4f& color, SkColorSpace* cs, const SkIRect* subset = nullptr) const; + bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const; private: const void* fPixels; size_t fRowBytes; SkImageInfo fInfo; - - friend class SkPixmapPriv; }; #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h index 92cb0b7f09994..a5e7fa09fbab5 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h @@ -8,9 +8,11 @@ #ifndef SkPoint_DEFINED #define SkPoint_DEFINED -#include "include/core/SkMath.h" #include "include/core/SkScalar.h" -#include "include/private/SkSafe32.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkSafe32.h" + +#include struct SkIPoint; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h index 05434c0942517..0bd4034fdcda6 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h @@ -10,7 +10,7 @@ #include "include/core/SkTypes.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/core/SkRefCnt.h" #include "include/gpu/GrBackendSurface.h" /** @@ -41,6 +41,6 @@ class SK_API SkPromiseImageTexture : public SkNVRefCnt { GrBackendTexture fBackendTexture; }; -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) #endif // SkPromiseImageTexture_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h index 099385168ff73..73bc4a95b99ec 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h @@ -10,8 +10,12 @@ #include "include/core/SkPoint.h" #include "include/core/SkRect.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" + +#include +#include -class SkPath; class SkMatrix; class SkString; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h index 9467a331c3e19..1ed7823c23773 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h @@ -9,12 +9,15 @@ #define SkRect_DEFINED #include "include/core/SkPoint.h" +#include "include/core/SkScalar.h" #include "include/core/SkSize.h" -#include "include/private/SkSafe32.h" -#include "include/private/SkTFitsIn.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkSafe32.h" +#include "include/private/base/SkTFitsIn.h" +#include #include -#include +#include struct SkRect; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h index fc687b3840171..668de14e1d1af 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h @@ -9,14 +9,14 @@ #define SkRefCnt_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkDebug.h" -#include // std::atomic, std::memory_order_* -#include // std::nullptr_t -#include // std::basic_ostream -#include // TODO: unused -#include // std::enable_if, std::is_convertible -#include // std::forward, std::swap +#include +#include +#include +#include +#include +#include /** \class SkRefCntBase @@ -174,7 +174,7 @@ class SkNVRefCnt { bool unique() const { return 1 == fRefCnt.load(std::memory_order_acquire); } void ref() const { (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed); } - void unref() const { + void unref() const { if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) { // restore the 1 for our destructor's assert SkDEBUGCODE(fRefCnt.store(1, std::memory_order_relaxed)); @@ -217,12 +217,7 @@ class SkNVRefCnt { * may be considered as trivially relocatable by the compiler so that destroying-move operations * i.e. move constructor followed by destructor can be optimized to memcpy. */ -#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::trivial_abi) -#define SK_SP_TRIVIAL_ABI [[clang::trivial_abi]] -#else -#define SK_SP_TRIVIAL_ABI -#endif -template class SK_SP_TRIVIAL_ABI sk_sp { +template class SK_TRIVIAL_ABI sk_sp { public: using element_type = T; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h index 463a39ff36d54..6f8aa25d54282 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h @@ -9,7 +9,7 @@ #define SkRegion_DEFINED #include "include/core/SkRect.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTypeTraits.h" class SkPath; class SkRgnBuilder; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h index 2a6bb3ec361ef..f3e11b34c2504 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h @@ -8,10 +8,8 @@ #ifndef SkScalar_DEFINED #define SkScalar_DEFINED -#include "include/private/SkFloatingPoint.h" - -#undef SK_SCALAR_IS_FLOAT -#define SK_SCALAR_IS_FLOAT 1 +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkFloatingPoint.h" typedef float SkScalar; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h index 87e10d847ce6c..a9a0386370cd9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h @@ -8,9 +8,15 @@ #ifndef SkSerialProcs_DEFINED #define SkSerialProcs_DEFINED -#include "include/core/SkImage.h" -#include "include/core/SkPicture.h" -#include "include/core/SkTypeface.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" + +#include + +class SkData; +class SkImage; +class SkPicture; +class SkTypeface; /** * A serial-proc is asked to serialize the specified object (e.g. picture or image). @@ -22,30 +28,32 @@ * The default action for typefaces is to use Skia's internal format. */ -typedef sk_sp (*SkSerialPictureProc)(SkPicture*, void* ctx); -typedef sk_sp (*SkSerialImageProc)(SkImage*, void* ctx); -typedef sk_sp (*SkSerialTypefaceProc)(SkTypeface*, void* ctx); +using SkSerialPictureProc = sk_sp (*)(SkPicture*, void* ctx); +using SkSerialImageProc = sk_sp (*)(SkImage*, void* ctx); +using SkSerialTypefaceProc = sk_sp (*)(SkTypeface*, void* ctx); /** * Called with the encoded form of a picture (previously written with a custom * SkSerialPictureProc proc). Return a picture object, or nullptr indicating failure. */ -typedef sk_sp (*SkDeserialPictureProc)(const void* data, size_t length, void* ctx); +using SkDeserialPictureProc = sk_sp (*)(const void* data, size_t length, void* ctx); /** - * Called with the encoded from of an image. The proc can return an image object, or if it + * Called with the encoded form of an image. The proc can return an image object, or if it * returns nullptr, then Skia will take its default action to try to create an image from the data. * + * This will also be used to decode the internal mipmap layers that are saved on some images. + * * Note that unlike SkDeserialPictureProc and SkDeserialTypefaceProc, return nullptr from this * does not indicate failure, but is a signal for Skia to take its default action. */ -typedef sk_sp (*SkDeserialImageProc)(const void* data, size_t length, void* ctx); +using SkDeserialImageProc = sk_sp (*)(const void* data, size_t length, void* ctx); /** * Called with the encoded form of a typeface (previously written with a custom * SkSerialTypefaceProc proc). Return a typeface object, or nullptr indicating failure. */ -typedef sk_sp (*SkDeserialTypefaceProc)(const void* data, size_t length, void* ctx); +using SkDeserialTypefaceProc = sk_sp (*)(const void* data, size_t length, void* ctx); struct SK_API SkSerialProcs { SkSerialPictureProc fPictureProc = nullptr; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h index 1c05c6238cb59..be42a87b9a9c6 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h @@ -56,69 +56,6 @@ class SK_API SkShader : public SkFlattenable { return this->isAImage(nullptr, (SkTileMode*)nullptr) != nullptr; } - // TODO(skbug.com/8941): Have Android use SkAndroidFrameworkUtils, move types to SkShaderBase, - // and delete asAGradient(). -#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK -private: -#endif - - /** - * If the shader subclass can be represented as a gradient, asAGradient - * returns the matching GradientType enum (or kNone_GradientType if it - * cannot). Also, if info is not null, asAGradient populates info with - * the relevant (see below) parameters for the gradient. fColorCount - * is both an input and output parameter. On input, it indicates how - * many entries in fColors and fColorOffsets can be used, if they are - * non-NULL. After asAGradient has run, fColorCount indicates how - * many color-offset pairs there are in the gradient. If there is - * insufficient space to store all of the color-offset pairs, fColors - * and fColorOffsets will not be altered. fColorOffsets specifies - * where on the range of 0 to 1 to transition to the given color. - * The meaning of fPoint and fRadius is dependant on the type of gradient. - * - * None: - * info is ignored. - * Color: - * fColorOffsets[0] is meaningless. - * Linear: - * fPoint[0] and fPoint[1] are the end-points of the gradient - * Radial: - * fPoint[0] and fRadius[0] are the center and radius - * Conical: - * fPoint[0] and fRadius[0] are the center and radius of the 1st circle - * fPoint[1] and fRadius[1] are the center and radius of the 2nd circle - * Sweep: - * fPoint[0] is the center of the sweep. - */ - - enum GradientType { - kNone_GradientType, - kColor_GradientType, - kLinear_GradientType, - kRadial_GradientType, - kSweep_GradientType, - kConical_GradientType, - }; - - struct GradientInfo { - int fColorCount = 0; //!< In-out parameter, specifies passed size - // of fColors/fColorOffsets on input, and - // actual number of colors/offsets on - // output. - SkColor* fColors = nullptr; //!< The colors in the gradient. - SkScalar* fColorOffsets = nullptr; //!< The unit offset for color transitions. - SkPoint fPoint[2]; //!< Type specific, see above. - SkScalar fRadius[2]; //!< Type specific, see above. - SkTileMode fTileMode; - uint32_t fGradientFlags = 0; //!< see SkGradientShader::Flags - }; - - GradientType asAGradient(GradientInfo* info) const; - -#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK -public: -#endif - ////////////////////////////////////////////////////////////////////////// // Methods to create combinations or variants of shaders @@ -148,7 +85,7 @@ class SK_API SkShaders { static sk_sp Color(const SkColor4f&, sk_sp); static sk_sp Blend(SkBlendMode mode, sk_sp dst, sk_sp src); static sk_sp Blend(sk_sp, sk_sp dst, sk_sp src); - + static sk_sp CoordClamp(sk_sp, const SkRect& subset); private: SkShaders() = delete; }; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h index 79d673775e8d1..867f4eeb97b90 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h @@ -10,6 +10,8 @@ #include "include/core/SkScalar.h" +#include + struct SkISize { int32_t fWidth; int32_t fHeight; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h index 03eb3b5b0fb66..37cac632b1e8d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h @@ -5,117 +5,9 @@ * found in the LICENSE file. */ -#ifndef SkSpan_DEFINED -#define SkSpan_DEFINED +// We want SkSpan to be a public API, but it is also fundamental to many of our internal types. +// Thus, we have a public file that clients can include. This file defers to the private copy +// so we do not have a dependency cycle from our "base" files to our "core" files. -#include -#include -#include -#include -#include -#include "include/private/SkTLogic.h" +#include "include/private/base/SkSpan_impl.h" // IWYU pragma: export -// Add macro to check the lifetime of initializer_list arguments. initializer_list has a very -// short life span, and can only be used as a parameter, and not as a variable. -#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::lifetimebound) -#define SK_CHECK_IL_LIFETIME [[clang::lifetimebound]] -#else -#define SK_CHECK_IL_LIFETIME -#endif - -/** - * SkSpan holds a reference to contiguous data of type T along with a count. SkSpan does not own - * the data itself but is merely a reference, therefore you must take care with the lifetime of - * the underlying data. - * - * SkSpan is a count and a pointer into existing array or data type that stores its data in - * contiguous memory like std::vector. Any container that works with std::size() and std::data() - * can be used. - * - * SkSpan makes a convenient parameter for a routine to accept array like things. This allows you to - * write the routine without overloads for all different container types. - * - * Example: - * void routine(SkSpan a) { ... } - * - * std::vector v = {1, 2, 3, 4, 5}; - * - * routine(a); - * - * A word of caution when working with initializer_list, initializer_lists have a lifetime that is - * limited to the current statement. The following is correct and safe: - * - * Example: - * routine({1,2,3,4,5}); - * - * The following is undefined, and will result in erratic execution: - * - * Bad Example: - * initializer_list l = {1, 2, 3, 4, 5}; // The data behind l dies at the ;. - * routine(l); - */ -template -class SkSpan { -public: - constexpr SkSpan() : fPtr{nullptr}, fSize{0} {} - constexpr SkSpan(T* ptr, size_t size) : fPtr{ptr}, fSize{size} { - SkASSERT(ptr || size == 0); // disallow nullptr + a nonzero size - SkASSERT(size < kMaxSize); - } - template ::value>::type> - constexpr SkSpan(const SkSpan& that) : fPtr(std::data(that)), fSize{std::size(that)} {} - constexpr SkSpan(const SkSpan& o) = default; - template constexpr SkSpan(T(&a)[N]) : SkSpan(a, N) { } - template - constexpr SkSpan(Container& c) : SkSpan{std::data(c), std::size(c)} { } - SkSpan(std::initializer_list il SK_CHECK_IL_LIFETIME) - : SkSpan(std::data(il), std::size(il)) {} - - constexpr SkSpan& operator=(const SkSpan& that) = default; - - constexpr T& operator [] (size_t i) const { - SkASSERT(i < this->size()); - return fPtr[i]; - } - constexpr T& front() const { return fPtr[0]; } - constexpr T& back() const { return fPtr[fSize - 1]; } - constexpr T* begin() const { return fPtr; } - constexpr T* end() const { return fPtr + fSize; } - constexpr auto rbegin() const { return std::make_reverse_iterator(this->end()); } - constexpr auto rend() const { return std::make_reverse_iterator(this->begin()); } - constexpr T* data() const { return this->begin(); } - constexpr size_t size() const { return fSize; } - constexpr bool empty() const { return fSize == 0; } - constexpr size_t size_bytes() const { return fSize * sizeof(T); } - constexpr SkSpan first(size_t prefixLen) const { - SkASSERT(prefixLen <= this->size()); - return SkSpan{fPtr, prefixLen}; - } - constexpr SkSpan last(size_t postfixLen) const { - SkASSERT(postfixLen <= this->size()); - return SkSpan{fPtr + (this->size() - postfixLen), postfixLen}; - } - constexpr SkSpan subspan(size_t offset) const { - return this->subspan(offset, this->size() - offset); - } - constexpr SkSpan subspan(size_t offset, size_t count) const { - SkASSERT(offset <= this->size()); - SkASSERT(count <= this->size() - offset); - return SkSpan{fPtr + offset, count}; - } - -private: - static const constexpr size_t kMaxSize = std::numeric_limits::max() / sizeof(T); - T* fPtr; - size_t fSize; -}; - -template -SkSpan(Container&) -> - SkSpan()))>>; - -template -SkSpan(std::initializer_list) -> - SkSpan>()))>>; - -#endif // SkSpan_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h index 768de9b5a33d0..c582c80a0528c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h @@ -11,15 +11,16 @@ #include "include/core/SkData.h" #include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" -#include "include/private/SkTo.h" - -#include - -class SkStream; -class SkStreamRewindable; -class SkStreamSeekable; +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkTo.h" + +#include +#include +#include +#include +#include class SkStreamAsset; -class SkStreamMemory; /** * SkStream -- abstraction for a source of bytes. Subclasses can be backed by @@ -255,10 +256,10 @@ class SK_API SkWStream { bool writeText(const char text[]) { SkASSERT(text); - return this->write(text, strlen(text)); + return this->write(text, std::strlen(text)); } - bool newline() { return this->write("\n", strlen("\n")); } + bool newline() { return this->write("\n", std::strlen("\n")); } bool writeDecAsText(int32_t); bool writeBigDecAsText(int64_t, int minDigits = 0); @@ -296,8 +297,6 @@ class SK_API SkNullWStream : public SkWStream { //////////////////////////////////////////////////////////////////////////////////////// -#include - /** A stream that wraps a C FILE* file stream. */ class SK_API SkFILEStream : public SkStreamAsset { public: diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkString.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkString.h index e659910c6f00e..1b27fbf44b07c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkString.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkString.h @@ -11,15 +11,16 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" -#include -#include #include +#include +#include +#include #include #include +#include /* Some helper functions for C strings */ static inline bool SkStrStartsWith(const char string[], const char prefixStr[]) { @@ -128,6 +129,7 @@ class SK_API SkString { bool isEmpty() const { return 0 == fRec->fLength; } size_t size() const { return (size_t) fRec->fLength; } + const char* data() const { return fRec->data(); } const char* c_str() const { return fRec->data(); } char operator[](size_t n) const { return this->c_str()[n]; } @@ -173,8 +175,8 @@ class SK_API SkString { SkString& operator=(SkString&&); SkString& operator=(const char text[]); - char* writable_str(); - char& operator[](size_t n) { return this->writable_str()[n]; } + char* data(); + char& operator[](size_t n) { return this->data()[n]; } void reset(); /** String contents are preserved on resize. (For destructive resize, `set(nullptr, length)`.) @@ -286,22 +288,4 @@ static inline void swap(SkString& a, SkString& b) { a.swap(b); } -enum SkStrSplitMode { - // Strictly return all results. If the input is ",," and the separator is ',' this will return - // an array of three empty strings. - kStrict_SkStrSplitMode, - - // Only nonempty results will be added to the results. Multiple separators will be - // coalesced. Separators at the beginning and end of the input will be ignored. If the input is - // ",," and the separator is ',', this will return an empty vector. - kCoalesce_SkStrSplitMode -}; - -// Split str on any characters in delimiters into out. (Think, strtok with a sane API.) -void SkStrSplit(const char* str, const char* delimiters, SkStrSplitMode splitMode, - SkTArray* out); -inline void SkStrSplit(const char* str, const char* delimiters, SkTArray* out) { - SkStrSplit(str, delimiters, kCoalesce_SkStrSplitMode, out); -} - #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h index b4796fcbfa6ca..1257d04a844b7 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h @@ -9,7 +9,7 @@ #define SkStrokeRec_DEFINED #include "include/core/SkPaint.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" class SkPath; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h index 98dcfdefcb3db..3673d172b6d02 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h @@ -9,41 +9,61 @@ #define SkSurface_DEFINED #include "include/core/SkImage.h" +#include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkSamplingOptions.h" +#include "include/core/SkScalar.h" #include "include/core/SkSurfaceProps.h" +#include "include/core/SkTypes.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrTypes.h" +#else +enum GrSurfaceOrigin: int; +#endif + +#if defined(SK_GRAPHITE) +#include "include/gpu/GpuTypes.h" +namespace skgpu::graphite { +class BackendTexture; +} #endif #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 #include +class GrDirectContext; #endif -#if SK_SUPPORT_GPU && defined(SK_METAL) +#if defined(SK_GANESH) && defined(SK_METAL) #include "include/gpu/mtl/GrMtlTypes.h" #endif +#include +#include +#include + +class GrBackendRenderTarget; +class GrBackendSemaphore; +class GrBackendTexture; +class GrRecordingContext; +class SkBitmap; class SkCanvas; class SkCapabilities; +class SkColorSpace; class SkDeferredDisplayList; class SkPaint; class SkSurfaceCharacterization; -class GrBackendRenderTarget; -class GrBackendSemaphore; -class GrBackendTexture; -class GrDirectContext; -class GrRecordingContext; -class GrRenderTarget; -enum GrSurfaceOrigin: int; +enum SkColorType : int; +struct SkIRect; +struct SkISize; namespace skgpu { class MutableTextureState; +enum class Budgeted : bool; } namespace skgpu::graphite { -class BackendTexture; class Recorder; } @@ -206,7 +226,7 @@ class SK_API SkSurface : public SkRefCnt { backend API (accounting only for use of the texture by this surface). If SkSurface creation fails textureReleaseProc is called before this function returns. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param backendTexture texture residing on GPU @@ -241,7 +261,7 @@ class SK_API SkSurface : public SkRefCnt { backend API (accounting only for use of the render target by this surface). If SkSurface creation fails releaseProc is called before this function returns. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param backendRenderTarget GPU intermediate memory buffer @@ -276,7 +296,7 @@ class SK_API SkSurface : public SkRefCnt { shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace; @@ -287,9 +307,11 @@ class SK_API SkSurface : public SkRefCnt { @param shouldCreateWithMips hint that SkSurface will host mip map images @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, const SkImageInfo& imageInfo, - int sampleCount, GrSurfaceOrigin surfaceOrigin, + int sampleCount, + GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps* surfaceProps, bool shouldCreateWithMips = false); @@ -314,10 +336,12 @@ class SK_API SkSurface : public SkRefCnt { fonts; may be nullptr @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, - const SkImageInfo& imageInfo, int sampleCount, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, + const SkImageInfo& imageInfo, + int sampleCount, const SkSurfaceProps* surfaceProps) { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) return MakeRenderTarget(context, budgeted, imageInfo, sampleCount, kBottomLeft_GrSurfaceOrigin, surfaceProps); #else @@ -339,9 +363,10 @@ class SK_API SkSurface : public SkRefCnt { of raster surface; width, or height, or both, may be zero @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, const SkImageInfo& imageInfo) { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) if (!imageInfo.width() || !imageInfo.height()) { return nullptr; } @@ -362,8 +387,7 @@ class SK_API SkSurface : public SkRefCnt { */ static sk_sp MakeRenderTarget(GrRecordingContext* context, const SkSurfaceCharacterization& characterization, - SkBudgeted budgeted); - + skgpu::Budgeted budgeted); #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 /** Private. @@ -398,7 +422,7 @@ class SK_API SkSurface : public SkRefCnt { ); #endif -#ifdef SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) /** * In Graphite, while clients hold a ref on an SkSurface, the backing gpu object does _not_ * count against the budget. Once an SkSurface is freed, the backing gpu object may or may @@ -408,7 +432,7 @@ class SK_API SkSurface : public SkRefCnt { static sk_sp MakeGraphite( skgpu::graphite::Recorder*, const SkImageInfo& imageInfo, - skgpu::graphite::Mipmapped = skgpu::graphite::Mipmapped::kNo, + skgpu::Mipmapped = skgpu::Mipmapped::kNo, const SkSurfaceProps* surfaceProps = nullptr); /** @@ -430,9 +454,9 @@ class SK_API SkSurface : public SkRefCnt { sk_sp colorSpace, const SkSurfaceProps* props); -#endif // SK_GRAPHITE_ENABLED +#endif // SK_GRAPHITE -#if SK_SUPPORT_GPU && defined(SK_METAL) +#if defined(SK_GANESH) && defined(SK_METAL) /** Creates SkSurface from CAMetalLayer. Returned SkSurface takes a reference on the CAMetalLayer. The ref on the layer will be released when the SkSurface is destroyed. @@ -525,7 +549,7 @@ class SK_API SkSurface : public SkRefCnt { /** Returns an ImageInfo describing the surface. */ - SkImageInfo imageInfo(); + virtual SkImageInfo imageInfo() const { return SkImageInfo::MakeUnknown(fWidth, fHeight); } /** Returns unique value identifying the content of SkSurface. Returned value changes each time the content changes. Content is changed by drawing, or by calling @@ -566,7 +590,7 @@ class SK_API SkSurface : public SkRefCnt { */ skgpu::graphite::Recorder* recorder(); -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) enum BackendHandleAccess { kFlushRead_BackendHandleAccess, //!< back-end object is readable kFlushWrite_BackendHandleAccess, //!< back-end object is writable @@ -669,7 +693,7 @@ class SK_API SkSurface : public SkRefCnt { /** Returns SkImage capturing SkSurface contents. Subsequent drawing to SkSurface contents are not captured. SkImage allocation is accounted for if SkSurface was created with - SkBudgeted::kYes. + skgpu::Budgeted::kYes. @return SkImage initialized with SkSurface contents @@ -690,6 +714,34 @@ class SK_API SkSurface : public SkRefCnt { */ sk_sp makeImageSnapshot(const SkIRect& bounds); +#if defined(SK_GRAPHITE) + /** + * The 'asImage' and 'makeImageCopy' API/entry points are currently only available for + * Graphite. + * + * In this API, SkSurface no longer supports copy-on-write behavior. Instead, when creating + * an image for a surface, the client must explicitly indicate if a copy should be made. + * In both of the below calls the resource backing the surface will never change. + * + * The 'asImage' entry point has some major ramifications for the mutability of the + * returned SkImage. Since the originating surface and the returned image share the + * same backing, care must be taken by the client to ensure that the contents of the image + * reflect the desired contents when it is consumed by the gpu. + * Note: if the backing GPU buffer isn't textureable this method will return null. Graphite + * will not attempt to make a copy. + * Note: For 'asImage', the mipmapping of the image will match that of the source surface. + * + * The 'makeImageCopy' entry point allows subsetting and the addition of mipmaps (since + * a copy is already being made). + * + * In Graphite, the legacy API call (i.e., makeImageSnapshot) will just always make a copy. + */ + sk_sp asImage(); + + sk_sp makeImageCopy(const SkIRect* subset = nullptr, + skgpu::Mipmapped mipmapped = skgpu::Mipmapped::kNo); +#endif + /** Draws SkSurface contents to canvas, with its top-left corner at (x, y). If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter, and SkBlendMode. @@ -834,36 +886,6 @@ class SK_API SkSurface : public SkRefCnt { using RescaleGamma = SkImage::RescaleGamma; using RescaleMode = SkImage::RescaleMode; - /** Makes surface pixel data available to caller, possibly asynchronously. - - Currently asynchronous reads are only supported on the GPU backend and only when the - underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all - other cases this operates synchronously. - - Data is read from the source sub-rectangle, then converted to the color space, color type, - and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the surface - causes failure. - - When the pixel data is ready the caller's ReadPixelsCallback is called with a - AsyncReadResult containing pixel data in the requested color type, alpha type, and color - space. The AsyncReadResult will have count() == 1. Upon failure the callback is called - with nullptr for AsyncReadResult. For a GPU surface this flushes work but a submit must - occur to guarantee a finite time before the callback is called. - - The data is valid for the lifetime of AsyncReadResult with the exception that if the - SkSurface is GPU-backed the data is immediately invalidated if the context is abandoned - or destroyed. - - @param info info of the requested pixels - @param srcRect subrectangle of surface to read - @param callback function to call with result of the read - @param context passed to callback - */ - void asyncReadPixels(const SkImageInfo& info, - const SkIRect& srcRect, - ReadPixelsCallback callback, - ReadPixelsContext context); - /** Makes surface pixel data available to caller, possibly asynchronously. It can also rescale the surface pixels. @@ -994,7 +1016,7 @@ class SK_API SkSurface : public SkRefCnt { kPresent, //!< back-end surface will be used for presenting to screen }; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** If a surface is GPU texture backed, is being drawn with MSAA, and there is a resolve texture, this call will insert a resolve command into the stream of gpu commands. In order for the resolve to actually have an effect, the work still needs to be flushed and submitted @@ -1100,7 +1122,7 @@ class SK_API SkSurface : public SkRefCnt { */ GrSemaphoresSubmitted flush(const GrFlushInfo& info, const skgpu::MutableTextureState* newState = nullptr); -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) void flush(); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h index 91b10e87bf7a9..0b65a10d03c4b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h @@ -17,7 +17,7 @@ class SkColorSpace; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrContextThreadSafeProxy.h" #include "include/gpu/GrTypes.h" @@ -118,7 +118,7 @@ class SK_API SkSurfaceCharacterization { bool isCompatible(const GrBackendTexture&) const; private: - friend class SkSurface_Gpu; // for 'set' & 'config' + friend class SkSurface_Ganesh; // for 'set' & 'config' friend class GrVkSecondaryCBDrawContext; // for 'set' & 'config' friend class GrContextThreadSafeProxy; // for private ctor friend class SkDeferredDisplayListRecorder; // for 'config' @@ -210,7 +210,7 @@ class SK_API SkSurfaceCharacterization { SkSurfaceProps fSurfaceProps; }; -#else// !SK_SUPPORT_GPU +#else// !defined(SK_GANESH) class GrBackendFormat; class SK_API SkSurfaceCharacterization { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h index 7b07554e5be34..4790f258e4ad5 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h @@ -9,6 +9,7 @@ #define SkSurfaceProps_DEFINED #include "include/core/SkTypes.h" +#include "include/private/base/SkTo.h" /** * Description of how the LCD strips are arranged for each pixel. If this is unknown, or the @@ -53,7 +54,10 @@ class SK_API SkSurfaceProps { enum Flags { kUseDeviceIndependentFonts_Flag = 1 << 0, // Use internal MSAA to render to non-MSAA GPU surfaces. - kDynamicMSAA_Flag = 1 << 1 + kDynamicMSAA_Flag = 1 << 1, + // If set, all rendering will have dithering enabled + // Currently this only impacts GPU backends + kAlwaysDither_Flag = 1 << 2, }; /** Deprecated alias used by Chromium. Will be removed. */ static const Flags kUseDistanceFieldFonts_Flag = kUseDeviceIndependentFonts_Flag; @@ -76,6 +80,10 @@ class SK_API SkSurfaceProps { return SkToBool(fFlags & kUseDeviceIndependentFonts_Flag); } + bool isAlwaysDither() const { + return SkToBool(fFlags & kAlwaysDither_Flag); + } + bool operator==(const SkSurfaceProps& that) const { return fFlags == that.fFlags && fPixelGeometry == that.fPixelGeometry; } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h index e010ea9cc788d..8f6cb01c045ff 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h @@ -12,7 +12,7 @@ #include "include/core/SkPaint.h" #include "include/core/SkRefCnt.h" #include "include/core/SkString.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include @@ -491,7 +491,7 @@ class SK_API SkTextBlobBuilder { friend class SkTextBlobPriv; friend class SkTextBlobBuilderPriv; - SkAutoTMalloc fStorage; + skia_private::AutoTMalloc fStorage; size_t fStorageSize; size_t fStorageUsed; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h new file mode 100644 index 0000000000000..e9b441378d0c4 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h @@ -0,0 +1,30 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkTextureCompressionType_DEFINED +#define SkTextureCompressionType_DEFINED +/* + * Skia | GL_COMPRESSED_* | MTLPixelFormat* | VK_FORMAT_*_BLOCK + * -------------------------------------------------------------------------------------- + * kETC2_RGB8_UNORM | ETC1_RGB8 | ETC2_RGB8 (iOS-only) | ETC2_R8G8B8_UNORM + * | RGB8_ETC2 | | + * -------------------------------------------------------------------------------------- + * kBC1_RGB8_UNORM | RGB_S3TC_DXT1_EXT | N/A | BC1_RGB_UNORM + * -------------------------------------------------------------------------------------- + * kBC1_RGBA8_UNORM | RGBA_S3TC_DXT1_EXT | BC1_RGBA (macOS-only)| BC1_RGBA_UNORM + */ +enum class SkTextureCompressionType { + kNone, + kETC2_RGB8_UNORM, + + kBC1_RGB8_UNORM, + kBC1_RGBA8_UNORM, + kLast = kBC1_RGBA8_UNORM, + kETC1_RGB8 = kETC2_RGB8_UNORM, +}; + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h index 3da2c8c7715b9..9135c7e113c0d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h @@ -11,7 +11,7 @@ #define SkTime_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" #include diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h index d4a13877152d3..9e099d41e37f5 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h @@ -14,8 +14,8 @@ #include "include/core/SkFontTypes.h" #include "include/core/SkRect.h" #include "include/core/SkString.h" -#include "include/private/SkOnce.h" #include "include/private/SkWeakRefCnt.h" +#include "include/private/base/SkOnce.h" class SkData; class SkDescriptor; @@ -360,6 +360,12 @@ class SK_API SkTypeface : public SkWeakRefCnt { return this->onGetCTFontRef(); } + /* Skia reserves all tags that begin with a lower case letter and 0 */ + using FactoryId = SkFourByteTag; + static void Register( + FactoryId id, + sk_sp (*make)(std::unique_ptr, const SkFontArguments&)); + protected: explicit SkTypeface(const SkFontStyle& style, bool isFixedPitch = false); ~SkTypeface() override; @@ -435,7 +441,8 @@ class SK_API SkTypeface : public SkWeakRefCnt { * typefaces that contain a COLR table. */ bool glyphMaskNeedsCurrentColor() const; - friend class SkStrikeServerImpl; // glyphMaskNeedsCurrentColor + friend class SkStrikeServerImpl; // glyphMaskNeedsCurrentColor + friend class SkTypefaceProxyPrototype; // glyphMaskNeedsCurrentColor /** Retrieve detailed typeface metrics. Used by the PDF backend. */ std::unique_ptr getAdvancedMetrics() const; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h index 8f7a2c0982b68..5530cc4463b39 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h @@ -8,235 +8,25 @@ #ifndef SkTypes_DEFINED #define SkTypes_DEFINED -/** \file SkTypes.h -*/ - -// Pre-SkUserConfig.h setup. - -// Allows embedders that want to disable macros that take arguments to just -// define that symbol to be one of these -#define SK_NOTHING_ARG1(arg1) -#define SK_NOTHING_ARG2(arg1, arg2) -#define SK_NOTHING_ARG3(arg1, arg2, arg3) - -#if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && \ - !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) - - #ifdef __APPLE__ - #include - #endif - - #if defined(_WIN32) || defined(__SYMBIAN32__) - #define SK_BUILD_FOR_WIN - #elif defined(ANDROID) || defined(__ANDROID__) - #define SK_BUILD_FOR_ANDROID - #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || \ - defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || \ - defined(__DragonFly__) || defined(__Fuchsia__) || \ - defined(__GLIBC__) || defined(__GNU__) || defined(__unix__) - #define SK_BUILD_FOR_UNIX - #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR - #define SK_BUILD_FOR_IOS - #else - #define SK_BUILD_FOR_MAC - #endif - -#endif - -#if defined(SK_BUILD_FOR_WIN) && !defined(__clang__) - #if !defined(SK_RESTRICT) - #define SK_RESTRICT __restrict - #endif - #if !defined(SK_WARN_UNUSED_RESULT) - #define SK_WARN_UNUSED_RESULT - #endif -#endif - -#if !defined(SK_RESTRICT) - #define SK_RESTRICT __restrict__ -#endif - -#if !defined(SK_WARN_UNUSED_RESULT) - #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#endif - -#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) - #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) - #define SK_CPU_BENDIAN - #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) - #define SK_CPU_LENDIAN - #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ - defined(__PPC__) || defined(__PPC64__) || \ - defined(_MIPSEB) || defined(__ARMEB__) || \ - defined(__s390__) || \ - (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ - (defined(__ia64) && defined(__BIG_ENDIAN__)) - #define SK_CPU_BENDIAN - #else - #define SK_CPU_LENDIAN - #endif -#endif - -#if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) - #define SK_CPU_X86 1 -#endif - -/** - * SK_CPU_SSE_LEVEL - * - * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. - * On non-intel CPU this should be undefined. - */ -#define SK_CPU_SSE_LEVEL_SSE1 10 -#define SK_CPU_SSE_LEVEL_SSE2 20 -#define SK_CPU_SSE_LEVEL_SSE3 30 -#define SK_CPU_SSE_LEVEL_SSSE3 31 -#define SK_CPU_SSE_LEVEL_SSE41 41 -#define SK_CPU_SSE_LEVEL_SSE42 42 -#define SK_CPU_SSE_LEVEL_AVX 51 -#define SK_CPU_SSE_LEVEL_AVX2 52 -#define SK_CPU_SSE_LEVEL_SKX 60 - -// Are we in GCC/Clang? -#ifndef SK_CPU_SSE_LEVEL - // These checks must be done in descending order to ensure we set the highest - // available SSE level. - #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ - defined(__AVX512BW__) && defined(__AVX512VL__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX - #elif defined(__AVX2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 - #elif defined(__AVX__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX - #elif defined(__SSE4_2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42 - #elif defined(__SSE4_1__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41 - #elif defined(__SSSE3__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 - #elif defined(__SSE3__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 - #elif defined(__SSE2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #endif -#endif - -// Are we in VisualStudio? -#ifndef SK_CPU_SSE_LEVEL - // These checks must be done in descending order to ensure we set the highest - // available SSE level. 64-bit intel guarantees at least SSE2 support. - #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ - defined(__AVX512BW__) && defined(__AVX512VL__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX - #elif defined(__AVX2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 - #elif defined(__AVX__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX - #elif defined(_M_X64) || defined(_M_AMD64) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #elif defined(_M_IX86_FP) - #if _M_IX86_FP >= 2 - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #elif _M_IX86_FP == 1 - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 - #endif - #endif -#endif - -// ARM defines -#if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) - #define SK_CPU_ARM32 -#elif defined(__aarch64__) - #define SK_CPU_ARM64 -#endif - -// All 64-bit ARM chips have NEON. Many 32-bit ARM chips do too. -#if !defined(SK_ARM_HAS_NEON) && defined(__ARM_NEON) - #define SK_ARM_HAS_NEON -#endif - -#if defined(__ARM_FEATURE_CRC32) - #define SK_ARM_HAS_CRC32 -#endif - - -// DLL/.so exports. -#if !defined(SKIA_IMPLEMENTATION) - #define SKIA_IMPLEMENTATION 0 -#endif -#if !defined(SK_API) - #if defined(SKIA_DLL) - #if defined(_MSC_VER) - #if SKIA_IMPLEMENTATION - #define SK_API __declspec(dllexport) - #else - #define SK_API __declspec(dllimport) - #endif - #else - #define SK_API __attribute__((visibility("default"))) - #endif - #else - #define SK_API - #endif -#endif - -// SK_SPI is functionally identical to SK_API, but used within src to clarify that it's less stable -#if !defined(SK_SPI) - #define SK_SPI SK_API -#endif - +// All of these files should be independent of things users can set via the user config file. +// They should also be able to be included in any order. // IWYU pragma: begin_exports -#if defined (SK_USER_CONFIG_HEADER) - #include SK_USER_CONFIG_HEADER -#else - #include "include/config/SkUserConfig.h" -#endif -// IWYU pragma: end_exports -#include -#include - -// Post SkUserConfig.h checks and such. -#if !defined(SK_DEBUG) && !defined(SK_RELEASE) - #ifdef NDEBUG - #define SK_RELEASE - #else - #define SK_DEBUG - #endif -#endif +#include "include/private/base/SkFeatures.h" -#if defined(SK_DEBUG) && defined(SK_RELEASE) -# error "cannot define both SK_DEBUG and SK_RELEASE" -#elif !defined(SK_DEBUG) && !defined(SK_RELEASE) -# error "must define either SK_DEBUG or SK_RELEASE" -#endif - -#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) -# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" -#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) -# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" -#endif - -#if defined(SK_CPU_BENDIAN) && !defined(I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN) - #error "The Skia team is not endian-savvy enough to support big-endian CPUs." - #error "If you still want to use Skia," - #error "please define I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN." -#endif +// Load and verify defines from the user config file. +#include "include/private/base/SkLoadUserConfig.h" -#if !defined(SK_ATTRIBUTE) -# if defined(__clang__) || defined(__GNUC__) -# define SK_ATTRIBUTE(attr) __attribute__((attr)) -# else -# define SK_ATTRIBUTE(attr) -# endif -#endif +// Any includes or defines below can be configured by the user config file. +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkDebug.h" +// IWYU pragma: end_exports -#if !defined(SK_SUPPORT_GPU) -# define SK_SUPPORT_GPU 1 -#endif +#include +#include -#if SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GANESH) || defined(SK_GRAPHITE) # if !defined(SK_ENABLE_SKSL) # define SK_ENABLE_SKSL # endif @@ -248,45 +38,6 @@ # undef SK_DIRECT3D #endif -#if !defined(SkUNREACHABLE) -# if defined(_MSC_VER) && !defined(__clang__) -# include -# define FAST_FAIL_INVALID_ARG 5 -// See https://developercommunity.visualstudio.com/content/problem/1128631/code-flow-doesnt-see-noreturn-with-extern-c.html -// for why this is wrapped. Hopefully removable after msvc++ 19.27 is no longer supported. -[[noreturn]] static inline void sk_fast_fail() { __fastfail(FAST_FAIL_INVALID_ARG); } -# define SkUNREACHABLE sk_fast_fail() -# else -# define SkUNREACHABLE __builtin_trap() -# endif -#endif - -#if defined(SK_BUILD_FOR_GOOGLE3) - void SkDebugfForDumpStackTrace(const char* data, void* unused); - namespace base { - void DumpStackTrace(int skip_count, void w(const char*, void*), void* arg); - } -# define SK_DUMP_GOOGLE3_STACK() ::base::DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr) -#else -# define SK_DUMP_GOOGLE3_STACK() -#endif - -#ifndef SK_ABORT -# ifdef SK_BUILD_FOR_WIN - // This style lets Visual Studio follow errors back to the source file. -# define SK_DUMP_LINE_FORMAT "%s(%d)" -# else -# define SK_DUMP_LINE_FORMAT "%s:%d" -# endif -# define SK_ABORT(message, ...) \ - do { \ - SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \ - __FILE__, __LINE__, ##__VA_ARGS__); \ - SK_DUMP_GOOGLE3_STACK(); \ - sk_abort_no_print(); \ - } while (false) -#endif - // If SK_R32_SHIFT is set, we'll use that to choose RGBA or BGRA. // If not, we'll default to RGBA everywhere except BGRA on Windows. #if defined(SK_R32_SHIFT) @@ -306,7 +57,6 @@ #define SK_G32_SHIFT 8 #define SK_A32_SHIFT 24 - /** * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. */ @@ -332,48 +82,6 @@ #undef free #endif -#if !defined(SK_UNUSED) -# if !defined(__clang__) && defined(_MSC_VER) -# define SK_UNUSED __pragma(warning(suppress:4189)) -# else -# define SK_UNUSED SK_ATTRIBUTE(unused) -# endif -#endif - -/** - * If your judgment is better than the compiler's (i.e. you've profiled it), - * you can use SK_ALWAYS_INLINE to force inlining. E.g. - * inline void someMethod() { ... } // may not be inlined - * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined - */ -#if !defined(SK_ALWAYS_INLINE) -# if defined(SK_BUILD_FOR_WIN) -# define SK_ALWAYS_INLINE __forceinline -# else -# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline -# endif -#endif - -/** - * If your judgment is better than the compiler's (i.e. you've profiled it), - * you can use SK_NEVER_INLINE to prevent inlining. - */ -#if !defined(SK_NEVER_INLINE) -# if defined(SK_BUILD_FOR_WIN) -# define SK_NEVER_INLINE __declspec(noinline) -# else -# define SK_NEVER_INLINE SK_ATTRIBUTE(noinline) -# endif -#endif - -#ifndef SK_PRINTF_LIKE -# if defined(__clang__) || defined(__GNUC__) -# define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) -# else -# define SK_PRINTF_LIKE(A, B) -# endif -#endif - #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 0 #endif @@ -386,11 +94,6 @@ # define GR_TEST_UTILS 0 #endif -#if !SK_SUPPORT_GPU - #define SK_GPU_V1 0 // always false if Ganesh is disabled -#elif !defined(SK_GPU_V1) -# define SK_GPU_V1 1 // otherwise default to v1 enabled -#endif #if defined(SK_HISTOGRAM_ENUMERATION) || \ defined(SK_HISTOGRAM_BOOLEAN) || \ @@ -420,145 +123,44 @@ #define SK_HISTOGRAM_PERCENTAGE(name, percent_as_int) \ SK_HISTOGRAM_EXACT_LINEAR(name, percent_as_int, 101) -#ifndef SK_DISABLE_LEGACY_SHADERCONTEXT -#define SK_ENABLE_LEGACY_SHADERCONTEXT +// The top-level define SK_ENABLE_OPTIMIZE_SIZE can be used to remove several large features at once +#if defined(SK_ENABLE_OPTIMIZE_SIZE) +# define SK_FORCE_RASTER_PIPELINE_BLITTER +# define SK_DISABLE_SDF_TEXT #endif -#ifdef SK_ENABLE_API_AVAILABLE -#define SK_API_AVAILABLE API_AVAILABLE -#else -#define SK_API_AVAILABLE(...) +#ifndef SK_DISABLE_LEGACY_SHADERCONTEXT +# define SK_ENABLE_LEGACY_SHADERCONTEXT #endif #if defined(SK_BUILD_FOR_LIBFUZZER) || defined(SK_BUILD_FOR_AFL_FUZZ) +#if !defined(SK_BUILD_FOR_FUZZER) #define SK_BUILD_FOR_FUZZER #endif +#endif -/** Called internally if we hit an unrecoverable error. - The platform implementation must not return, but should either throw - an exception or otherwise exit. -*/ -[[noreturn]] SK_API extern void sk_abort_no_print(void); +/** + * Gr defines are set to 0 or 1, rather than being undefined or defined + */ -#ifndef SkDebugf - SK_API void SkDebugf(const char format[], ...) SK_PRINTF_LIKE(1, 2); +#if !defined(GR_CACHE_STATS) + #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) + #define GR_CACHE_STATS 1 + #else + #define GR_CACHE_STATS 0 + #endif #endif -// SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g. -// uint32_t foo(int x) { -// SkASSERT(x > 4); -// return x - 4; -// } -// and are also written to be compatible with constexpr functions: -// constexpr uint32_t foo(int x) { -// return SkASSERT(x > 4), -// x - 4; -// } -#define SkASSERT_RELEASE(cond) \ - static_cast( (cond) ? (void)0 : []{ SK_ABORT("assert(%s)", #cond); }() ) - -#ifdef SK_DEBUG - #define SkASSERT(cond) SkASSERT_RELEASE(cond) - #define SkASSERTF(cond, fmt, ...) static_cast( (cond) ? (void)0 : [&]{ \ - SkDebugf(fmt"\n", ##__VA_ARGS__); \ - SK_ABORT("assert(%s)", #cond); \ - }() ) - #define SkDEBUGFAIL(message) SK_ABORT("%s", message) - #define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__) - #define SkDEBUGCODE(...) __VA_ARGS__ - #define SkDEBUGF(...) SkDebugf(__VA_ARGS__) - #define SkAssertResult(cond) SkASSERT(cond) -#else - #define SkASSERT(cond) static_cast(0) - #define SkASSERTF(cond, fmt, ...) static_cast(0) - #define SkDEBUGFAIL(message) - #define SkDEBUGFAILF(fmt, ...) - #define SkDEBUGCODE(...) - #define SkDEBUGF(...) - - // unlike SkASSERT, this macro executes its condition in the non-debug build. - // The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT. - #define SkAssertResult(cond) if (cond) {} do {} while(false) +#if !defined(GR_GPU_STATS) + #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || GR_TEST_UTILS + #define GR_GPU_STATS 1 + #else + #define GR_GPU_STATS 0 + #endif #endif //////////////////////////////////////////////////////////////////////////////// -/** Fast type for unsigned 8 bits. Use for parameter passing and local - variables, not for storage -*/ -typedef unsigned U8CPU; - -/** Fast type for unsigned 16 bits. Use for parameter passing and local - variables, not for storage -*/ -typedef unsigned U16CPU; - -/** @return false or true based on the condition -*/ -template static constexpr bool SkToBool(const T& x) { - return (bool)x; -} - -static constexpr int16_t SK_MaxS16 = INT16_MAX; -static constexpr int16_t SK_MinS16 = -SK_MaxS16; - -static constexpr int32_t SK_MaxS32 = INT32_MAX; -static constexpr int32_t SK_MinS32 = -SK_MaxS32; -static constexpr int32_t SK_NaN32 = INT32_MIN; - -static constexpr int64_t SK_MaxS64 = INT64_MAX; -static constexpr int64_t SK_MinS64 = -SK_MaxS64; - -static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { - return (int32_t) ((uint32_t) value << shift); -} - -static inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) { - return (int64_t) ((uint64_t) value << shift); -} - -//////////////////////////////////////////////////////////////////////////////// - -/** @return the number of entries in an array (not a pointer) -*/ -// The SkArrayCountHelper template returns a type 'char (&)[N]', a reference to an array of -// char with N elements, where N is deduced using function parameter type deduction. This is then -// used in the sizeof operator in SK_ARRAY_COUNT. The sizeof operator ignores the reference, and -// just evaluates the size of the array type. -// -// DEPRECATED: use std::size() instead. -// Note: Rarely, std::size(z) can't deduce the type of z during compile time for static_assert -// while SK_ARRAY_COUNT can. It can't be deduced because z is part of class, and the class' this -// pointer is not a valid constexpr expression. Use SkASSERT instead. -template char (&SkArrayCountHelper(T (&array)[N]))[N]; -#define SK_ARRAY_COUNT(array) (sizeof(SkArrayCountHelper(array))) - -//////////////////////////////////////////////////////////////////////////////// - -template static constexpr T SkAlign2(T x) { return (x + 1) >> 1 << 1; } -template static constexpr T SkAlign4(T x) { return (x + 3) >> 2 << 2; } -template static constexpr T SkAlign8(T x) { return (x + 7) >> 3 << 3; } - -template static constexpr bool SkIsAlign2(T x) { return 0 == (x & 1); } -template static constexpr bool SkIsAlign4(T x) { return 0 == (x & 3); } -template static constexpr bool SkIsAlign8(T x) { return 0 == (x & 7); } - -template static constexpr T SkAlignPtr(T x) { - return sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x); -} -template static constexpr bool SkIsAlignPtr(T x) { - return sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x); -} - -/** - * align up to a power of 2 - */ -static inline constexpr size_t SkAlignTo(size_t x, size_t alignment) { - // The same as alignment && SkIsPow2(value), w/o a dependency cycle. - SkASSERT(alignment && (alignment & (alignment - 1)) == 0); - return (x + alignment - 1) & ~(alignment - 1); -} - typedef uint32_t SkFourByteTag; static inline constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d) { return (((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | (uint32_t)d); @@ -591,36 +193,5 @@ static constexpr uint32_t SK_InvalidGenID = 0; */ static constexpr uint32_t SK_InvalidUniqueID = 0; -static inline int32_t SkAbs32(int32_t value) { - SkASSERT(value != SK_NaN32); // The most negative int32_t can't be negated. - if (value < 0) { - value = -value; - } - return value; -} - -template static inline T SkTAbs(T value) { - if (value < 0) { - value = -value; - } - return value; -} - -//////////////////////////////////////////////////////////////////////////////// - -/** Indicates whether an allocation should count against a cache budget. -*/ -enum class SkBudgeted : bool { - kNo = false, - kYes = true -}; - -/** Indicates whether a backing store needs to be an exact match or can be - larger than is strictly necessary -*/ -enum class SkBackingFit { - kApprox, - kExact -}; #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h index fc53e9d01aaf8..2c3f784a42674 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h @@ -12,6 +12,8 @@ #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include + class SkData; struct SkPoint; class SkVerticesPriv; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h index a3cf210f37099..bbbae5d383d94 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h @@ -10,9 +10,13 @@ #include "include/codec/SkEncodedOrigin.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkMatrix.h" #include "include/core/SkSize.h" +#include "include/core/SkTypes.h" #include +#include +#include #include /** diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h index de04ab14dc3c9..2ecb9005df1af 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h @@ -8,14 +8,20 @@ #ifndef SkYUVAPixmaps_DEFINED #define SkYUVAPixmaps_DEFINED +#include "include/core/SkColorType.h" #include "include/core/SkData.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSize.h" +#include "include/core/SkTypes.h" #include "include/core/SkYUVAInfo.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" #include #include +#include +#include class GrImageContext; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h index bf131848baa12..16e953be5e5ed 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h @@ -12,7 +12,7 @@ #include "include/core/SkScalar.h" #include "include/core/SkString.h" #include "include/core/SkTime.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #define SKPDF_STRING(X) SKPDF_STRING_IMPL(X) #define SKPDF_STRING_IMPL(X) #X @@ -143,6 +143,17 @@ struct Metadata { */ SkExecutor* fExecutor = nullptr; + /** PDF streams may be compressed to save space. + Use this to specify the desired compression vs time tradeoff. + */ + enum class CompressionLevel : int { + Default = -1, + None = 0, + LowButFast = 1, + Average = 6, + HighButSlow = 9, + } fCompressionLevel = CompressionLevel::Default; + /** Preferred Subsetter. Only respected if both are compiled in. The Sfntly subsetter is deprecated. diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h index ee470f96d38b2..5092278f0def3 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h @@ -8,12 +8,13 @@ #ifndef SkColorMatrix_DEFINED #define SkColorMatrix_DEFINED -#include "include/core/SkImageInfo.h" #include "include/core/SkTypes.h" #include #include +enum SkYUVColorSpace : int; + class SK_API SkColorMatrix { public: constexpr SkColorMatrix() : SkColorMatrix(1, 0, 0, 0, 0, diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h index df08c96f59322..43a67e242e11e 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h @@ -62,10 +62,43 @@ class SK_API SkGradientShader { struct Interpolation { enum class InPremul : bool { kNo = false, kYes = true }; - InPremul fInPremul = InPremul::kNo; + enum class ColorSpace : uint8_t { + // Default Skia behavior: interpolate in the color space of the destination surface + kDestination, + + // https://www.w3.org/TR/css-color-4/#interpolation-space + kSRGBLinear, + kLab, + kOKLab, + kLCH, + kOKLCH, + kSRGB, + kHSL, + kHWB, + + kLastColorSpace = kHWB, + }; + static constexpr int kColorSpaceCount = static_cast(ColorSpace::kLastColorSpace) + 1; + + enum class HueMethod : uint8_t { + // https://www.w3.org/TR/css-color-4/#hue-interpolation + kShorter, + kLonger, + kIncreasing, + kDecreasing, + + kLastHueMethod = kDecreasing, + }; + static constexpr int kHueMethodCount = static_cast(HueMethod::kLastHueMethod) + 1; + + InPremul fInPremul = InPremul::kNo; + ColorSpace fColorSpace = ColorSpace::kDestination; + HueMethod fHueMethod = HueMethod::kShorter; // Only relevant for LCH, OKLCH, HSL, or HWB static Interpolation FromFlags(uint32_t flags) { - return {flags & kInterpolateColorsInPremul_Flag ? InPremul::kYes : InPremul::kNo}; + return {flags & kInterpolateColorsInPremul_Flag ? InPremul::kYes : InPremul::kNo, + ColorSpace::kDestination, + HueMethod::kShorter}; } }; @@ -76,8 +109,11 @@ class SK_API SkGradientShader { @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the start and end point. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >=2. The number of colors (and pos if not NULL) entries. @param mode The tiling mode @@ -95,8 +131,11 @@ class SK_API SkGradientShader { @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the start and end point. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >=2. The number of colors (and pos if not NULL) entries. @param mode The tiling mode @@ -123,8 +162,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the center and edge of the circle. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode The tiling mode */ @@ -141,8 +183,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the center and edge of the circle. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode The tiling mode */ @@ -214,8 +259,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, then the colors are distributed evenly within the angular range. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode Tiling mode: controls drawing outside of the gradient angular range. @param startAngle Start of the angular range, corresponding to pos == 0. @@ -250,8 +298,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, then the colors are distributed evenly within the angular range. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode Tiling mode: controls drawing outside of the gradient angular range. @param startAngle Start of the angular range, corresponding to pos == 0. diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h index 5665c607015c7..75d2cb0bcc54f 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h @@ -310,17 +310,6 @@ class SK_API SkImageFilters { static sk_sp Offset(SkScalar dx, SkScalar dy, sk_sp input, const CropRect& cropRect = {}); - /** - * Create a filter that fills the output with the given paint. - * @param paint The paint to fill - * @param cropRect Optional rectangle that will be filled. If null, the source bitmap's bounds - * are filled even though the source bitmap itself is not used. - * - * DEPRECATED: Use Shader() instead, since many features of SkPaint are ignored when filling - * the target output, and paint color/alpha can be emulated with SkShaders::Color(). - */ - static sk_sp Paint(const SkPaint& paint, const CropRect& cropRect = {}); - /** * Create a filter that produces the SkPicture as its output, drawn into targetRect. Note that * the targetRect is not the same as the SkIRect cropRect that many filters accept. Returns diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h index a8e0f4d7dc837..4d3450ee25878 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h @@ -16,8 +16,10 @@ #include "include/core/SkShader.h" #include "include/core/SkSpan.h" #include "include/core/SkString.h" -#include "include/private/SkOnce.h" +#include "include/core/SkTypes.h" #include "include/private/SkSLSampleUsage.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkTemplates.h" #include #include @@ -34,6 +36,7 @@ class SkRuntimeImageFilter; namespace SkSL { class DebugTrace; +class DebugTracePriv; class ErrorReporter; class FunctionDefinition; struct Program; @@ -43,7 +46,11 @@ struct ProgramSettings; namespace skvm { class Program; -} // namespace skvm +} + +namespace SkSL::RP { +class Program; +} /* * SkRuntimeEffect supports creating custom SkShader and SkColorFilter objects using Skia's SkSL @@ -126,9 +133,9 @@ class SK_API SkRuntimeEffect : public SkRefCnt { friend class SkRuntimeEffect; friend class SkRuntimeEffectPriv; - // Public SkSL does not allow access to sk_FragCoord. The semantics of that variable are - // confusing, and expose clients to implementation details of saveLayer and image filters. - bool usePrivateRTShaderModule = false; + // This flag allows Runtime Effects to access Skia implementation details like sk_FragCoord + // and functions with private identifiers (e.g. $rgb_to_hsl). + bool allowPrivateAccess = false; // TODO(skia:11209) - Replace this with a promised SkCapabilities? // This flag lifts the ES2 restrictions on Runtime Effects that are gated by the @@ -276,6 +283,7 @@ class SK_API SkRuntimeEffect : public SkRefCnt { kSamplesOutsideMain_Flag = 0x10, kUsesColorTransform_Flag = 0x20, kAlwaysOpaque_Flag = 0x40, + kAlphaUnchanged_Flag = 0x80, }; SkRuntimeEffect(std::unique_ptr baseProgram, @@ -301,15 +309,17 @@ class SK_API SkRuntimeEffect : public SkRefCnt { bool samplesOutsideMain() const { return (fFlags & kSamplesOutsideMain_Flag); } bool usesColorTransform() const { return (fFlags & kUsesColorTransform_Flag); } bool alwaysOpaque() const { return (fFlags & kAlwaysOpaque_Flag); } + bool isAlphaUnchanged() const { return (fFlags & kAlphaUnchanged_Flag); } const SkFilterColorProgram* getFilterColorProgram() const; + const SkSL::RP::Program* getRPProgram(SkSL::DebugTracePriv* debugTrace) const; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) friend class GrSkSLFP; // fBaseProgram, fSampleUsages friend class GrGLSLSkSLFP; // #endif - friend class SkRTShader; // fBaseProgram, fMain + friend class SkRTShader; // fBaseProgram, fMain, fSampleUsages, getRPProgram() friend class SkRuntimeBlender; // friend class SkRuntimeColorFilter; // @@ -319,6 +329,8 @@ class SK_API SkRuntimeEffect : public SkRefCnt { uint32_t fHash; std::unique_ptr fBaseProgram; + std::unique_ptr fRPProgram; + mutable SkOnce fCompileRPProgramOnce; const SkSL::FunctionDefinition& fMain; std::vector fUniforms; std::vector fChildren; @@ -415,6 +427,11 @@ class SkRuntimeEffectBuilder { BuilderUniform uniform(std::string_view name) { return { this, fEffect->findUniform(name) }; } BuilderChild child(std::string_view name) { return { this, fEffect->findChild(name) }; } + // Get access to the collated uniforms and children (in the order expected by APIs like + // makeShader on the effect): + sk_sp uniforms() { return fUniforms; } + SkSpan children() { return fChildren; } + protected: SkRuntimeEffectBuilder() = delete; explicit SkRuntimeEffectBuilder(sk_sp effect) @@ -432,10 +449,6 @@ class SkRuntimeEffectBuilder { SkRuntimeEffectBuilder& operator=(SkRuntimeEffectBuilder&&) = delete; SkRuntimeEffectBuilder& operator=(const SkRuntimeEffectBuilder&) = delete; - sk_sp uniforms() { return fUniforms; } - SkRuntimeEffect::ChildPtr* children() { return fChildren.data(); } - size_t numChildren() { return fChildren.size(); } - private: void* writableUniformData() { if (!fUniforms->unique()) { @@ -492,6 +505,23 @@ class SK_API SkRuntimeShaderBuilder : public SkRuntimeEffectBuilder { friend class SkRuntimeImageFilter; }; +/** + * SkRuntimeColorFilterBuilder makes it easy to setup and assign uniforms to runtime color filters. + */ +class SK_API SkRuntimeColorFilterBuilder : public SkRuntimeEffectBuilder { +public: + explicit SkRuntimeColorFilterBuilder(sk_sp); + ~SkRuntimeColorFilterBuilder(); + + SkRuntimeColorFilterBuilder(const SkRuntimeColorFilterBuilder&) = delete; + SkRuntimeColorFilterBuilder& operator=(const SkRuntimeColorFilterBuilder&) = delete; + + sk_sp makeColorFilter(); + +private: + using INHERITED = SkRuntimeEffectBuilder; +}; + /** * SkRuntimeBlendBuilder is a utility to simplify creation and uniform setup of runtime blenders. */ diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h index 657b9a98a96c7..8f76e8016c848 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h @@ -9,8 +9,12 @@ #define SkEncoder_DEFINED #include "include/core/SkPixmap.h" -#include "include/private/SkNoncopyable.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkNoncopyable.h" +#include "include/private/base/SkTemplates.h" + +#include +#include class SK_API SkEncoder : SkNoncopyable { public: @@ -53,7 +57,7 @@ class SK_API SkEncoder : SkNoncopyable { const SkPixmap& fSrc; int fCurrRow; - SkAutoTMalloc fStorage; + skia_private::AutoTMalloc fStorage; }; #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h new file mode 100644 index 0000000000000..b14836b2ab6aa --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h @@ -0,0 +1,36 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkICC_DEFINED +#define SkICC_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" + +#include + +class SkData; +struct skcms_ICCProfile; +struct skcms_Matrix3x3; +struct skcms_TransferFunction; + +SK_API sk_sp SkWriteICCProfile(const skcms_TransferFunction&, + const skcms_Matrix3x3& toXYZD50); + +SK_API sk_sp SkWriteICCProfile(const skcms_ICCProfile*, const char* description); + +// Utility function for populating the grid_16 member of skcms_A2B and skcms_B2A +// structures. This converts a point in XYZD50 to its representation in grid_16_lab. +// It will write 6 bytes. The behavior of this function matches how skcms will decode +// values, but might not match the specification, see https://crbug.com/skia/13807. +SK_API void SkICCFloatXYZD50ToGrid16Lab(const float* float_xyz, uint8_t* grid16_lab); + +// Utility function for popluating the table_16 member of skcms_Curve structure. +// This converts a float to its representation in table_16. It will write 2 bytes. +SK_API void SkICCFloatToTable16(const float f, uint8_t* table_16); + +#endif//SkICC_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h index f2107f1263a38..f7e8effa7fa5b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h @@ -8,90 +8,121 @@ #ifndef SkJpegEncoder_DEFINED #define SkJpegEncoder_DEFINED -#include "include/encode/SkEncoder.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" -class SkJpegEncoderMgr; +#include + +class SkColorSpace; +class SkData; +class SkEncoder; +class SkPixmap; class SkWStream; +class SkImage; +class GrDirectContext; +class SkYUVAPixmaps; +struct skcms_ICCProfile; + +namespace SkJpegEncoder { -class SK_API SkJpegEncoder : public SkEncoder { -public: - - enum class AlphaOption { - kIgnore, - kBlendOnBlack, - }; - - enum class Downsample { - /** - * Reduction by a factor of two in both the horizontal and vertical directions. - */ - k420, - - /** - * Reduction by a factor of two in the horizontal direction. - */ - k422, - - /** - * No downsampling. - */ - k444, - }; - - struct Options { - /** - * |fQuality| must be in [0, 100] where 0 corresponds to the lowest quality. - */ - int fQuality = 100; - - /** - * Choose the downsampling factor for the U and V components. This is only - * meaningful if the |src| is not kGray, since kGray will not be encoded as YUV. - * - * Our default value matches the libjpeg-turbo default. - */ - Downsample fDownsample = Downsample::k420; - - /** - * Jpegs must be opaque. This instructs the encoder on how to handle input - * images with alpha. - * - * The default is to ignore the alpha channel and treat the image as opaque. - * Another option is to blend the pixels onto a black background before encoding. - * In the second case, the encoder supports linear or legacy blending. - */ - AlphaOption fAlphaOption = AlphaOption::kIgnore; - }; +enum class AlphaOption { + kIgnore, + kBlendOnBlack, +}; +enum class Downsample { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * Reduction by a factor of two in both the horizontal and vertical directions. */ - static bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + k420, /** - * Create a jpeg encoder that will encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * |dst| is unowned but must remain valid for the lifetime of the object. - * - * This returns nullptr on an invalid or unsupported |src|. + * Reduction by a factor of two in the horizontal direction. */ - static std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, - const Options& options); + k422, - ~SkJpegEncoder() override; + /** + * No downsampling. + */ + k444, +}; + +struct Options { + /** + * |fQuality| must be in [0, 100] where 0 corresponds to the lowest quality. + */ + int fQuality = 100; + + /** + * Choose the downsampling factor for the U and V components. This is only + * meaningful if the |src| is not kGray, since kGray will not be encoded as YUV. + * This is ignored in favor of |src|'s subsampling when |src| is an SkYUVAPixmaps. + * + * Our default value matches the libjpeg-turbo default. + */ + Downsample fDownsample = Downsample::k420; -protected: - bool onEncodeRows(int numRows) override; + /** + * Jpegs must be opaque. This instructs the encoder on how to handle input + * images with alpha. + * + * The default is to ignore the alpha channel and treat the image as opaque. + * Another option is to blend the pixels onto a black background before encoding. + * In the second case, the encoder supports linear or legacy blending. + */ + AlphaOption fAlphaOption = AlphaOption::kIgnore; -private: - SkJpegEncoder(std::unique_ptr, const SkPixmap& src); + /** + * Optional XMP metadata. + */ + const SkData* xmpMetadata = nullptr; - std::unique_ptr fEncoderMgr; - using INHERITED = SkEncoder; + /** + * An optional ICC profile to override the default behavior. + * + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. + */ + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; }; +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); +SK_API bool Encode(SkWStream* dst, + const SkYUVAPixmaps& src, + const SkColorSpace* srcColorSpace, + const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Create a jpeg encoder that will encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * |dst| is unowned but must remain valid for the lifetime of the object. + * + * This returns nullptr on an invalid or unsupported |src|. + */ +SK_API std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, const Options& options); +SK_API std::unique_ptr Make(SkWStream* dst, + const SkYUVAPixmaps& src, + const SkColorSpace* srcColorSpace, + const Options& options); +} // namespace SkJpegEncoder + #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h index ccfa292f747d7..b26befa323ef3 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h @@ -9,91 +9,109 @@ #define SkPngEncoder_DEFINED #include "include/core/SkDataTable.h" -#include "include/encode/SkEncoder.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" -class SkPngEncoderMgr; +// TODO(kjlubick) update clients to directly include this +#include "include/encode/SkEncoder.h" // IWYU pragma: keep + +#include + +class GrDirectContext; +class SkData; +class SkImage; +class SkPixmap; class SkWStream; +struct skcms_ICCProfile; + +namespace SkPngEncoder { + +enum class FilterFlag : int { + kZero = 0x00, + kNone = 0x08, + kSub = 0x10, + kUp = 0x20, + kAvg = 0x40, + kPaeth = 0x80, + kAll = kNone | kSub | kUp | kAvg | kPaeth, +}; -class SK_API SkPngEncoder : public SkEncoder { -public: - - enum class FilterFlag : int { - kZero = 0x00, - kNone = 0x08, - kSub = 0x10, - kUp = 0x20, - kAvg = 0x40, - kPaeth = 0x80, - kAll = kNone | kSub | kUp | kAvg | kPaeth, - }; - - struct Options { - /** - * Selects which filtering strategies to use. - * - * If a single filter is chosen, libpng will use that filter for every row. - * - * If multiple filters are chosen, libpng will use a heuristic to guess which filter - * will encode smallest, then apply that filter. This happens on a per row basis, - * different rows can use different filters. - * - * Using a single filter (or less filters) is typically faster. Trying all of the - * filters may help minimize the output file size. - * - * Our default value matches libpng's default. - */ - FilterFlag fFilterFlags = FilterFlag::kAll; - - /** - * Must be in [0, 9] where 9 corresponds to maximal compression. This value is passed - * directly to zlib. 0 is a special case to skip zlib entirely, creating dramatically - * larger pngs. - * - * Our default value matches libpng's default. - */ - int fZLibLevel = 6; - - /** - * Represents comments in the tEXt ancillary chunk of the png. - * The 2i-th entry is the keyword for the i-th comment, - * and the (2i + 1)-th entry is the text for the i-th comment. - */ - sk_sp fComments; - }; +inline FilterFlag operator|(FilterFlag x, FilterFlag y) { return (FilterFlag)((int)x | (int)y); } +struct Options { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * Selects which filtering strategies to use. + * + * If a single filter is chosen, libpng will use that filter for every row. + * + * If multiple filters are chosen, libpng will use a heuristic to guess which filter + * will encode smallest, then apply that filter. This happens on a per row basis, + * different rows can use different filters. + * + * Using a single filter (or less filters) is typically faster. Trying all of the + * filters may help minimize the output file size. * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * Our default value matches libpng's default. */ - static bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + FilterFlag fFilterFlags = FilterFlag::kAll; /** - * Create a png encoder that will encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * Must be in [0, 9] where 9 corresponds to maximal compression. This value is passed + * directly to zlib. 0 is a special case to skip zlib entirely, creating dramatically + * larger pngs. * - * |dst| is unowned but must remain valid for the lifetime of the object. - * - * This returns nullptr on an invalid or unsupported |src|. + * Our default value matches libpng's default. */ - static std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, - const Options& options); - - ~SkPngEncoder() override; - -protected: - bool onEncodeRows(int numRows) override; + int fZLibLevel = 6; - SkPngEncoder(std::unique_ptr, const SkPixmap& src); + /** + * Represents comments in the tEXt ancillary chunk of the png. + * The 2i-th entry is the keyword for the i-th comment, + * and the (2i + 1)-th entry is the text for the i-th comment. + */ + sk_sp fComments; - std::unique_ptr fEncoderMgr; - using INHERITED = SkEncoder; + /** + * An optional ICC profile to override the default behavior. + * + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. + */ + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; }; -static inline SkPngEncoder::FilterFlag operator|(SkPngEncoder::FilterFlag x, - SkPngEncoder::FilterFlag y) { - return (SkPngEncoder::FilterFlag)((int)x | (int)y); -} +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Create a png encoder that will encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * The primary use of this is incremental encoding of the pixels. + * + * |dst| is unowned but must remain valid for the lifetime of the object. + * + * This returns nullptr on an invalid or unsupported |src|. + */ +SK_API std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, const Options& options); + +} // namespace SkPngEncoder #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h index 1930e4099f84a..fe11044e73804 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h @@ -8,58 +8,85 @@ #ifndef SkWebpEncoder_DEFINED #define SkWebpEncoder_DEFINED -#include "include/core/SkSpan.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSpan.h" // IWYU pragma: keep #include "include/encode/SkEncoder.h" +#include "include/private/base/SkAPI.h" +class SkPixmap; class SkWStream; +class SkData; +class GrDirectContext; +class SkImage; +struct skcms_ICCProfile; namespace SkWebpEncoder { - enum class Compression { - kLossy, - kLossless, - }; - - struct SK_API Options { - /** - * |fCompression| determines whether we will use webp lossy or lossless compression. - * - * |fQuality| must be in [0.0f, 100.0f]. - * If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the - * encoding. Decreasing the quality will result in a smaller encoded image. - * If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort - * put into the encoding. Lower values will compress faster into larger files, - * while larger values will compress slower into smaller files. - * - * This scheme is designed to match the libwebp API. - */ - Compression fCompression = Compression::kLossy; - float fQuality = 100.0f; - }; +enum class Compression { + kLossy, + kLossless, +}; +struct SK_API Options { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * |fCompression| determines whether we will use webp lossy or lossless compression. + * + * |fQuality| must be in [0.0f, 100.0f]. + * If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the + * encoding. Decreasing the quality will result in a smaller encoded image. + * If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort + * put into the encoding. Lower values will compress faster into larger files, + * while larger values will compress slower into smaller files. * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * This scheme is designed to match the libwebp API. */ - SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + Compression fCompression = Compression::kLossy; + float fQuality = 100.0f; /** - * Encode the |src| frames to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * The size of the first frame will be used as the canvas size. If any other frame does - * not match the canvas size, this is an error. - * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * An optional ICC profile to override the default behavior. * - * Note: libwebp API also supports set background color, loop limit and customize - * lossy/lossless for each frame. These could be added later as needed. + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. */ - SK_API bool EncodeAnimated(SkWStream* dst, - SkSpan src, - const Options& options); + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; +}; + +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Encode the |src| frames to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * The size of the first frame will be used as the canvas size. If any other frame does + * not match the canvas size, this is an error. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + * + * Note: libwebp API also supports set background color, loop limit and customize + * lossy/lossless for each frame. These could be added later as needed. + */ +SK_API bool EncodeAnimated(SkWStream* dst, + SkSpan src, + const Options& options); } // namespace SkWebpEncoder #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h index 2eb88a8d433ce..e2e3961f8b9e5 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h @@ -26,16 +26,29 @@ enum class BackendApi : unsigned { kMock, }; +/** Indicates whether an allocation should count against a cache budget. */ +enum class Budgeted : bool { + kNo = false, + kYes = true, +}; + /** * Value passed into various callbacks to tell the client the result of operations connected to a * specific callback. The actual interpretation of kFailed and kSuccess are dependent on the * specific callbacks and are documented with the callback itself. */ enum class CallbackResult : bool { - kFailed = true, + kFailed = false, kSuccess = true, }; +/** + * Is the texture mipmapped or not + */ +enum class Mipmapped : bool { + kNo = false, + kYes = true, +}; /** * Is the data protected on the GPU or not. @@ -45,6 +58,15 @@ enum class Protected : bool { kYes = true, }; +/** + * Is a texture renderable or not + */ +enum class Renderable : bool { + kNo = false, + kYes = true, +}; + } // namespace skgpu + #endif // skgpu_GpuTypes_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h index 759cc1d39837a..37ab666d52ec4 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h @@ -35,6 +35,7 @@ class GrVkImageLayout; class GrGLTextureParameters; class GrColorFormatDesc; +enum class SkTextureCompressionType; namespace skgpu { class MutableTextureStateRef; @@ -57,7 +58,7 @@ class GrD3DResourceState; class SkString; #endif -#if !SK_SUPPORT_GPU +#if !defined(SK_GANESH) // SkSurfaceCharacterization always needs a minimal version of this class SK_API GrBackendFormat { @@ -124,7 +125,8 @@ class SK_API GrBackendFormat { } #endif - static GrBackendFormat MakeMock(GrColorType colorType, SkImage::CompressionType compression, + static GrBackendFormat MakeMock(GrColorType colorType, + SkTextureCompressionType compression, bool isStencilFormat = false); bool operator==(const GrBackendFormat& that) const; @@ -191,7 +193,7 @@ class SK_API GrBackendFormat { * kUnknown, the compression type is not kNone, or this is a mock stencil format. */ GrColorType asMockColorType() const; - SkImage::CompressionType asMockCompressionType() const; + SkTextureCompressionType asMockCompressionType() const; bool isMockStencilFormat() const; // If possible, copies the GrBackendFormat and forces the texture type to be Texture2D. If the @@ -228,7 +230,7 @@ class SK_API GrBackendFormat { GrBackendFormat(DXGI_FORMAT dxgiFormat); #endif - GrBackendFormat(GrColorType, SkImage::CompressionType, bool isStencilFormat); + GrBackendFormat(GrColorType, SkTextureCompressionType, bool isStencilFormat); #ifdef SK_DEBUG bool validateMock() const; @@ -259,9 +261,9 @@ class SK_API GrBackendFormat { DXGI_FORMAT fDxgiFormat; #endif struct { - GrColorType fColorType; - SkImage::CompressionType fCompressionType; - bool fIsStencilFormat; + GrColorType fColorType; + SkTextureCompressionType fCompressionType; + bool fIsStencilFormat; } fMock; }; GrTextureType fTextureType = GrTextureType::kNone; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h deleted file mode 100644 index 9fe6629dd7ead..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h +++ /dev/null @@ -1,53 +0,0 @@ - -/* - * Copyright 2010 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrConfig_DEFINED -#define GrConfig_DEFINED - -#include "include/core/SkTypes.h" - -/** - * Gr defines are set to 0 or 1, rather than being undefined or defined - */ - -#if !defined(GR_CACHE_STATS) - #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) - #define GR_CACHE_STATS 1 - #else - #define GR_CACHE_STATS 0 - #endif -#endif - -#if !defined(GR_GPU_STATS) - #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || GR_TEST_UTILS - #define GR_GPU_STATS 1 - #else - #define GR_GPU_STATS 0 - #endif -#endif - -#endif - -/** - * GR_STRING makes a string of X where X is expanded before conversion to a string - * if X itself contains macros. - */ -#define GR_STRING(X) GR_STRING_IMPL(X) -#define GR_STRING_IMPL(X) #X - -/** - * GR_CONCAT concatenates X and Y where each is expanded before - * contanenation if either contains macros. - */ -#define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y) -#define GR_CONCAT_IMPL(X,Y) X##Y - -/** - * Creates a string of the form "() : " - */ -#define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : " diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h index 28675297a1331..bf4ca409a8f6d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h @@ -20,7 +20,7 @@ class SkExecutor; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) struct SK_API GrContextOptions { enum class Enable { /** Forces an option to be disabled. */ @@ -80,8 +80,9 @@ struct SK_API GrContextOptions { /** * Controls whether we check for GL errors after functions that allocate resources (e.g. - * glTexImage2D), for shader compilation success, and program link success. Ignored on - * backends other than GL. + * glTexImage2D), at the end of a GPU submission, or checking framebuffer completeness. The + * results of shader compilation and program linking are always checked, regardless of this + * option. Ignored on backends other than GL. */ Enable fSkipGLErrorChecks = Enable::kDefault; @@ -244,6 +245,12 @@ struct SK_API GrContextOptions { */ bool fSuppressMipmapSupport = false; + /** + * If true, the TessellationPathRenderer will not be used for path rendering. + * If false, will fallback to any driver workarounds, if set. + */ + bool fDisableTessellationPathRenderer = false; + /** * If true, and if supported, enables hardware tessellation in the caps. * DEPRECATED: This value is ignored; experimental hardware tessellation is always disabled. @@ -254,13 +261,7 @@ struct SK_API GrContextOptions { * If true, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp * rendering of all glyphs. This must be set to true to use Slugs. */ - #if defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_STRIKE_SERIALIZE) - bool fSupportBilerpFromGlyphAtlas = true; - #else bool fSupportBilerpFromGlyphAtlas = false; - #endif /** * Uses a reduced variety of shaders. May perform less optimally in steady state but can reduce @@ -273,6 +274,24 @@ struct SK_API GrContextOptions { */ bool fAllowMSAAOnNewIntel = false; + /** + * Currently on ARM Android we disable the use of GL TexStorage because of memory regressions. + * However, some clients may still want to use TexStorage. For example, TexStorage support is + * required for creating protected textures. + * + * This flag has no impact on non GL backends. + */ + bool fAlwaysUseTexStorageWhenAvailable = false; + + /** + * Optional callback that can be passed into the GrDirectContext which will be called when the + * GrDirectContext is about to be destroyed. When this call is made, it will be safe for the + * client to delete the GPU backend context that is backing the GrDirectContext. The + * GrDirectContextDestroyedContext will be passed back to the client in the callback. + */ + GrDirectContextDestroyedContext fContextDeleteContext = nullptr; + GrDirectContextDestroyedProc fContextDeleteProc = nullptr; + #if GR_TEST_UTILS /** * Private options that are only meant for testing within Skia's tools. diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h index 7e1ee65ffcdd5..eb755553647b9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h @@ -10,9 +10,10 @@ #include "include/core/SkRefCnt.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/core/SkImageInfo.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/GrContextOptions.h" #include "include/gpu/GrTypes.h" @@ -25,6 +26,7 @@ class GrThreadSafeCache; class GrThreadSafePipelineBuilder; class SkSurfaceCharacterization; class SkSurfaceProps; +enum class SkTextureCompressionType; namespace sktext::gpu { class TextBlobRedrawCoordinator; } @@ -107,13 +109,13 @@ class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt fAbandoned{false}; }; -#else // !SK_SUPPORT_GPU +#else // !defined(SK_GANESH) class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt {}; #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h index 903623fb7161d..a22fc4fe5784c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h @@ -8,46 +8,52 @@ #ifndef GrDirectContext_DEFINED #define GrDirectContext_DEFINED +#include "include/core/SkColor.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" +#include "include/gpu/GpuTypes.h" +#include "include/gpu/GrContextOptions.h" #include "include/gpu/GrRecordingContext.h" +#include "include/gpu/GrTypes.h" -#include "include/gpu/GrBackendSurface.h" - -// We shouldn't need this but currently Android is relying on this being include transitively. -#include "include/core/SkUnPreMultiply.h" +#include +#include +#include +#include +#include class GrAtlasManager; class GrBackendSemaphore; +class GrBackendFormat; +class GrBackendTexture; +class GrBackendRenderTarget; class GrClientMappedBufferManager; -class GrDirectContextPriv; class GrContextThreadSafeProxy; -struct GrD3DBackendContext; -class GrFragmentProcessor; +class GrDirectContextPriv; class GrGpu; -struct GrGLInterface; -struct GrMtlBackendContext; -struct GrMockOptions; -class GrPath; class GrResourceCache; class GrResourceProvider; -class GrSurfaceProxy; -class GrTextureProxy; -struct GrVkBackendContext; - +class SkData; class SkImage; -class SkString; -class SkSurfaceCharacterization; -class SkSurfaceProps; +class SkPixmap; class SkTaskGroup; class SkTraceMemoryDump; +enum SkColorType : int; +enum class SkTextureCompressionType; +struct GrGLInterface; +struct GrMockOptions; +struct GrVkBackendContext; // IWYU pragma: keep +struct GrD3DBackendContext; // IWYU pragma: keep +struct GrMtlBackendContext; // IWYU pragma: keep namespace skgpu { -class Swizzle; -namespace v1 { class SmallPathAtlasMgr; } -} - -namespace sktext::gpu { -class StrikeCache; + class MutableTextureState; +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + namespace ganesh { class SmallPathAtlasMgr; } +#endif } +namespace sktext { namespace gpu { class StrikeCache; } } +namespace wgpu { class Device; } // IWYU pragma: keep class SK_API GrDirectContext : public GrRecordingContext { public: @@ -387,7 +393,24 @@ class SK_API GrDirectContext : public GrRecordingContext { */ GrSemaphoresSubmitted flush(const GrFlushInfo& info); - void flush() { this->flush({}); } + void flush() { this->flush(GrFlushInfo()); } + + /** Flushes any pending uses of texture-backed images in the GPU backend. If the image is not + * texture-backed (including promise texture images) or if the GrDirectContext does not + * have the same context ID as the context backing the image then this is a no-op. + * If the image was not used in any non-culled draws in the current queue of work for the + * passed GrDirectContext then this is a no-op unless the GrFlushInfo contains semaphores or + * a finish proc. Those are respected even when the image has not been used. + * @param image the non-null image to flush. + * @param info flush options + */ + GrSemaphoresSubmitted flush(sk_sp image, const GrFlushInfo& info); + void flush(sk_sp image); + + /** Version of flush() that uses a default GrFlushInfo. Also submits the flushed work to the + GPU. + */ + void flushAndSubmit(sk_sp image); /** * Submit outstanding work to the gpu from all previously un-submitted flushes. The return @@ -548,10 +571,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(&srcData, 1, textureOrigin, renderable, isProtected, - finishedProc, finishedContext, label); - } + std::string_view label = {}); // Deprecated versions that do not take origin and assume top-left. GrBackendTexture createBackendTexture(const SkPixmap srcData[], @@ -560,30 +580,14 @@ class SK_API GrDirectContext : public GrRecordingContext { GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(srcData, - numLevels, - kTopLeft_GrSurfaceOrigin, - renderable, - isProtected, - finishedProc, - finishedContext, - label); - } + std::string_view label = {}); + GrBackendTexture createBackendTexture(const SkPixmap& srcData, GrRenderable renderable, GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(&srcData, - 1, - renderable, - isProtected, - finishedProc, - finishedContext, - label); - } + std::string_view label = {}); /** * If possible, updates a backend texture to be filled to a particular color. The client should @@ -662,17 +666,10 @@ class SK_API GrDirectContext : public GrRecordingContext { const SkPixmap srcData[], int numLevels, GrGpuFinishedProc finishedProc, - GrGpuFinishedContext finishedContext) { - return this->updateBackendTexture(texture, - srcData, - numLevels, - kTopLeft_GrSurfaceOrigin, - finishedProc, - finishedContext); - } + GrGpuFinishedContext finishedContext); /** - * Retrieve the GrBackendFormat for a given SkImage::CompressionType. This is + * Retrieve the GrBackendFormat for a given SkTextureCompressionType. This is * guaranteed to match the backend format used by the following * createCompressedBackendTexture methods that take a CompressionType. * @@ -698,7 +695,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrGpuFinishedContext finishedContext = nullptr); GrBackendTexture createCompressedBackendTexture(int width, int height, - SkImage::CompressionType, + SkTextureCompressionType, const SkColor4f& color, GrMipmapped, GrProtected = GrProtected::kNo, @@ -726,7 +723,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrGpuFinishedContext finishedContext = nullptr); GrBackendTexture createCompressedBackendTexture(int width, int height, - SkImage::CompressionType, + SkTextureCompressionType, const void* data, size_t dataSize, GrMipmapped, GrProtected = GrProtected::kNo, @@ -850,7 +847,9 @@ class SK_API GrDirectContext : public GrRecordingContext { bool init() override; GrAtlasManager* onGetAtlasManager() { return fAtlasManager.get(); } - skgpu::v1::SmallPathAtlasMgr* onGetSmallPathAtlasMgr(); +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + skgpu::ganesh::SmallPathAtlasMgr* onGetSmallPathAtlasMgr(); +#endif GrDirectContext* asDirectContext() override { return this; } @@ -868,6 +867,28 @@ class SK_API GrDirectContext : public GrRecordingContext { // bool is used for this signal. void syncAllOutstandingGpuWork(bool shouldExecuteWhileAbandoned); + // This delete callback needs to be the first thing on the GrDirectContext so that it is the + // last thing destroyed. The callback may signal the client to clean up things that may need + // to survive the lifetime of some of the other objects on the GrDirectCotnext. So make sure + // we don't call it until all else has been destroyed. + class DeleteCallbackHelper { + public: + DeleteCallbackHelper(GrDirectContextDestroyedContext context, + GrDirectContextDestroyedProc proc) + : fContext(context), fProc(proc) {} + + ~DeleteCallbackHelper() { + if (fProc) { + fProc(fContext); + } + } + + private: + GrDirectContextDestroyedContext fContext; + GrDirectContextDestroyedProc fProc; + }; + std::unique_ptr fDeleteCallbackHelper; + const DirectContextID fDirectContextID; // fTaskGroup must appear before anything that uses it (e.g. fGpu), so that it is destroyed // after all of its users. Clients of fTaskGroup will generally want to ensure that they call @@ -894,11 +915,11 @@ class SK_API GrDirectContext : public GrRecordingContext { std::unique_ptr fMappedBufferManager; std::unique_ptr fAtlasManager; - std::unique_ptr fSmallPathAtlasMgr; +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + std::unique_ptr fSmallPathAtlasMgr; +#endif friend class GrDirectContextPriv; - - using INHERITED = GrRecordingContext; }; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h index c57efc6016586..1aa995c79177a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h @@ -13,7 +13,8 @@ #ifdef SK_GPU_WORKAROUNDS_HEADER #include SK_GPU_WORKAROUNDS_HEADER #else -// To regenerate this file, set gn arg "skia_generate_workarounds = true". +// To regenerate this file, set gn arg "skia_generate_workarounds = true" +// or invoke `bazel run //tools:generate_workarounds` // This is not rebuilt by default to avoid embedders having to have extra // build steps. #include "include/gpu/GrDriverBugWorkaroundsAutogen.h" diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h index f8b9c3f39230a..85cc77c051c8f 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h @@ -9,7 +9,8 @@ #define GrRecordingContext_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkTArray.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkTArray.h" #include "include/private/gpu/ganesh/GrImageContext.h" #if GR_GPU_STATS && GR_TEST_UTILS @@ -190,7 +191,7 @@ class GrRecordingContext : public GrImageContext { // of the programInfos matches the intended use. For example, in DDL-record mode it // is known that all the programInfos will have been allocated in an arena with the // same lifetime at the DDL itself. - virtual void detachProgramData(SkTArray*) {} + virtual void detachProgramData(skia_private::TArray*) {} sktext::gpu::TextBlobRedrawCoordinator* getTextBlobRedrawCoordinator(); const sktext::gpu::TextBlobRedrawCoordinator* getTextBlobRedrawCoordinator() const; @@ -223,7 +224,8 @@ class GrRecordingContext : public GrImageContext { #if GR_TEST_UTILS void dump(SkString* out) const; - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const; + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const; #endif private: @@ -236,14 +238,16 @@ class GrRecordingContext : public GrImageContext { #if GR_TEST_UTILS void dump(SkString*) const {} - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const {} + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const {} #endif #endif // GR_GPU_STATS } fStats; #if GR_GPU_STATS && GR_TEST_UTILS struct DMSAAStats { - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const; + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const; void dump() const; void merge(const DMSAAStats&); int fNumRenderPasses = 0; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h index f8895345d658a..177a35a9437f9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h @@ -8,13 +8,18 @@ #ifndef GrTypes_DEFINED #define GrTypes_DEFINED -#include "include/core/SkMath.h" #include "include/core/SkTypes.h" -#include "include/gpu/GrConfig.h" +#include "include/private/base/SkTo.h" // IWYU pragma: keep +#include +#include class GrBackendSemaphore; -class SkImage; -class SkSurface; + +namespace skgpu { +enum class Mipmapped : bool; +enum class Protected : bool; +enum class Renderable : bool; +} //////////////////////////////////////////////////////////////////////////////// @@ -122,28 +127,20 @@ static constexpr GrBackendApi kMock_GrBackend = GrBackendApi::kMock; /** * Used to say whether a texture has mip levels allocated or not. */ -enum class GrMipmapped : bool { - kNo = false, - kYes = true -}; -/** Deprecated legacy alias of GrMipmapped. */ -using GrMipMapped = GrMipmapped; +/** Deprecated legacy alias of skgpu::Mipmapped. */ +using GrMipmapped = skgpu::Mipmapped; +/** Deprecated legacy alias of skgpu::Mipmapped. */ +using GrMipMapped = skgpu::Mipmapped; /* * Can a GrBackendObject be rendered to? */ -enum class GrRenderable : bool { - kNo = false, - kYes = true -}; +using GrRenderable = skgpu::Renderable; /* * Used to say whether texture is backed by protected memory. */ -enum class GrProtected : bool { - kNo = false, - kYes = true -}; +using GrProtected = skgpu::Protected; /////////////////////////////////////////////////////////////////////////////// @@ -188,6 +185,9 @@ typedef void (*GrGpuFinishedProc)(GrGpuFinishedContext finishedContext); typedef void* GrGpuSubmittedContext; typedef void (*GrGpuSubmittedProc)(GrGpuSubmittedContext submittedContext, bool success); +typedef void* GrDirectContextDestroyedContext; +typedef void (*GrDirectContextDestroyedProc)(GrDirectContextDestroyedContext destroyedContext); + /** * Struct to supply options to flush calls. * diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h index d2e890f780a1f..b595422e8692a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h @@ -22,7 +22,7 @@ // prepared to rename those identifiers. #include "include/core/SkRefCnt.h" -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include #include @@ -184,7 +184,7 @@ struct GrD3DTextureResourceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; unsigned int fSampleQualityPattern = DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrD3DTextureResourceInfo() = default; @@ -195,7 +195,7 @@ struct GrD3DTextureResourceInfo { uint32_t sampleCount, uint32_t levelCount, unsigned int sampleQualityLevel, - GrProtected isProtected = GrProtected::kNo) + skgpu::Protected isProtected = skgpu::Protected::kNo) : fResource(resource) , fAlloc(alloc) , fResourceState(resourceState) @@ -239,7 +239,7 @@ struct GrD3DFenceInfo { struct GrD3DSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; DXGI_FORMAT fFormat = DXGI_FORMAT_UNKNOWN; unsigned int fSampleQualityPattern = DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h index 70a2f9f6d6c5d..fbd3dbaf55cb1 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h @@ -8,7 +8,7 @@ #ifndef GrDawnTypes_DEFINED #define GrDawnTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #ifdef Always #undef Always @@ -22,7 +22,7 @@ static constexpr int Success = 0; #undef None static constexpr int None = 0L; #endif -#include "webgpu/webgpu_cpp.h" +#include "webgpu/webgpu_cpp.h" // IWYU pragma: export struct GrDawnTextureInfo { wgpu::Texture fTexture; @@ -87,7 +87,7 @@ struct GrDawnRenderTargetInfo { struct GrDawnSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; wgpu::TextureFormat fFormat; }; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h new file mode 100644 index 0000000000000..68f13ce4b5119 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h @@ -0,0 +1,77 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrTextureGenerator_DEFINED +#define GrTextureGenerator_DEFINED + +#include "include/core/SkImageGenerator.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GrTypes.h" +#include "include/private/base/SkAPI.h" + +#include +#include + +class GrRecordingContext; +class GrSurfaceProxyView; +class SkImage; +enum class GrImageTexGenPolicy : int; +namespace skgpu { enum class Mipmapped : bool; } +struct SkImageInfo; + +class SK_API GrTextureGenerator : public SkImageGenerator { +public: + bool isTextureGenerator() const final { return true; } + + /** + * If the generator can natively/efficiently return its pixels as a GPU image (backed by a + * texture) this will return that image. If not, this will return NULL. + * + * Regarding the GrRecordingContext parameter: + * + * It must be non-NULL. The generator should only succeed if: + * - its internal context is the same + * - it can somehow convert its texture into one that is valid for the provided context. + * + * If the mipmapped parameter is kYes, the generator should try to create a TextureProxy that + * at least has the mip levels allocated and the base layer filled in. If this is not possible, + * the generator is allowed to return a non mipped proxy, but this will have some additional + * overhead in later allocating mips and copying of the base layer. + * + * GrImageTexGenPolicy determines whether or not a new texture must be created (and its budget + * status) or whether this may (but is not required to) return a pre-existing texture that is + * retained by the generator (kDraw). + */ + GrSurfaceProxyView generateTexture(GrRecordingContext*, + const SkImageInfo& info, + skgpu::Mipmapped mipmapped, + GrImageTexGenPolicy); + + virtual GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&, + skgpu::Mipmapped, GrImageTexGenPolicy) = 0; + + // Most internal SkImageGenerators produce textures and views that use kTopLeft_GrSurfaceOrigin. + // If the generator may produce textures with different origins (e.g. + // GrAHardwareBufferImageGenerator) it should override this function to return the correct + // origin. Implementations should be thread-safe. + virtual GrSurfaceOrigin origin() const { return kTopLeft_GrSurfaceOrigin; } + +protected: + GrTextureGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID); +}; + +namespace SkImages { +/** + * Like SkImages::DeferredFromGenerator except allows for the use of SkGaneshTextureGenerator. + * + * @param gen producer of textures + * @return created SkImage, or nullptr + */ +SK_API sk_sp DeferredFromTextureGenerator(std::unique_ptr gen); +} + +#endif // GrTextureGenerator_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h new file mode 100644 index 0000000000000..296d90d17e3f9 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h @@ -0,0 +1,385 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkImageGanesh_DEFINED +#define SkImageGanesh_DEFINED + +#include "include/core/SkImage.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GpuTypes.h" +#include "include/gpu/GrTypes.h" +#include "include/private/base/SkAPI.h" + +#include +#include + +class GrBackendFormat; +class GrBackendTexture; +class GrContextThreadSafeProxy; +class GrDirectContext; +class GrRecordingContext; +class GrYUVABackendTextureInfo; +class GrYUVABackendTextures; +class SkColorSpace; +class SkData; +class SkPixmap; +class SkPromiseImageTexture; +class SkYUVAPixmaps; +enum SkAlphaType : int; +enum SkColorType : int; +enum class SkTextureCompressionType; +struct SkISize; + +/** + * All factories in this file refer to the Ganesh GPU backend when they say GPU. + */ + +namespace SkImages { +/** Defines a callback function, taking one parameter of type GrBackendTexture with + no return value. Function is called when backend texture is to be released. +*/ +using BackendTextureReleaseProc = std::function; +/** User function called when supplied texture may be deleted. */ +using TextureReleaseProc = void (*)(ReleaseContext); + +/** Creates GPU-backed SkImage from backendTexture associated with context. + Skia will assume ownership of the resource and will release it when no longer needed. + A non-null SkImage is returned if format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @param context GPU context + @param backendTexture texture residing on GPU + @param textureOrigin origin of backendTexture + @param colorType color type of the resulting image + @param alphaType alpha type of the resulting image + @param colorSpace range of colors; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType); +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType, + SkAlphaType alphaType); +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace); + +/** Creates GPU-backed SkImage from the provided GPU texture associated with context. + GPU texture must stay valid and unchanged until textureReleaseProc is called by Skia. + Skia will call textureReleaseProc with the passed-in releaseContext when SkImage + is deleted or no longer refers to the texture. + A non-null SkImage is returned if format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @note When using a DDL recording context, textureReleaseProc will be called on the + GPU thread after the DDL is played back on the direct context. + @param context GPU context + @param backendTexture texture residing on GPU + @param colorSpace This describes the color space of this image's contents, as + seen after sampling. In general, if the format of the backend + texture is SRGB, some linear colorSpace should be supplied + (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the + backend texture is linear, then the colorSpace should include + a description of the transfer function as + well (e.g., SkColorSpace::MakeSRGB()). + @param textureReleaseProc function called when texture can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp BorrowTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); + +/** Creates a GPU-backed SkImage from pixmap. It is uploaded to GPU backend using context. + Created SkImage is available to other GPU contexts, and is available across thread + boundaries. All contexts must be in the same GPU share group, or otherwise + share resources. + When SkImage is no longer referenced, context releases texture memory + asynchronously. + SkColorSpace of SkImage is determined by pixmap.colorSpace(). + SkImage is returned referring to GPU backend if context is not nullptr, + format of data is recognized and supported, and if context supports moving + resources between contexts. Otherwise, pixmap pixel data is copied and SkImage + as returned in raster format if possible; nullptr may be returned. + Recognized GPU formats vary by platform and GPU backend. + @param context GPU context + @param pixmap SkImageInfo, pixel address, and row bytes + @param buildMips create SkImage as mip map if true + @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary + @return created SkImage, or nullptr +*/ +SK_API sk_sp CrossContextTextureFromPixmap(GrDirectContext* context, + const SkPixmap& pixmap, + bool buildMips, + bool limitToMaxTextureSize = false); + +/** Creates a GPU-backed SkImage from a GPU backend texture. The backend texture must stay + valid and unchanged until textureReleaseProc is called. The textureReleaseProc is + called when the SkImage is deleted or no longer refers to the texture and will be + passed the releaseContext. + An SkImage is returned if the format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @note When using a DDL recording context, textureReleaseProc will be called on the + GPU thread after the DDL is played back on the direct context. + @param context the GPU context + @param backendTexture a texture already allocated by the GPU + @param alphaType This characterizes the nature of the alpha values in the + backend texture. For opaque compressed formats (e.g., ETC1) + this should usually be set to kOpaq + ue_SkAlphaType. + @param colorSpace This describes the color space of this image's contents, as + seen after sampling. In general, if the format of the backend + texture is SRGB, some linear colorSpace should be supplied + (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the + backend texture is linear, then the colorSpace should include + a description of the transfer function as + well (e.g., SkColorSpace::MakeSRGB()). + @param textureReleaseProc function called when the backend texture can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromCompressedTexture(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, + SkAlphaType alphaType, + sk_sp colorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); + +/** Creates a GPU-backed SkImage from compressed data. + This method will return an SkImage representing the compressed data. + If the GPU doesn't support the specified compression method, the data + will be decompressed and then wrapped in a GPU-backed image. + Note: one can query the supported compression formats via + GrRecordingContext::compressedBackendFormat. + @param context GPU context + @param data compressed data to store in SkImage + @param width width of full SkImage + @param height height of full SkImage + @param type type of compression used + @param mipmapped does 'data' contain data for all the mipmap levels? + @param isProtected do the contents of 'data' require DRM protection (on Vulkan)? + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromCompressedTextureData(GrDirectContext* direct, + sk_sp data, + int width, + int height, + SkTextureCompressionType type, + GrMipmapped mipmapped = GrMipmapped::kNo, + GrProtected isProtected = GrProtected::kNo); + +/** Returns SkImage backed by GPU texture associated with context. Returned SkImage is + compatible with SkSurface created with dstColorSpace. The returned SkImage respects + mipmapped setting; if mipmapped equals skgpu::Mipmapped::kYes, the backing texture + allocates mip map levels. + The mipmapped parameter is effectively treated as kNo if MIP maps are not supported by the + GPU. + Returns original SkImage if the image is already texture-backed, the context matches, and + mipmapped is compatible with the backing GPU texture. skgpu::Budgeted is ignored in this + case. + Returns nullptr if context is nullptr, or if SkImage was created with another + GrDirectContext. + @param GrDirectContext the GrDirectContext in play, if it exists + @param SkImage a non-null pointer to an SkImage. + @param skgpu::Mipmapped Whether created SkImage texture must allocate mip map levels. + Defaults to no. + @param skgpu::Budgeted Whether to count a newly created texture for the returned image + counts against the context's budget. Defaults to yes. + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromImage(GrDirectContext*, + const SkImage*, + skgpu::Mipmapped = skgpu::Mipmapped::kNo, + skgpu::Budgeted = skgpu::Budgeted::kYes); +inline sk_sp TextureFromImage(GrDirectContext* ctx, + sk_sp img, + skgpu::Mipmapped m = skgpu::Mipmapped::kNo, + skgpu::Budgeted b = skgpu::Budgeted::kYes) { + return TextureFromImage(ctx, img.get(), m, b); +} + +/** Creates a GPU-backed SkImage from SkYUVAPixmaps. + The image will remain planar with each plane converted to a texture using the passed + GrRecordingContext. + SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. + The SkColorSpace of the resulting RGB values is specified by imageColorSpace. This will + be the SkColorSpace reported by the image and when drawn the RGB values will be converted + from this space into the destination space (if the destination is tagged). + Currently, this is only supported using the GPU backend and will fail if context is nullptr. + SkYUVAPixmaps does not need to remain valid after this returns. + @param context GPU context + @param pixmaps The planes as pixmaps with supported SkYUVAInfo that + specifies conversion to RGB. + @param buildMips create internal YUVA textures as mip map if kYes. This is + silently ignored if the context does not support mip maps. + @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary + @param imageColorSpace range of colors of the resulting image; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromYUVAPixmaps(GrRecordingContext* context, + const SkYUVAPixmaps& pixmaps, + GrMipmapped buildMips, + bool limitToMaxTextureSize, + sk_sp imageColorSpace); +SK_API sk_sp TextureFromYUVAPixmaps(GrRecordingContext* context, + const SkYUVAPixmaps& pixmaps, + GrMipmapped buildMips = GrMipmapped::kNo, + bool limitToMaxTextureSize = false); + +/** Creates a GPU-backed SkImage from YUV[A] planar textures. This requires that the textures + * stay valid for the lifetime of the image. The ReleaseContext can be used to know when it is + * safe to either delete or overwrite the textures. If ReleaseProc is provided it is also called + * before return on failure. + @param context GPU context + @param yuvaTextures A set of textures containing YUVA data and a description of the + data and transformation to RGBA. + @param imageColorSpace range of colors of the resulting image after conversion to RGB; + may be nullptr + @param textureReleaseProc called when the backend textures can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromYUVATextures(GrRecordingContext* context, + const GrYUVABackendTextures& yuvaTextures, + sk_sp imageColorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); +SK_API sk_sp TextureFromYUVATextures(GrRecordingContext* context, + const GrYUVABackendTextures& yuvaTextures); + +using PromiseImageTextureContext = void*; +using PromiseImageTextureFulfillProc = sk_sp (*)(PromiseImageTextureContext); +using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); + +/** Create a new GPU-backed SkImage that is very similar to an SkImage created by BorrowTextureFrom. + The difference is that the caller need not have created the texture nor populated it with the + image pixel data. Moreover, the SkImage may be created on a thread as the creation of the + image does not require access to the backend API or GrDirectContext. Instead of passing a + GrBackendTexture the client supplies a description of the texture consisting of + GrBackendFormat, width, height, and GrMipmapped state. The resulting SkImage can be drawn + to a SkDeferredDisplayListRecorder or directly to a GPU-backed SkSurface. + When the actual texture is required to perform a backend API draw, textureFulfillProc will + be called to receive a GrBackendTexture. The properties of the GrBackendTexture must match + those set during the SkImage creation, and it must refer to a valid existing texture in the + backend API context/device, and be populated with the image pixel data. The texture cannot + be deleted until textureReleaseProc is called. + There is at most one call to each of textureFulfillProc and textureReleaseProc. + textureReleaseProc is always called even if image creation fails or if the + image is never fulfilled (e.g. it is never drawn or all draws are clipped out) + @param gpuContextProxy the thread-safe proxy of the gpu context. required. + @param backendFormat format of promised gpu texture + @param dimensions width & height of promised gpu texture + @param mipmapped mip mapped state of promised gpu texture + @param origin surface origin of promised gpu texture + @param colorType color type of promised gpu texture + @param alphaType alpha type of promised gpu texture + @param colorSpace range of colors; may be nullptr + @param textureFulfillProc function called to get actual gpu texture + @param textureReleaseProc function called when texture can be deleted + @param textureContext state passed to textureFulfillProc and textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp PromiseTextureFrom(sk_sp gpuContextProxy, + const GrBackendFormat& backendFormat, + SkISize dimensions, + GrMipmapped mipmapped, + GrSurfaceOrigin origin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace, + PromiseImageTextureFulfillProc textureFulfillProc, + PromiseImageTextureReleaseProc textureReleaseProc, + PromiseImageTextureContext textureContext); + +/** This is similar to 'PromiseTextureFrom' but it creates a GPU-backed SkImage from YUV[A] data. + The source data may be planar (i.e. spread across multiple textures). In + the extreme Y, U, V, and A are all in different planes and thus the image is specified by + four textures. 'backendTextureInfo' describes the planar arrangement, texture formats, + conversion to RGB, and origin of the textures. Separate 'textureFulfillProc' and + 'textureReleaseProc' calls are made for each texture. Each texture has its own + PromiseImageTextureContext. If 'backendTextureInfo' is not valid then no release proc + calls are made. Otherwise, the calls will be made even on failure. 'textureContexts' has one + entry for each of the up to four textures, as indicated by 'backendTextureInfo'. + Currently the mip mapped property of 'backendTextureInfo' is ignored. However, in the + near future it will be required that if it is kYes then textureFulfillProc must return + a mip mapped texture for each plane in order to successfully draw the image. + @param gpuContextProxy the thread-safe proxy of the gpu context. required. + @param backendTextureInfo info about the promised yuva gpu texture + @param imageColorSpace range of colors; may be nullptr + @param textureFulfillProc function called to get actual gpu texture + @param textureReleaseProc function called when texture can be deleted + @param textureContexts state passed to textureFulfillProc and textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp PromiseTextureFromYUVA(sk_sp gpuContextProxy, + const GrYUVABackendTextureInfo& backendTextureInfo, + sk_sp imageColorSpace, + PromiseImageTextureFulfillProc textureFulfillProc, + PromiseImageTextureReleaseProc textureReleaseProc, + PromiseImageTextureContext textureContexts[]); + +/** Retrieves the existing backend texture. If SkImage is not a Ganesh-backend texture image + or otherwise does not have such a texture, false is returned. Otherwise, outTexture will + be set to the image's texture. + + If flushPendingGrContextIO is true, completes deferred I/O operations. + If origin in not nullptr, copies location of content drawn into SkImage. + @param outTexture Will be set to the underlying texture of the image if non-null. + @param flushPendingGrContextIO flag to flush outstanding requests + @param origin Will be set to the origin orientation of the image if non-null. + @return false if a Ganesh backend texture cannot be retrieved. +*/ +SK_API bool GetBackendTextureFromImage(const SkImage* img, + GrBackendTexture* outTexture, + bool flushPendingGrContextIO, + GrSurfaceOrigin* origin = nullptr); +inline bool GetBackendTextureFromImage(sk_sp img, + GrBackendTexture* outTexture, + bool flushPendingGrContextIO, + GrSurfaceOrigin* origin = nullptr) { + return GetBackendTextureFromImage(img.get(), outTexture, flushPendingGrContextIO, origin); +} + +/** Extracts the backendTexture from an existing SkImage. + If the image is not already GPU-backed, the raster data will be uploaded as a texture + and returned. + If this is the only reference to the image, the old image's texture will be + moved out of the passed in image. + If the image is shared (has a refcount > 1), the texture will be copied and then returned. + @param context GPU context + @param image image, either CPU-backed or GPU-backed + @param backendTexture Will be set to the underlying texture of the image. + @param backendTextureReleaseProc Called when the texture is released + @return false if image cannot be uploaded. +*/ +SK_API bool MakeBackendTextureFromImage(GrDirectContext* context, + sk_sp image, + GrBackendTexture* backendTexture, + BackendTextureReleaseProc* backendTextureReleaseProc); +// Legacy name +inline bool GetBackendTextureFromImage(GrDirectContext* context, + sk_sp image, + GrBackendTexture* backendTexture, + BackendTextureReleaseProc* backendTextureReleaseProc) { + return MakeBackendTextureFromImage(context, std::move(image), backendTexture, + backendTextureReleaseProc); +} + +} // namespace SkImages + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h index 1e2823f71a95b..0ae85f07a0349 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h @@ -10,7 +10,7 @@ #include "include/core/SkString.h" #include "include/gpu/gl/GrGLFunctions.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include @@ -66,13 +66,13 @@ class SK_API GrGLExtensions { */ void add(const char[]); - void reset() { fStrings.reset(); } + void reset() { fStrings.clear(); } void dumpJSON(SkJSONWriter*) const; private: bool fInitialized = false; - SkTArray fStrings; + skia_private::TArray fStrings; }; #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h index 59b9cd9e18d55..4e488abcad432 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h @@ -11,7 +11,7 @@ #include #include "include/gpu/gl/GrGLTypes.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkTLogic.h" extern "C" { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h index 5d6e3bb2d5f3d..64ca419b9b16a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h @@ -304,9 +304,6 @@ struct SK_API GrGLInterface : public SkRefCnt { GrGLFunction fVertexAttribPointer; GrGLFunction fViewport; - /* NV_framebuffer_mixed_samples */ - GrGLFunction fCoverageModulation; - /* ARB_sync */ GrGLFunction fFenceSync; GrGLFunction fIsSync; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h index d5167787c1e05..3af4802eaacc2 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h @@ -10,6 +10,7 @@ #define GrGLTypes_DEFINED #include "include/core/SkRefCnt.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/gl/GrGLConfig.h" /** @@ -198,7 +199,7 @@ struct GrGLFramebufferInfo { struct GrGLSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrGLenum fTarget = 0; GrGLenum fFormat = 0; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h index f12d22ebb4f04..82a662ab13fdf 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h @@ -8,29 +8,71 @@ #ifndef skgpu_graphite_BackendTexture_DEFINED #define skgpu_graphite_BackendTexture_DEFINED +#include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/graphite/TextureInfo.h" +#ifdef SK_DAWN +#include "include/gpu/graphite/dawn/DawnTypes.h" +#endif + #ifdef SK_METAL -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" #endif #ifdef SK_VULKAN #include "include/private/gpu/vk/SkiaVulkan.h" #endif +namespace skgpu { +class MutableTextureState; +class MutableTextureStateRef; +} + namespace skgpu::graphite { -class BackendTexture { +class SK_API BackendTexture { public: - BackendTexture() {} + BackendTexture(); +#ifdef SK_DAWN + // Create a BackendTexture from a WGPUTexture. Texture info will be + // queried from the texture. Comparing to WGPUTextureView, + // SkImage::readPixels(), SkSurface::readPixels() and + // SkSurface::writePixels() are implemented by direct buffer copy. They + // should be more efficient. For WGPUTextureView, those methods will use + // create an intermediate WGPUTexture, and use it to transfer pixels. + // Note: + // - for better performance, using WGPUTexture IS RECOMMENDED. + // - The BackendTexture will not call retain or release on the passed in + // WGPUTexture. Thus the client must keep the WGPUTexture valid until + // they are no longer using the BackendTexture. + BackendTexture(WGPUTexture texture); + // Create a BackendTexture from a WGPUTextureView. Texture dimensions and + // info have to be provided. + // Note: + // - this method is for importing WGPUTextureView from wgpu::SwapChain only. + // - The BackendTexture will not call retain or release on the passed in + // WGPUTextureView. Thus the client must keep the WGPUTextureView valid + // until they are no longer using the BackendTexture. + BackendTexture(SkISize dimensions, + const DawnTextureInfo& info, + WGPUTextureView textureView); +#endif #ifdef SK_METAL // The BackendTexture will not call retain or release on the passed in MtlHandle. Thus the // client must keep the MtlHandle valid until they are no longer using the BackendTexture. BackendTexture(SkISize dimensions, MtlHandle mtlTexture); #endif +#ifdef SK_VULKAN + BackendTexture(SkISize dimensions, + const VulkanTextureInfo&, + VkImageLayout, + uint32_t queueFamilyIndex, + VkImage); +#endif + BackendTexture(const BackendTexture&); ~BackendTexture(); @@ -47,15 +89,42 @@ class BackendTexture { const TextureInfo& info() const { return fInfo; } + // If the client changes any of the mutable backend of the GrBackendTexture they should call + // this function to inform Skia that those values have changed. The backend API specific state + // that can be set from this function are: + // + // Vulkan: VkImageLayout and QueueFamilyIndex + void setMutableState(const skgpu::MutableTextureState&); + +#ifdef SK_DAWN + WGPUTexture getDawnTexturePtr() const; + WGPUTextureView getDawnTextureViewPtr() const; +#endif #ifdef SK_METAL MtlHandle getMtlTexture() const; #endif +#ifdef SK_VULKAN + VkImage getVkImage() const; + VkImageLayout getVkImageLayout() const; + uint32_t getVkQueueFamilyIndex() const; +#endif + private: + sk_sp mutableState() const; + SkISize fDimensions; TextureInfo fInfo; + sk_sp fMutableState; + union { +#ifdef SK_DAWN + struct { + WGPUTexture fDawnTexture; + WGPUTextureView fDawnTextureView; + }; +#endif #ifdef SK_METAL MtlHandle fMtlTexture; #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h deleted file mode 100644 index a0c977b283bf5..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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 skgpu_graphite_CombinationBuilder_DEFINED -#define skgpu_graphite_CombinationBuilder_DEFINED - -#include "include/core/SkTypes.h" - -#ifdef SK_ENABLE_PRECOMPILE - -#include -#include -#include -#include "include/core/SkBlendMode.h" -#include "include/core/SkSpan.h" -#include "include/core/SkTileMode.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTHash.h" - -class SkArenaAllocWithReset; -class SkKeyContext; -class SkPaintParamsKeyBuilder; -class SkShaderCodeDictionary; -class SkUniquePaintParamsID; - -namespace skgpu::graphite { - -class CombinationBuilder; -class CombinationBuilderTestAccess; -class Context; -class Option; - -enum class ShaderType : uint32_t { - kSolidColor, - - kLinearGradient, - kRadialGradient, - kSweepGradient, - kConicalGradient, - - kLocalMatrix, - kImage, - kPorterDuffBlendShader, - kBlendShader, - - kLast = kBlendShader -}; - -static constexpr int kShaderTypeCount = static_cast(ShaderType::kLast) + 1; - -struct TileModePair { - SkTileMode fX; - SkTileMode fY; - - bool operator==(const TileModePair& other) const { return fX == other.fX && fY == other.fY; } - bool operator!=(const TileModePair& other) const { return !(*this == other); } -}; - -// TODO: add ShaderID and ColorFilterID too -class BlenderID { -public: - BlenderID() : fID(0) {} // 0 is an invalid blender ID - BlenderID(const BlenderID& src) : fID(src.fID) {} - - bool isValid() const { return fID > 0; } - - bool operator==(const BlenderID& other) const { return fID == other.fID; } - - BlenderID& operator=(const BlenderID& src) { - fID = src.fID; - return *this; - } - -private: - friend class ::SkShaderCodeDictionary; // for ctor and asUInt access - friend class CombinationBuilder; // for asUInt access - - BlenderID(uint32_t id) : fID(id) {} - - uint32_t asUInt() const { return fID; } - - uint32_t fID; -}; - -// When combination options are added to the combination builder an CombinationOption -// object is frequently returned. This allows options to be added, recursively, to the -// previously added options. -// Note: CombinationOptions are stable memory-wise so, once returned, they are valid -// until CombinationBuilder::reset is called. -class CombinationOption { -public: - CombinationOption addChildOption(int childIndex, ShaderType); - - CombinationOption addChildOption(int childIndex, ShaderType, - int minNumStops, int maxNumStops); - - CombinationOption addChildOption(int childIndex, ShaderType, - SkSpan tileModes); - - bool isValid() const { return fDataInArena; } - -private: - friend class CombinationBuilder; // for ctor - friend class CombinationBuilderTestAccess; - - CombinationOption(CombinationBuilder* builder, Option* dataInArena) - : fBuilder(builder) - , fDataInArena(dataInArena) {} - - ShaderType type() const; - int numChildSlots() const; - SkDEBUGCODE(int epoch() const;) - - CombinationBuilder* fBuilder; - Option* fDataInArena; -}; - -class CombinationBuilder { -public: - enum class BlendModeGroup { - kPorterDuff, // [ kClear .. kScreen ] - kAdvanced, // [ kOverlay .. kMultiply ] - kColorAware, // [ kHue .. kLuminosity ] - kAll - }; - - CombinationBuilder(SkShaderCodeDictionary*); - ~CombinationBuilder(); - - // Blend Modes - void addOption(SkBlendMode); - void addOption(SkBlendMode rangeStart, SkBlendMode rangeEnd); // inclusive - void addOption(BlendModeGroup); - - // TODO: have this variant return an CombinationOption object - void addOption(BlenderID); - - // Shaders - CombinationOption addOption(ShaderType); - CombinationOption addOption(ShaderType, int minNumStops, int maxNumStops); // inclusive - CombinationOption addOption(ShaderType, SkSpan tileModes); - - void reset(); - -private: - friend class Context; // for access to 'buildCombinations' - friend class CombinationOption; // for 'addOptionInternal' and 'arena' - friend class CombinationBuilderTestAccess; // for 'num*Combinations' and 'epoch' - - int numShaderCombinations() const; - int numBlendModeCombinations() const; - int numCombinations() { - return this->numShaderCombinations() * this->numBlendModeCombinations(); - } - - // 'desiredCombination' must be less than numCombinations - void createKey(const SkKeyContext&, int desiredCombination, SkPaintParamsKeyBuilder*); - -#ifdef SK_DEBUG - void dump() const; - int epoch() const { return fEpoch; } -#endif - - SkArenaAllocWithReset* arena() { return fArena.get(); } - - template - Option* allocInArena(Args&&... args); - - Option* addOptionInternal(ShaderType); - Option* addOptionInternal(ShaderType, int minNumStops, int maxNumStops); - Option* addOptionInternal(ShaderType, SkSpan tileModes); - - void buildCombinations(SkShaderCodeDictionary*, - const std::function&); - - SkShaderCodeDictionary* fDictionary; - std::unique_ptr fArena; - SkTArray fShaderOptions; - - uint32_t fBlendModes; - // TODO: store the SkBlender-based blenders in the arena - SkTHashSet fBlenders; - - SkDEBUGCODE(int fEpoch = 0;) -}; - -} // namespace skgpu::graphite - -#endif // SK_ENABLE_PRECOMPILE - -#endif // skgpu_graphite_CombinationBuilder_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h index c5ff91e6cb7e0..0fb6eee418687 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h @@ -8,36 +8,34 @@ #ifndef skgpu_graphite_Context_DEFINED #define skgpu_graphite_Context_DEFINED +#include "include/core/SkImage.h" #include "include/core/SkRefCnt.h" #include "include/core/SkShader.h" #include "include/gpu/graphite/ContextOptions.h" #include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/graphite/Recorder.h" -#include "include/private/SingleOwner.h" +#include "include/private/base/SingleOwner.h" +#include #include class SkRuntimeEffect; -namespace skgpu { struct VulkanBackendContext; } - namespace skgpu::graphite { class BackendTexture; +class Buffer; +class ClientMappedBufferManager; class Context; class ContextPriv; -struct DawnBackendContext; class GlobalCache; -struct MtlBackendContext; +class PaintOptions; +class PlotUploadTracker; class QueueManager; class Recording; class ResourceProvider; class SharedContext; - -#ifdef SK_ENABLE_PRECOMPILE -class BlenderID; -class CombinationBuilder; -#endif +class TextureProxy; class SK_API Context final { public: @@ -48,37 +46,30 @@ class SK_API Context final { ~Context(); -#ifdef SK_DAWN - static std::unique_ptr MakeDawn(const DawnBackendContext&, const ContextOptions&); -#endif -#ifdef SK_METAL - static std::unique_ptr MakeMetal(const MtlBackendContext&, const ContextOptions&); -#endif - -#ifdef SK_VULKAN - static std::unique_ptr MakeVulkan(const VulkanBackendContext&, const ContextOptions&); -#endif - BackendApi backend() const; std::unique_ptr makeRecorder(const RecorderOptions& = {}); - void insertRecording(const InsertRecordingInfo&); - void submit(SyncToCpu = SyncToCpu::kNo); + bool insertRecording(const InsertRecordingInfo&); + bool submit(SyncToCpu = SyncToCpu::kNo); + + void asyncReadPixels(const SkImage* image, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); + + void asyncReadPixels(const SkSurface* surface, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); /** * Checks whether any asynchronous work is complete and if so calls related callbacks. */ void checkAsyncWorkCompletion(); -#ifdef SK_ENABLE_PRECOMPILE - // TODO: add "ShaderID addUserDefinedShader(sk_sp)" here - // TODO: add "ColorFilterID addUserDefinedColorFilter(sk_sp)" here - BlenderID addUserDefinedBlender(sk_sp); - - void precompile(CombinationBuilder*); -#endif - /** * Called to delete the passed in BackendTexture. This should only be called if the * BackendTexture was created by calling Recorder::createBackendTexture on a Recorder created @@ -94,21 +85,83 @@ class SK_API Context final { ContextPriv priv(); const ContextPriv priv() const; // NOLINT(readability-const-return-type) + class ContextID { + public: + static Context::ContextID Next(); + + ContextID() : fID(SK_InvalidUniqueID) {} + + bool operator==(const ContextID& that) const { return fID == that.fID; } + bool operator!=(const ContextID& that) const { return !(*this == that); } + + void makeInvalid() { fID = SK_InvalidUniqueID; } + bool isValid() const { return fID != SK_InvalidUniqueID; } + + private: + constexpr ContextID(uint32_t id) : fID(id) {} + uint32_t fID; + }; + + ContextID contextID() const { return fContextID; } + protected: - Context(sk_sp, std::unique_ptr); + Context(sk_sp, std::unique_ptr, const ContextOptions&); private: friend class ContextPriv; + friend class ContextCtorAccessor; SingleOwner* singleOwner() const { return &fSingleOwner; } + // Must be called in Make() to handle one-time GPU setup operations that can possibly fail and + // require Context::Make() to return a nullptr. + bool finishInitialization(); + + void asyncReadPixels(const TextureProxy* textureProxy, + const SkImageInfo& srcImageInfo, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); + + // Inserts a texture to buffer transfer task, used by asyncReadPixels methods + struct PixelTransferResult { + using ConversionFn = void(void* dst, const void* mappedBuffer); + // If null then the transfer could not be performed. Otherwise this buffer will contain + // the pixel data when the transfer is complete. + sk_sp fTransferBuffer; + // RowBytes for transfer buffer data + size_t fRowBytes; + // If this is null then the transfer buffer will contain the data in the requested + // color type. Otherwise, when the transfer is done this must be called to convert + // from the transfer buffer's color type to the requested color type. + std::function fPixelConverter; + }; + PixelTransferResult transferPixels(const TextureProxy*, + const SkImageInfo& srcImageInfo, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect); + sk_sp fSharedContext; std::unique_ptr fResourceProvider; std::unique_ptr fQueueManager; + std::unique_ptr fMappedBufferManager; + std::unique_ptr fPlotUploadTracker; // In debug builds we guard against improper thread handling. This guard is passed to the // ResourceCache for the Context. mutable SingleOwner fSingleOwner; + +#if GRAPHITE_TEST_UTILS + // In test builds a Recorder may track the Context that was used to create it. + bool fStoreContextRefInRecorder = false; + // If this tracking is on, to allow the client to safely delete this Context or its Recorders + // in any order we must also track the Recorders created here. + std::vector fTrackedRecorders; +#endif + + // Needed for MessageBox handling + const ContextID fContextID; }; } // namespace skgpu::graphite diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h index d55351a774c1d..b9ac1b09d1619 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h @@ -8,6 +8,8 @@ #ifndef skgpu_graphite_ContextOptions_DEFINED #define skgpu_graphite_ContextOptions_DEFINED +#include "include/private/base/SkAPI.h" + namespace skgpu { class ShaderErrorHandler; } namespace skgpu::graphite { @@ -15,6 +17,13 @@ namespace skgpu::graphite { struct SK_API ContextOptions { ContextOptions() {} + /** + * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. + * This does not affect code path choices that are made for perfomance reasons nor does it + * override other ContextOption settings. + */ + bool fDisableDriverCorrectnessWorkarounds = false; + /** * If present, use this object to report shader compilation failures. If not, report failures * via SkDebugf and assert. @@ -55,18 +64,7 @@ struct SK_API ContextOptions { * fGlypheCacheTextureMaximumBytes. */ bool fAllowMultipleGlyphCacheTextures = true; - - /** - * If true, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp - * rendering of all glyphs. This must be set to true to use Slugs. - */ - #if defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_STRIKE_SERIALIZE) - bool fSupportBilerpFromGlyphAtlas = true; - #else bool fSupportBilerpFromGlyphAtlas = false; - #endif #if GRAPHITE_TEST_UTILS /** @@ -77,6 +75,12 @@ struct SK_API ContextOptions { * Maximum width and height of internal texture atlases. */ int fMaxTextureAtlasSize = 2048; + + /** + * If true, will store a pointer in Recorder that points back to the Context + * that created it. Used by readPixels() and other methods that normally require a Context. + */ + bool fStoreContextRefInRecorder = false; #endif }; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h index 474e5089fcf2a..231f2a5e1454d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h @@ -8,14 +8,18 @@ #ifndef skgpu_graphite_GraphiteTypes_DEFINED #define skgpu_graphite_GraphiteTypes_DEFINED +#include "include/core/SkPoint.h" #include "include/core/SkTypes.h" #include "include/gpu/GpuTypes.h" #include +class SkSurface; + namespace skgpu::graphite { class Recording; +class Task; using GpuFinishedContext = void*; using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackResult); @@ -27,9 +31,33 @@ using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackRes * the Recording that they may be holding onto. If the Recording is successfully submitted to the * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All * other cases where some failure occured it will be called with CallbackResult::kFailed. + * + * The fTargetSurface, if provided, is used as a target for any draws recorded onto a deferred + * canvas returned from Recorder::makeDeferredCanvas. This target surface must be provided iff + * the Recording contains any such draws. It must be Graphite-backed and its backing texture's + * TextureInfo must match the info provided to the Recorder when making the deferred canvas. + * + * fTargetTranslation is an additional translation applied to draws targeting fTargetSurface. */ struct InsertRecordingInfo { Recording* fRecording = nullptr; + + SkSurface* fTargetSurface = nullptr; + SkIVector fTargetTranslation = {0, 0}; + + GpuFinishedContext fFinishedContext = nullptr; + GpuFinishedProc fFinishedProc = nullptr; +}; + +/** + * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or + * when there is a failure that caused it not to be submitted. The callback will always be called + * and the caller can use the callback to know it is safe to free any resources associated with + * the Recording that they may be holding onto. If the Recording is successfully submitted to the + * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All + * other cases where some failure occured it will be called with CallbackResult::kFailed. + */ +struct InsertFinishInfo { GpuFinishedContext fFinishedContext = nullptr; GpuFinishedProc fFinishedProc = nullptr; }; @@ -42,12 +70,34 @@ enum class SyncToCpu : bool { kNo = false }; -/** - * Is the texture mipmapped or not +/* + * For Promise Images - should the Promise Image be fulfilled every time a Recording that references + * it is inserted into the Context. */ -enum class Mipmapped : bool { - kNo = false, - kYes = true, +enum class Volatile : bool { + kNo = false, // only fulfilled once + kYes = true // fulfilled on every insertion call +}; + +/* + * Graphite's different rendering methods each only apply to certain types of draws. This + * enum supports decision-making regarding the different renderers and what is being drawn. + */ +enum DrawTypeFlags : uint8_t { + + kNone = 0b000, + + // SkCanvas:: drawSimpleText, drawString, drawGlyphs, drawTextBlob, drawSlug + kText = 0b001, + + // SkCanvas::drawVertices + kDrawVertices = 0b010, + + // All other canvas draw calls + kShape = 0b100, + + kMostCommon = kText | kShape, + kAll = kText | kDrawVertices | kShape }; } // namespace skgpu::graphite diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h index 748b678c5ffa9..3c071fe9ea3e7 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h @@ -13,7 +13,6 @@ namespace skgpu::graphite { -enum class Mipmapped : bool; class Recorder; /* @@ -23,9 +22,12 @@ class Recorder; * return a Graphite-backed version of the provided SkImage that meets the specified * requirements. * - * Skia requires that 'findOrCreate' return a Graphite-backed image that preserves the dimensions, - * number of channels and alpha type of the original image. The bit depth of the - * individual channels can change (e.g., 4444 -> 8888 is allowed). + * Skia requires that 'findOrCreate' return a Graphite-backed image that preserves the + * dimensions and alpha type of the original image. The bit depth of the + * individual channels can change (e.g., 4444 -> 8888 is allowed) as well as the channels - as + * long as the returned image has a superset of the original image's channels + * (e.g., 565 -> 8888 opaque is allowed). + * * Wrt mipmapping, the returned image can have different mipmap settings than requested. If * mipmapping was requested but not returned, the sampling level will be reduced to linear. * If the requirements are not met by the returned image (modulo the flexibility wrt mipmapping) diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h index 82cbd0f1698cf..6e911a4e72c72 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h @@ -11,17 +11,20 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/gpu/graphite/GraphiteTypes.h" -#include "include/private/SingleOwner.h" -#include "include/private/SkTHash.h" +#include "include/gpu/graphite/Recording.h" +#include "include/private/base/SingleOwner.h" +#include "include/private/base/SkTArray.h" #include +class SkCanvas; +struct SkImageInfo; class SkPixmap; -class SkRuntimeEffectDictionary; -class SkTextureDataBlock; -class SkUniformDataBlock; -namespace skgpu { class TokenTracker; } +namespace skgpu { +class RefCntedCallback; +class TokenTracker; +} namespace sktext::gpu { class StrikeCache; @@ -33,22 +36,26 @@ namespace skgpu::graphite { class AtlasManager; class BackendTexture; class Caps; +class Context; class Device; class DrawBufferManager; class GlobalCache; class ImageProvider; +class ProxyCache; class RecorderPriv; -class Recording; class ResourceProvider; +class RuntimeEffectDictionary; class SharedContext; class Task; class TaskGraph; +class TextureDataBlock; class TextureInfo; +class UniformDataBlock; class UploadBufferManager; template class PipelineDataCache; -using UniformDataCache = PipelineDataCache; -using TextureDataCache = PipelineDataCache; +using UniformDataCache = PipelineDataCache; +using TextureDataCache = PipelineDataCache; struct SK_API RecorderOptions final { RecorderOptions(); @@ -115,11 +122,23 @@ class SK_API Recorder final { */ void deleteBackendTexture(BackendTexture&); + // Adds a proc that will be moved to the Recording upon snap, subsequently attached to the + // CommandBuffer when the Recording is added, and called when that CommandBuffer is submitted + // and finishes. If the Recorder or Recording is deleted before the proc is added to the + // CommandBuffer, it will be called with result Failure. + void addFinishInfo(const InsertFinishInfo&); + + // Returns a canvas that will record to a proxy surface, which must be instantiated on replay. + // This can only be called once per Recording; subsequent calls will return null until a + // Recording is snapped. Additionally, the returned SkCanvas is only valid until the next + // Recording snap, at which point it is deleted. + SkCanvas* makeDeferredCanvas(const SkImageInfo&, const TextureInfo&); + // Provides access to functions that aren't part of the public API. RecorderPriv priv(); const RecorderPriv priv() const; // NOLINT(readability-const-return-type) -#if GR_TEST_UTILS +#if GRAPHITE_TEST_UTILS bool deviceIsRegistered(Device*); #endif @@ -156,7 +175,7 @@ class SK_API Recorder final { sk_sp fSharedContext; std::unique_ptr fResourceProvider; - std::unique_ptr fRuntimeEffectDict; + std::unique_ptr fRuntimeEffectDict; std::unique_ptr fGraph; std::unique_ptr fUniformDataCache; @@ -176,6 +195,17 @@ class SK_API Recorder final { // This guard is passed to the ResourceCache. // TODO: Should we also pass this to Device, DrawContext, and similar classes? mutable SingleOwner fSingleOwner; + + sk_sp fTargetProxyDevice; + std::unique_ptr fTargetProxyCanvas; + std::unique_ptr fTargetProxyData; + + skia_private::TArray> fFinishedProcs; + +#if GRAPHITE_TEST_UTILS + // For testing use only -- the Context used to create this Recorder + Context* fContext = nullptr; +#endif }; } // namespace skgpu::graphite diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h index b1cb770bf0667..4a60e5b936626 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h @@ -9,10 +9,17 @@ #define skgpu_graphite_Recording_DEFINED #include "include/core/SkRefCnt.h" +#include "include/private/SkChecksum.h" +#include "include/private/base/SkTArray.h" #include +#include #include +namespace skgpu { +class RefCntedCallback; +} + namespace skgpu::graphite { class CommandBuffer; @@ -20,18 +27,51 @@ class RecordingPriv; class Resource; class ResourceProvider; class TaskGraph; +class Texture; +class TextureInfo; +class TextureProxy; -class Recording final { +class SK_API Recording final { public: ~Recording(); RecordingPriv priv(); +#if GRAPHITE_TEST_UTILS + bool isTargetProxyInstantiated() const; +#endif + private: - friend class Recorder; // for ctor + friend class Recorder; // for ctor and LazyProxyData friend class RecordingPriv; - Recording(std::unique_ptr); + // LazyProxyData is used if this recording should be replayed to a target that is provided on + // replay, and it handles the target proxy's instantiation with the provided target. + class LazyProxyData { + public: + LazyProxyData(const TextureInfo&); + + TextureProxy* lazyProxy(); + sk_sp refLazyProxy(); + + bool lazyInstantiate(ResourceProvider*, sk_sp); + + private: + sk_sp fTarget; + sk_sp fTargetProxy; + }; + + struct ProxyHash { + std::size_t operator()(const sk_sp& proxy) const { + return SkGoodHash()(proxy.get()); + } + }; + + Recording(std::unique_ptr, + std::unordered_set, ProxyHash>&& nonVolatileLazyProxies, + std::unordered_set, ProxyHash>&& volatileLazyProxies, + std::unique_ptr targetProxyData, + skia_private::TArray>&& finishedProcs); bool addCommands(CommandBuffer*, ResourceProvider*); void addResourceRef(sk_sp); @@ -42,6 +82,13 @@ class Recording final { // Those refs are stored in the array here and will eventually be passed onto a CommandBuffer // when the Recording adds its commands. std::vector> fExtraResourceRefs; + + std::unordered_set, ProxyHash> fNonVolatileLazyProxies; + std::unordered_set, ProxyHash> fVolatileLazyProxies; + + std::unique_ptr fTargetProxyData; + + skia_private::TArray> fFinishedProcs; }; } // namespace skgpu::graphite diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h index 15f3081e55f73..9a30839ab43e8 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h @@ -10,8 +10,12 @@ #include "include/gpu/graphite/GraphiteTypes.h" +#ifdef SK_DAWN +#include "include/private/gpu/graphite/DawnTypesPriv.h" +#endif + #ifdef SK_METAL -#include "include/private/gpu/graphite/MtlTypesPriv.h" +#include "include/private/gpu/graphite/MtlGraphiteTypesPriv.h" #endif #ifdef SK_VULKAN @@ -20,15 +24,25 @@ namespace skgpu::graphite { -class TextureInfo { +class SK_API TextureInfo { public: TextureInfo() {} +#ifdef SK_DAWN + TextureInfo(const DawnTextureInfo& dawnInfo) + : fBackend(BackendApi::kDawn) + , fValid(true) + , fSampleCount(dawnInfo.fSampleCount) + , fMipmapped(dawnInfo.fMipmapped) + , fProtected(Protected::kNo) + , fDawnSpec(dawnInfo) {} +#endif + #ifdef SK_METAL TextureInfo(const MtlTextureInfo& mtlInfo) : fBackend(BackendApi::kMetal) , fValid(true) , fSampleCount(mtlInfo.fSampleCount) - , fLevelCount(mtlInfo.fLevelCount) + , fMipmapped(mtlInfo.fMipmapped) , fProtected(Protected::kNo) , fMtlSpec(mtlInfo) {} #endif @@ -38,7 +52,7 @@ class TextureInfo { : fBackend(BackendApi::kVulkan) , fValid(true) , fSampleCount(vkInfo.fSampleCount) - , fLevelCount(vkInfo.fLevelCount) + , fMipmapped(vkInfo.fMipmapped) , fProtected(Protected::kNo) , fVkSpec(vkInfo) { if (vkInfo.fFlags & VK_IMAGE_CREATE_PROTECTED_BIT) { @@ -58,15 +72,25 @@ class TextureInfo { BackendApi backend() const { return fBackend; } uint32_t numSamples() const { return fSampleCount; } - uint32_t numMipLevels() const { return fLevelCount; } + Mipmapped mipmapped() const { return fMipmapped; } Protected isProtected() const { return fProtected; } +#ifdef SK_DAWN + bool getDawnTextureInfo(DawnTextureInfo* info) const { + if (!this->isValid() || fBackend != BackendApi::kDawn) { + return false; + } + *info = DawnTextureSpecToTextureInfo(fDawnSpec, fSampleCount, fMipmapped); + return true; + } +#endif + #ifdef SK_METAL bool getMtlTextureInfo(MtlTextureInfo* info) const { if (!this->isValid() || fBackend != BackendApi::kMetal) { return false; } - *info = MtlTextureSpecToTextureInfo(fMtlSpec, fSampleCount, fLevelCount); + *info = MtlTextureSpecToTextureInfo(fMtlSpec, fSampleCount, fMipmapped); return true; } #endif @@ -76,12 +100,24 @@ class TextureInfo { if (!this->isValid() || fBackend != BackendApi::kVulkan) { return false; } - *info = VulkanTextureSpecToTextureInfo(fVkSpec, fSampleCount, fLevelCount); + *info = VulkanTextureSpecToTextureInfo(fVkSpec, fSampleCount, fMipmapped); return true; } #endif private: +#ifdef SK_DAWN + friend class DawnCaps; + friend class DawnCommandBuffer; + friend class DawnGraphicsPipeline; + friend class DawnResourceProvider; + friend class DawnTexture; + const DawnTextureSpec& dawnTextureSpec() const { + SkASSERT(fValid && fBackend == BackendApi::kDawn); + return fDawnSpec; + } +#endif + #ifdef SK_METAL friend class MtlCaps; friend class MtlGraphicsPipeline; @@ -105,10 +141,13 @@ class TextureInfo { bool fValid = false; uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + Mipmapped fMipmapped = Mipmapped::kNo; Protected fProtected = Protected::kNo; union { +#ifdef SK_DAWN + DawnTextureSpec fDawnSpec; +#endif #ifdef SK_METAL MtlTextureSpec fMtlSpec; #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h new file mode 100644 index 0000000000000..c3b80ae196e32 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h @@ -0,0 +1,139 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef skgpu_graphite_YUVABackendTextures_DEFINED +#define skgpu_graphite_YUVABackendTextures_DEFINED + +#include "include/core/SkSpan.h" +#include "include/core/SkYUVAInfo.h" +#include "include/gpu/graphite/BackendTexture.h" + +#include + +namespace skgpu::graphite { +class Recorder; + +/** + * A description of a set of BackendTextures that hold the planar data described by a SkYUVAInfo. + */ +class SK_API YUVABackendTextureInfo { +public: + static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; + + /** Default YUVABackendTextureInfo is invalid. */ + YUVABackendTextureInfo() = default; + YUVABackendTextureInfo(const YUVABackendTextureInfo&) = default; + YUVABackendTextureInfo& operator=(const YUVABackendTextureInfo&) = default; + + /** + * Initializes a YUVABackendTextureInfo to describe a set of textures that can store the + * planes indicated by the SkYUVAInfo. The texture dimensions are taken from the SkYUVAInfo's + * plane dimensions. All the described textures share a common origin. The planar image this + * describes will be mip mapped if all the textures are individually mip mapped as indicated + * by Mipmapped. This will produce an invalid result (return false from isValid()) if the + * passed formats' channels don't agree with SkYUVAInfo. + */ + YUVABackendTextureInfo(const Recorder*, + const SkYUVAInfo&, + const TextureInfo[kMaxPlanes], + Mipmapped); + + bool operator==(const YUVABackendTextureInfo&) const; + bool operator!=(const YUVABackendTextureInfo& that) const { return !(*this == that); } + + /** TextureInfo for the ith plane, or invalid if i >= numPlanes() */ + const TextureInfo& planeTextureInfo(int i) const { + SkASSERT(i >= 0); + return fPlaneTextureInfos[static_cast(i)]; + } + + const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } + + SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } + + Mipmapped mipmapped() const { return fMipmapped; } + + /** The number of planes, 0 if this YUVABackendTextureInfo is invalid. */ + int numPlanes() const { return fYUVAInfo.numPlanes(); } + + /** + * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture + * formats. + */ + bool isValid() const { return fYUVAInfo.isValid(); } + + /** + * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be + * valid if this->isValid(). + */ + SkYUVAInfo::YUVALocations toYUVALocations() const; + +private: + SkYUVAInfo fYUVAInfo; + std::array fPlaneTextureInfos; + std::array fPlaneChannelMasks; + Mipmapped fMipmapped = Mipmapped::kNo; +}; + +/** + * A set of BackendTextures that hold the planar data for an image described a SkYUVAInfo. + */ +class SK_API YUVABackendTextures { +public: + static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; + + YUVABackendTextures() = default; + YUVABackendTextures(const YUVABackendTextures&) = delete; + YUVABackendTextures& operator=(const YUVABackendTextures&) = delete; + + /** + * Initializes a YUVABackendTextures object from a set of textures that store the planes + * indicated by the SkYUVAInfo. This will produce an invalid result (return false from + * isValid()) if the passed texture formats' channels don't agree with SkYUVAInfo. + */ + YUVABackendTextures(const Recorder*, + const SkYUVAInfo&, + const BackendTexture[kMaxPlanes]); + + SkSpan planeTextures() const { + return SkSpan(fPlaneTextures); + } + + /** BackendTexture for the ith plane, or invalid if i >= numPlanes() */ + BackendTexture planeTexture(int i) const { + SkASSERT(i >= 0); + return fPlaneTextures[static_cast(i)]; + } + + const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } + + SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } + + /** The number of planes, 0 if this YUVABackendTextureInfo is invalid. */ + int numPlanes() const { return fYUVAInfo.numPlanes(); } + + /** + * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture + * formats. + */ + bool isValid() const { return fYUVAInfo.isValid(); } + + /** + * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be + * valid if this->isValid(). + */ + SkYUVAInfo::YUVALocations toYUVALocations() const; + +private: + SkYUVAInfo fYUVAInfo; + std::array fPlaneTextures; + std::array fPlaneChannelMasks; +}; + +} // End of namespace skgpu::graphite + +#endif // skgpu_graphite_YUVABackendTextures_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h new file mode 100644 index 0000000000000..291be756306e7 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h @@ -0,0 +1,40 @@ +/* + * 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 skgpu_graphite_DawnTypes_DEFINED +#define skgpu_graphite_DawnTypes_DEFINED + +#include "include/gpu/graphite/GraphiteTypes.h" +#include "webgpu/webgpu_cpp.h" + +namespace skgpu::graphite { + +struct DawnTextureInfo { + uint32_t fSampleCount = 1; + Mipmapped fMipmapped = Mipmapped::kNo; + + // wgpu::TextureDescriptor properties + wgpu::TextureFormat fFormat = wgpu::TextureFormat::Undefined; + wgpu::TextureUsage fUsage = wgpu::TextureUsage::None; + + DawnTextureInfo() = default; + DawnTextureInfo(const wgpu::Texture& texture); + DawnTextureInfo(uint32_t sampleCount, + Mipmapped mipmapped, + wgpu::TextureFormat format, + wgpu::TextureUsage usage) + : fSampleCount(sampleCount) + , fMipmapped(mipmapped) + , fFormat(format) + , fUsage(usage) {} +}; + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_DawnTypes_DEFINED + + diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h new file mode 100644 index 0000000000000..059d128ef59d6 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h @@ -0,0 +1,28 @@ +/* + * 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 skgpu_graphite_DawnUtils_DEFINED +#define skgpu_graphite_DawnUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; +struct DawnBackendContext; + +namespace ContextFactory { +SK_API std::unique_ptr MakeDawn(const DawnBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + + +#endif // skgpu_graphite_DawnUtils_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h index de5f917a9aa04..9d6d0192d170d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h @@ -8,7 +8,7 @@ #ifndef skgpu_graphite_MtlBackendContext_DEFINED #define skgpu_graphite_MtlBackendContext_DEFINED -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" namespace skgpu::graphite { diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h similarity index 85% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h index 5f4c4c8dccff6..bc04421643db2 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h @@ -5,9 +5,10 @@ * found in the LICENSE file. */ -#ifndef skgpu_graphite_MtlTypes_DEFINED -#define skgpu_graphite_MtlTypes_DEFINED +#ifndef skgpu_graphite_MtlGraphiteTypes_DEFINED +#define skgpu_graphite_MtlGraphiteTypes_DEFINED +#include "include/gpu/graphite/GraphiteTypes.h" #include "include/ports/SkCFObject.h" /////////////////////////////////////////////////////////////////////////////// @@ -38,7 +39,7 @@ using MtlHandle = const void*; struct MtlTextureInfo { uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + skgpu::Mipmapped fMipmapped = skgpu::Mipmapped::kNo; // Since we aren't in an Obj-C header we can't directly use Mtl types here. Each of these can // cast to their mapped Mtl types list below. @@ -50,13 +51,13 @@ struct MtlTextureInfo { MtlTextureInfo() = default; MtlTextureInfo(MtlHandle mtlTexture); MtlTextureInfo(uint32_t sampleCount, - uint32_t levelCount, + skgpu::Mipmapped mipmapped, MtlPixelFormat format, MtlTextureUsage usage, MtlStorageMode storageMode, bool framebufferOnly) : fSampleCount(sampleCount) - , fLevelCount(levelCount) + , fMipmapped(mipmapped) , fFormat(format) , fUsage(usage) , fStorageMode(storageMode) @@ -65,4 +66,4 @@ struct MtlTextureInfo { } // namespace skgpu::graphite -#endif // skgpu_graphite_MtlTypes_DEFINED +#endif // skgpu_graphite_MtlGraphiteTypes_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h new file mode 100644 index 0000000000000..cd7837f86c238 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.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 skgpu_graphite_MtlGraphiteUtils_DEFINED +#define skgpu_graphite_MtlGraphiteUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; +struct MtlBackendContext; + +namespace ContextFactory { +SK_API std::unique_ptr MakeMetal(const MtlBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_MtlGraphiteUtils_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h index 4e9802dbca9dc..bd448d2ca6c1e 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h @@ -8,13 +8,14 @@ #ifndef skgpu_graphite_VulkanGraphiteTypes_DEFINED #define skgpu_graphite_VulkanGraphiteTypes_DEFINED +#include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/vk/VulkanTypes.h" namespace skgpu::graphite { struct VulkanTextureInfo { uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + Mipmapped fMipmapped = Mipmapped::kNo; // VkImageCreateInfo properties // Currently the only supported flag is VK_IMAGE_CREATE_PROTECTED_BIT. Any other flag will not @@ -24,8 +25,6 @@ struct VulkanTextureInfo { VkImageTiling fImageTiling = VK_IMAGE_TILING_OPTIMAL; VkImageUsageFlags fImageUsageFlags = 0; VkSharingMode fSharingMode = VK_SHARING_MODE_EXCLUSIVE; - uint32_t fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED; - VkImageLayout fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; // Properties related to the image view and sampling. These are less inherent properties of the // VkImage but describe how the VkImage should be used within Skia. @@ -41,24 +40,20 @@ struct VulkanTextureInfo { VulkanTextureInfo() = default; VulkanTextureInfo(uint32_t sampleCount, - uint32_t levelCount, + Mipmapped mipmapped, VkImageCreateFlags flags, VkFormat format, VkImageTiling imageTiling, VkImageUsageFlags imageUsageFlags, VkSharingMode sharingMode, - uint32_t currentQueueFamily, - VkImageLayout imageLayout, VkImageAspectFlags aspectMask) : fSampleCount(sampleCount) - , fLevelCount(levelCount) + , fMipmapped(mipmapped) , fFlags(flags) , fFormat(format) , fImageTiling(imageTiling) , fImageUsageFlags(imageUsageFlags) , fSharingMode(sharingMode) - , fCurrentQueueFamily(currentQueueFamily) - , fImageLayout(imageLayout) , fAspectMask(aspectMask) {} }; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h new file mode 100644 index 0000000000000..0cfa0e9bf0a40 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h @@ -0,0 +1,28 @@ +/* + * 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 skgpu_graphite_VulkanGraphiteUtils_DEFINED +#define skgpu_graphite_VulkanGraphiteUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu { struct VulkanBackendContext; } + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; + +namespace ContextFactory { +SK_API std::unique_ptr MakeVulkan(const VulkanBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_VulkanGraphiteUtils_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h index ac866167bc679..b3e4b7b84268d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h @@ -8,7 +8,8 @@ #ifndef GrMockOptions_DEFINED #define GrMockOptions_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/core/SkTextureCompressionType.h" +#include "include/gpu/GpuTypes.h" #include "include/private/gpu/ganesh/GrTypesPriv.h" class GrBackendFormat; @@ -16,17 +17,17 @@ class GrBackendFormat; struct GrMockTextureInfo { GrMockTextureInfo() : fColorType(GrColorType::kUnknown) - , fCompressionType(SkImage::CompressionType::kNone) + , fCompressionType(SkTextureCompressionType::kNone) , fID(0) {} GrMockTextureInfo(GrColorType colorType, - SkImage::CompressionType compressionType, + SkTextureCompressionType compressionType, int id) : fColorType(colorType) , fCompressionType(compressionType) , fID(id) { SkASSERT(fID); - if (fCompressionType != SkImage::CompressionType::kNone) { + if (fCompressionType != SkTextureCompressionType::kNone) { SkASSERT(colorType == GrColorType::kUnknown); } } @@ -39,10 +40,10 @@ struct GrMockTextureInfo { GrBackendFormat getBackendFormat() const; - SkImage::CompressionType compressionType() const { return fCompressionType; } + SkTextureCompressionType compressionType() const { return fCompressionType; } GrColorType colorType() const { - SkASSERT(fCompressionType == SkImage::CompressionType::kNone); + SkASSERT(fCompressionType == SkTextureCompressionType::kNone); return fColorType; } @@ -50,7 +51,7 @@ struct GrMockTextureInfo { private: GrColorType fColorType; - SkImage::CompressionType fCompressionType; + SkTextureCompressionType fCompressionType; int fID; }; @@ -82,12 +83,15 @@ struct GrMockRenderTargetInfo { struct GrMockSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrColorType fColorType = GrColorType::kUnknown; - SkImage::CompressionType fCompressionType = SkImage::CompressionType::kNone; + SkTextureCompressionType fCompressionType = SkTextureCompressionType::kNone; }; +static constexpr int kSkTextureCompressionTypeCount = + static_cast(SkTextureCompressionType::kLast) + 1; + /** * A pointer to this type is used as the GrBackendContext when creating a Mock GrContext. It can be * used to specify capability options for the mock context. If nullptr is used a default constructed @@ -105,9 +109,9 @@ struct GrMockOptions { fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888]; - fCompressedOptions[(int)SkImage::CompressionType::kETC2_RGB8_UNORM].fTexturable = true; - fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGB8_UNORM].fTexturable = true; - fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGBA8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kETC2_RGB8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kBC1_RGB8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kBC1_RGBA8_UNORM].fTexturable = true; } struct ConfigOptions { @@ -126,7 +130,7 @@ struct GrMockOptions { int fMaxWindowRectangles = 0; int fMaxVertexAttributes = 16; ConfigOptions fConfigOptions[kGrColorTypeCnt]; - ConfigOptions fCompressedOptions[SkImage::kCompressionTypeCount]; + ConfigOptions fCompressedOptions[kSkTextureCompressionTypeCount]; // GrShaderCaps options. bool fIntegerSupport = false; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h index f7a232e3c6cea..7c0d620e06412 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h @@ -8,7 +8,7 @@ #ifndef GrMtlTypes_DEFINED #define GrMtlTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include "include/ports/SkCFObject.h" /** @@ -49,7 +49,7 @@ struct GrMtlTextureInfo { struct GrMtlSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; // Since we aren't in an Obj-C header we can't directly use Mtl types here. Each of these can // cast to their mapped Mtl types list below. diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h index b166e59920676..23c1b0deaf4a5 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h @@ -72,7 +72,7 @@ struct SK_API GrVkBackendContext { bool fOwnsInstanceAndDevice = false; // Indicates that we are working with protected content and all CommandPool and Queue operations // should be done in a protected context. - GrProtected fProtectedContext = GrProtected::kNo; + skgpu::Protected fProtectedContext = skgpu::Protected::kNo; }; #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h index 9d0a4c2c60133..ae680a8af5521 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h @@ -9,7 +9,7 @@ #ifndef GrVkTypes_DEFINED #define GrVkTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/vk/VulkanTypes.h" using GrVkBackendMemory = skgpu::VulkanBackendMemory; @@ -72,7 +72,7 @@ struct GrVkImageInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; uint32_t fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrVkYcbcrConversionInfo fYcbcrConversionInfo; VkSharingMode fSharingMode = VK_SHARING_MODE_EXCLUSIVE; #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK @@ -137,7 +137,7 @@ struct GrVkDrawableInfo { struct GrVkSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; VkImageTiling fImageTiling = VK_IMAGE_TILING_OPTIMAL; VkFormat fFormat = VK_FORMAT_UNDEFINED; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h index 445fd53908333..90a40c0e674d8 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h @@ -10,7 +10,7 @@ #include "include/core/SkString.h" #include "include/gpu/vk/VulkanTypes.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" namespace skgpu { @@ -48,7 +48,7 @@ class SK_API VulkanExtensions { #ifdef SK_DEBUG void dump() const { SkDebugf("**Vulkan Extensions**\n"); - for (int i = 0; i < fExtensions.count(); ++i) { + for (int i = 0; i < fExtensions.size(); ++i) { SkDebugf("%s. Version: %d\n", fExtensions[i].fName.c_str(), fExtensions[i].fSpecVersion); } @@ -59,7 +59,7 @@ class SK_API VulkanExtensions { private: void getSpecVersions(VulkanGetProc getProc, VkInstance, VkPhysicalDevice); - SkTArray fExtensions; + skia_private::TArray fExtensions; }; } // namespace skgpu diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h index 9d73fdf4bdf65..ebaa28ed1b4b0 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h @@ -35,7 +35,7 @@ class VulkanMemoryAllocator : public SkRefCnt { }; enum class BufferUsage { - // Buffers that will only be accessed from the device (large const buffers). Will always be + // Buffers that will only be accessed from the device (large const buffers) will always be // in device local memory. kGpuOnly, // Buffers that typically will be updated multiple times by the host and read on the gpu @@ -103,12 +103,10 @@ class VulkanMemoryAllocator : public SkRefCnt { virtual void freeMemory(const skgpu::VulkanBackendMemory&) = 0; - // Returns the total amount of memory that is allocated and in use by an allocation for this - // allocator. - virtual uint64_t totalUsedMemory() const = 0; - - // Returns the total amount of memory that is allocated by this allocator. - virtual uint64_t totalAllocatedMemory() const = 0; + // Returns the total amount of memory that is allocated as well as total + // amount of memory in use by an allocation from this allocator. + // Return 1st param is total allocated memory, 2nd is total used memory. + virtual std::pair totalAllocatedAndUsedMemory() const = 0; }; } // namespace skgpu diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h index 18c71562e08c0..47d2b3118fbf6 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h @@ -9,8 +9,8 @@ #include "include/core/SkPath.h" #include "include/core/SkTypes.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkTDArray.h" struct SkRect; @@ -102,7 +102,7 @@ class SK_API SkOpBuilder { bool resolve(SkPath* result); private: - SkTArray fPathRefs; + skia_private::TArray fPathRefs; SkTDArray fOps; static bool FixWinding(SkPath* path); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h new file mode 100644 index 0000000000000..6a22365af433b --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h @@ -0,0 +1,22 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkFontMgr_data_DEFINED +#define SkFontMgr_data_DEFINED + +#include "include/core/SkData.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSpan.h" +#include "include/core/SkTypes.h" + +class SkFontMgr; + +/** Create a custom font manager which wraps a collection of SkData-stored fonts. + * This font manager uses FreeType for rendering. + */ +SK_API sk_sp SkFontMgr_New_Custom_Data(SkSpan>); + +#endif // SkFontMgr_data_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h index 73210bc9a546b..99a1813456f09 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h @@ -13,9 +13,9 @@ #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" #include "include/ports/SkRemotableFontMgr.h" -#include "include/private/SkMutex.h" -#include "include/private/SkOnce.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkTArray.h" class SkData; class SkFontStyle; @@ -34,18 +34,18 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { protected: int onCountFamilies() const override; void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onCreateStyleSet(int index) const override; + sk_sp onCreateStyleSet(int index) const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkTypeface* onMatchFamilyStyle(const char familyName[], - const SkFontStyle& fontStyle) const override; + sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle& fontStyle) const override; - SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], - const SkFontStyle&, - const char* bcp47[], - int bcp47Count, - SkUnichar character) const override; + sk_sp onMatchFamilyStyleCharacter(const char familyName[], + const SkFontStyle&, + const char* bcp47[], + int bcp47Count, + SkUnichar character) const override; sk_sp onMakeFromStreamIndex(std::unique_ptr, int ttcIndex) const override; sk_sp onMakeFromStreamArgs(std::unique_ptr stream, @@ -55,7 +55,7 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { sk_sp onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override; private: - SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const; + sk_sp createTypefaceFromFontId(const SkFontIdentity& fontId) const; sk_sp fImpl; sk_sp fProxy; @@ -93,7 +93,7 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { * typefaces with that data id. By storing the index next to the typeface, * this data cache also acts as a typeface cache. */ - mutable SkTArray fDataCache; + mutable skia_private::TArray fDataCache; mutable SkMutex fDataCacheMutex; friend class SkStyleSet_Indirect; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h index 8017b77cd9a76..eacb6bde9c540 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h @@ -11,7 +11,7 @@ #include "include/core/SkFontStyle.h" #include "include/core/SkRefCnt.h" #include "include/core/SkTypes.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" class SkDataTable; class SkStreamAsset; @@ -48,7 +48,7 @@ class SK_API SkRemotableFontIdentitySet : public SkRefCnt { friend SkRemotableFontIdentitySet* sk_remotable_font_identity_set_new(); int fCount; - SkAutoTArray fData; + skia_private::AutoTArray fData; using INHERITED = SkRefCnt; }; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h index 8437e7a5143ac..0f0d21ad2a67c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h @@ -8,6 +8,7 @@ #ifndef SkTypeface_win_DEFINED #define SkTypeface_win_DEFINED +#include "include/core/SkRefCnt.h" #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" @@ -26,7 +27,7 @@ typedef LOGFONTA LOGFONT; * corresponding typeface for the specified logfont. The caller is responsible * for calling unref() when it is finished. */ -SK_API SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT&); +SK_API sk_sp SkCreateTypefaceFromLOGFONT(const LOGFONT&); /** * Copy the LOGFONT associated with this typeface into the lf parameter. Note diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h index 235649feec3e3..e703b622bf363 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h @@ -10,17 +10,22 @@ #include "include/core/SkString.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" #include "include/private/SkOpts_spi.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkTLogic.h" #include #include +#include -class SkChecksum : SkNoncopyable { +class SkChecksum { public: + SkChecksum() = default; + // Make noncopyable + SkChecksum(const SkChecksum&) = delete; + SkChecksum& operator=(const SkChecksum&) = delete; + /** - * uint32_t -> uint32_t hash, useful for when you're about to trucate this hash but you + * uint32_t -> uint32_t hash, useful for when you're about to truncate this hash but you * suspect its low bits aren't well mixed. * * This is the Murmur3 finalizer. @@ -35,7 +40,7 @@ class SkChecksum : SkNoncopyable { } /** - * uint32_t -> uint32_t hash, useful for when you're about to trucate this hash but you + * uint32_t -> uint32_t hash, useful for when you're about to truncate this hash but you * suspect its low bits aren't well mixed. * * This version is 2-lines cheaper than Mix, but seems to be sufficient for the font cache. @@ -52,12 +57,14 @@ class SkChecksum : SkNoncopyable { // It should be both reasonably fast and high quality. struct SkGoodHash { template - std::enable_if_t operator()(const K& k) const { + std::enable_if_t::value && sizeof(K) == 4, uint32_t> + operator()(const K& k) const { return SkChecksum::Mix(*(const uint32_t*)&k); } template - std::enable_if_t operator()(const K& k) const { + std::enable_if_t::value && sizeof(K) != 4, uint32_t> + operator()(const K& k) const { return SkOpts::hash_fn(&k, sizeof(K), 0); } @@ -74,4 +81,22 @@ struct SkGoodHash { } }; +// The default hashing behavior in SkGoodHash requires the type to have a unique object +// representation (i.e. all bits in contribute to its identity so can be hashed directly). This is +// false when a struct has padding for alignment (which can be avoided by using +// SK_BEGIN|END_REQUIRE_DENSE) or if the struct has floating point members since there are multiple +// bit representations for NaN. +// +// Often Skia code has externally removed the possibility of NaN so the bit representation of a +// non-NaN float will still hash correctly. SkForceDirectHash produces the same as SkGoodHash +// for K's that do not satisfy std::has_unique_object_representation. It should be used sparingly +// and it's use may highlight design issues with the key's data that might warrant an explicitly +// implemented hash function. +template +struct SkForceDirectHash { + uint32_t operator()(const K& k) const { + return SkOpts::hash_fn(&k, sizeof(K), 0); + } +}; + #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h index 5761df2c0b5d4..1bef596a3628f 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h @@ -10,8 +10,7 @@ #include "include/core/SkColor.h" #include "include/core/SkColorPriv.h" -#include "include/private/SkTo.h" -#include "include/private/SkVx.h" +#include "include/private/base/SkTo.h" //////////////////////////////////////////////////////////////////////////////////////////// // Convert a 16bit pixel to a 32bit pixel @@ -374,30 +373,6 @@ static inline SkPMColor SkPixel4444ToPixel32(U16CPU c) { return d | (d << 4); } -static inline skvx::float4 swizzle_rb(const skvx::float4& x) { - return skvx::shuffle<2, 1, 0, 3>(x); -} - -static inline skvx::float4 swizzle_rb_if_bgra(const skvx::float4& x) { -#ifdef SK_PMCOLOR_IS_BGRA - return swizzle_rb(x); -#else - return x; -#endif -} - -static inline skvx::float4 Sk4f_fromL32(uint32_t px) { - return skvx::cast(skvx::byte4::Load(&px)) * (1 / 255.0f); -} - -static inline uint32_t Sk4f_toL32(const skvx::float4& px) { - uint32_t l32; - // For the expected positive color values, the +0.5 before the pin and cast effectively rounds - // to the nearest int without having to call round() or lrint(). - skvx::cast(pin(px * 255.f + 0.5f, skvx::float4(0.f), skvx::float4(255.f))).store(&l32); - return l32; -} - using SkPMColor4f = SkRGBA4f; constexpr SkPMColor4f SK_PMColor4fTRANSPARENT = { 0, 0, 0, 0 }; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h new file mode 100644 index 0000000000000..8cf511a10c265 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h @@ -0,0 +1,97 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkGainmapInfo_DEFINED +#define SkGainmapInfo_DEFINED + +#include "include/core/SkColor.h" + +/** + * Gainmap rendering parameters. Suppose our display has HDR to SDR ratio of H and we wish to + * display an image with gainmap on this display. Let B be the pixel value from the base image + * in a color space that has the primaries of the base image and a linear transfer function. Let + * G be the pixel value from the gainmap. Let D be the output pixel in the same color space as B. + * The value of D is computed as follows: + * + * First, let W be a weight parameter determing how much the gainmap will be applied. + * W = clamp((log(H) - log(fDisplayRatioSdr)) / + * (log(fDisplayRatioHdr) - log(fDisplayRatioSdr), 0, 1) + * + * Next, let L be the gainmap value in log space. We compute this from the value G that was + * sampled from the texture as follows: + * L = mix(log(fGainmapRatioMin), log(fGainmapRatioMax), pow(G, fGainmapGamma)) + * + * Finally, apply the gainmap to compute D, the displayed pixel. If the base image is SDR then + * compute: + * D = (B + fEpsilonSdr) * exp(L * W) - fEpsilonHdr + * If the base image is HDR then compute: + * D = (B + fEpsilonHdr) * exp(L * (W - 1)) - fEpsilonSdr + * + * In the above math, log() is a natural logarithm and exp() is natural exponentiation. Note, + * however, that the base used for the log() and exp() functions does not affect the results of + * the computation (it cancels out, as long as the same base is used throughout). + */ +struct SkGainmapInfo { + /** + * Parameters for converting the gainmap from its image encoding to log space. These are + * specified per color channel. The alpha value is unused. + */ + SkColor4f fGainmapRatioMin = {1.f, 1.f, 1.f, 1.0}; + SkColor4f fGainmapRatioMax = {2.f, 2.f, 2.f, 1.0}; + SkColor4f fGainmapGamma = {1.f, 1.f, 1.f, 1.f}; + + /** + * Parameters sometimes used in gainmap computation to avoid numerical instability. + */ + SkColor4f fEpsilonSdr = {0.f, 0.f, 0.f, 1.0}; + SkColor4f fEpsilonHdr = {0.f, 0.f, 0.f, 1.0}; + + /** + * If the output display's HDR to SDR ratio is less or equal than fDisplayRatioSdr then the SDR + * rendition is displayed. If the output display's HDR to SDR ratio is greater or equal than + * fDisplayRatioHdr then the HDR rendition is displayed. If the output display's HDR to SDR + * ratio is between these values then an interpolation between the two is displayed using the + * math above. + */ + float fDisplayRatioSdr = 1.f; + float fDisplayRatioHdr = 2.f; + + /** + * Whether the base image is the SDR image or the HDR image. + */ + enum class BaseImageType { + kSDR, + kHDR, + }; + BaseImageType fBaseImageType = BaseImageType::kSDR; + + inline bool operator==(const SkGainmapInfo& other) { + return fGainmapRatioMin == other.fGainmapRatioMin && + fGainmapRatioMax == other.fGainmapRatioMax && fGainmapGamma == other.fGainmapGamma && + fEpsilonSdr == other.fEpsilonSdr && fEpsilonHdr == other.fEpsilonHdr && + fDisplayRatioSdr == other.fDisplayRatioSdr && + fDisplayRatioHdr == other.fDisplayRatioHdr && fBaseImageType == other.fBaseImageType; + } + inline bool operator!=(const SkGainmapInfo& other) { return !(*this == other); } + + // TODO(ccameron): Remove these parameters once we are certain they are not used in Android. + enum class Type { + kUnknown, + kMultiPicture, + kJpegR_Linear, + kJpegR_HLG, + kJpegR_PQ, + kHDRGM, + }; + SkColor4f fLogRatioMin = {0.f, 0.f, 0.f, 1.0}; + SkColor4f fLogRatioMax = {1.f, 1.f, 1.f, 1.0}; + float fHdrRatioMin = 1.f; + float fHdrRatioMax = 50.f; + Type fType = Type::kUnknown; +}; + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h new file mode 100644 index 0000000000000..f490ab96a4cfc --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h @@ -0,0 +1,53 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkGainmapShader_DEFINED +#define SkGainmapShader_DEFINED + +#include "include/core/SkRefCnt.h" + +class SkColorSpace; +class SkShader; +class SkImage; +struct SkGainmapInfo; +struct SkRect; +struct SkSamplingOptions; + +/** + * A gainmap shader will apply a gainmap to an base image using the math described alongside the + * definition of SkGainmapInfo. + */ +class SK_API SkGainmapShader { +public: + /** + * Make a gainmap shader. + * + * When sampling the base image baseImage, the rectangle baseRect will be sampled to map to + * the rectangle dstRect. Sampling will be done according to baseSamplingOptions. + * + * When sampling the gainmap image gainmapImage, the rectangle gainmapRect will be sampled to + * map to the rectangle dstRect. Sampling will be done according to gainmapSamplingOptions. + * + * The gainmap will be applied according to the HDR to SDR ratio specified in dstHdrRatio. + * + * This shader must know the color space of the canvas that it will be rendered to. This color + * space must be specified in dstColorSpace. + * TODO(ccameron): Remove the need for dstColorSpace. + */ + static sk_sp Make(const sk_sp& baseImage, + const SkRect& baseRect, + const SkSamplingOptions& baseSamplingOptions, + const sk_sp& gainmapImage, + const SkRect& gainmapRect, + const SkSamplingOptions& gainmapSamplingOptions, + const SkGainmapInfo& gainmapInfo, + const SkRect& dstRect, + float dstHdrRatio, + sk_sp dstColorSpace); +}; + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h deleted file mode 100644 index 0888869607db7..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkHalf_DEFINED -#define SkHalf_DEFINED - -#include "include/core/SkTypes.h" -#include "include/private/SkVx.h" - -// 16-bit floating point value -// format is 1 bit sign, 5 bits exponent, 10 bits mantissa -// only used for storage -typedef uint16_t SkHalf; - -static constexpr uint16_t SK_HalfMin = 0x0400; // 2^-14 (minimum positive normal value) -static constexpr uint16_t SK_HalfMax = 0x7bff; // 65504 -static constexpr uint16_t SK_HalfEpsilon = 0x1400; // 2^-10 -static constexpr uint16_t SK_Half1 = 0x3C00; // 1 - -// convert between half and single precision floating point -float SkHalfToFloat(SkHalf h); -SkHalf SkFloatToHalf(float f); - -// Convert between half and single precision floating point, -// assuming inputs and outputs are both finite, and may -// flush values which would be denormal half floats to zero. -static inline skvx::float4 SkHalfToFloat_finite_ftz(uint64_t rgba) { - return skvx::from_half(skvx::half4::Load(&rgba)); -} -static inline skvx::half4 SkFloatToHalf_finite_ftz(const skvx::float4& c) { - return skvx::to_half(c); -} - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h index f7a5900e0e1ff..8ebb6ca18e53f 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h @@ -9,8 +9,9 @@ #define SkIDChangeListener_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkThreadAnnotations.h" #include @@ -65,7 +66,7 @@ class SkIDChangeListener : public SkRefCnt { private: mutable SkMutex fMutex; - SkTDArray fListeners SK_GUARDED_BY(fMutex); // pointers are reffed + skia_private::STArray<1, sk_sp> fListeners SK_GUARDED_BY(fMutex); }; private: diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h deleted file mode 100644 index 70b9d715f06b6..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkImageInfoPriv_DEFINED -#define SkImageInfoPriv_DEFINED - -#include "include/core/SkColor.h" -#include "include/core/SkImageInfo.h" - -static inline uint32_t SkColorTypeChannelFlags(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: return 0; - case kAlpha_8_SkColorType: return kAlpha_SkColorChannelFlag; - case kRGB_565_SkColorType: return kRGB_SkColorChannelFlags; - case kARGB_4444_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGB_888x_SkColorType: return kRGB_SkColorChannelFlags; - case kBGRA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_1010102_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGB_101010x_SkColorType: return kRGB_SkColorChannelFlags; - case kBGRA_1010102_SkColorType: return kRGBA_SkColorChannelFlags; - case kBGR_101010x_SkColorType: return kRGB_SkColorChannelFlags; - case kGray_8_SkColorType: return kGray_SkColorChannelFlag; - case kRGBA_F16Norm_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_F16_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_F32_SkColorType: return kRGBA_SkColorChannelFlags; - case kR8G8_unorm_SkColorType: return kRG_SkColorChannelFlags; - case kA16_unorm_SkColorType: return kAlpha_SkColorChannelFlag; - case kR16G16_unorm_SkColorType: return kRG_SkColorChannelFlags; - case kA16_float_SkColorType: return kAlpha_SkColorChannelFlag; - case kR16G16_float_SkColorType: return kRG_SkColorChannelFlags; - case kR16G16B16A16_unorm_SkColorType: return kRGBA_SkColorChannelFlags; - case kSRGBA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kR8_unorm_SkColorType: return kRed_SkColorChannelFlag; - } - SkUNREACHABLE; -} - -static inline bool SkColorTypeIsAlphaOnly(SkColorType ct) { - return SkColorTypeChannelFlags(ct) == kAlpha_SkColorChannelFlag; -} - -static inline bool SkAlphaTypeIsValid(unsigned value) { - return value <= kLastEnum_SkAlphaType; -} - -static int SkColorTypeShiftPerPixel(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: return 0; - case kAlpha_8_SkColorType: return 0; - case kRGB_565_SkColorType: return 1; - case kARGB_4444_SkColorType: return 1; - case kRGBA_8888_SkColorType: return 2; - case kRGB_888x_SkColorType: return 2; - case kBGRA_8888_SkColorType: return 2; - case kRGBA_1010102_SkColorType: return 2; - case kRGB_101010x_SkColorType: return 2; - case kBGRA_1010102_SkColorType: return 2; - case kBGR_101010x_SkColorType: return 2; - case kGray_8_SkColorType: return 0; - case kRGBA_F16Norm_SkColorType: return 3; - case kRGBA_F16_SkColorType: return 3; - case kRGBA_F32_SkColorType: return 4; - case kR8G8_unorm_SkColorType: return 1; - case kA16_unorm_SkColorType: return 1; - case kR16G16_unorm_SkColorType: return 2; - case kA16_float_SkColorType: return 1; - case kR16G16_float_SkColorType: return 2; - case kR16G16B16A16_unorm_SkColorType: return 3; - case kSRGBA_8888_SkColorType: return 2; - case kR8_unorm_SkColorType: return 0; - } - SkUNREACHABLE; -} - -static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { - return (size_t)(width * SkColorTypeBytesPerPixel(ct)); -} - -static inline bool SkColorTypeIsValid(unsigned value) { - return value <= kLastEnum_SkColorType; -} - -static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) { - if (kUnknown_SkColorType == ct) { - return 0; - } - return (size_t)y * rowBytes + ((size_t)x << SkColorTypeShiftPerPixel(ct)); -} - -static inline bool SkColorTypeIsNormalized(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: - case kAlpha_8_SkColorType: - case kRGB_565_SkColorType: - case kARGB_4444_SkColorType: - case kRGBA_8888_SkColorType: - case kRGB_888x_SkColorType: - case kBGRA_8888_SkColorType: - case kRGBA_1010102_SkColorType: - case kRGB_101010x_SkColorType: - case kBGRA_1010102_SkColorType: - case kBGR_101010x_SkColorType: - case kGray_8_SkColorType: - case kRGBA_F16Norm_SkColorType: - case kR8G8_unorm_SkColorType: - case kA16_unorm_SkColorType: - case kA16_float_SkColorType: /*subtle... alpha is always [0,1]*/ - case kR16G16_unorm_SkColorType: - case kR16G16B16A16_unorm_SkColorType: - case kSRGBA_8888_SkColorType: - case kR8_unorm_SkColorType: - return true; - - case kRGBA_F16_SkColorType: - case kRGBA_F32_SkColorType: - case kR16G16_float_SkColorType: - return false; - } - SkUNREACHABLE; -} - -static inline int SkColorTypeMaxBitsPerChannel(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: - return 0; - - case kARGB_4444_SkColorType: - return 4; - - case kRGB_565_SkColorType: - return 6; - - case kAlpha_8_SkColorType: - case kRGBA_8888_SkColorType: - case kRGB_888x_SkColorType: - case kBGRA_8888_SkColorType: - case kGray_8_SkColorType: - case kR8G8_unorm_SkColorType: - case kSRGBA_8888_SkColorType: - case kR8_unorm_SkColorType: - return 8; - - case kRGBA_1010102_SkColorType: - case kRGB_101010x_SkColorType: - case kBGRA_1010102_SkColorType: - case kBGR_101010x_SkColorType: - return 10; - - case kRGBA_F16Norm_SkColorType: - case kA16_unorm_SkColorType: - case kA16_float_SkColorType: - case kR16G16_unorm_SkColorType: - case kR16G16B16A16_unorm_SkColorType: - case kRGBA_F16_SkColorType: - case kR16G16_float_SkColorType: - return 16; - - case kRGBA_F32_SkColorType: - return 32; - } - SkUNREACHABLE; -} - -/** - * Returns true if |info| contains a valid colorType and alphaType. - */ -static inline bool SkColorInfoIsValid(const SkColorInfo& info) { - return info.colorType() != kUnknown_SkColorType && info.alphaType() != kUnknown_SkAlphaType; -} - -/** - * Returns true if |info| contains a valid combination of width, height and colorInfo. - */ -static inline bool SkImageInfoIsValid(const SkImageInfo& info) { - if (info.width() <= 0 || info.height() <= 0) { - return false; - } - - const int kMaxDimension = SK_MaxS32 >> 2; - if (info.width() > kMaxDimension || info.height() > kMaxDimension) { - return false; - } - - return SkColorInfoIsValid(info.colorInfo()); -} - -/** - * Returns true if Skia has defined a pixel conversion from the |src| to the |dst|. - * Returns false otherwise. - */ -static inline bool SkImageInfoValidConversion(const SkImageInfo& dst, const SkImageInfo& src) { - return SkImageInfoIsValid(dst) && SkImageInfoIsValid(src); -} -#endif // SkImageInfoPriv_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h new file mode 100644 index 0000000000000..756de78b23101 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h @@ -0,0 +1,71 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkJpegGainmapEncoder_DEFINED +#define SkJpegGainmapEncoder_DEFINED + +#include "include/encode/SkJpegEncoder.h" + +class SkPixmap; +class SkWStream; +struct SkGainmapInfo; + +class SK_API SkJpegGainmapEncoder { +public: + /** + * Encode a JpegR image to |dst|. + * + * The base image is specified by |base|, and |baseOptions| controls the encoding behavior for + * the base image. + * + * The gainmap image is specified by |gainmap|, and |gainmapOptions| controls the encoding + * behavior for the gainmap image. + * + * The rendering behavior of the gainmap image is provided in |gainmapInfo|. Not all gainmap + * based images are compatible with JpegR. If the image is not compatible with JpegR, then + * convert the gainmap to a format that is capable with JpegR. This conversion may result in + * less precise quantization of the gainmap image. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ + static bool EncodeJpegR(SkWStream* dst, + const SkPixmap& base, + const SkJpegEncoder::Options& baseOptions, + const SkPixmap& gainmap, + const SkJpegEncoder::Options& gainmapOptions, + const SkGainmapInfo& gainmapInfo); + + /** + * Encode an HDRGM image to |dst|. + * + * The base image is specified by |base|, and |baseOptions| controls the encoding behavior for + * the base image. + * + * The gainmap image is specified by |gainmap|, and |gainmapOptions| controls the encoding + * behavior for the gainmap image. + * + * The rendering behavior of the gainmap image is provided in |gainmapInfo|. + * + * If |baseOptions| or |gainmapOptions| specify XMP metadata, then that metadata will be + * overwritten. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ + static bool EncodeHDRGM(SkWStream* dst, + const SkPixmap& base, + const SkJpegEncoder::Options& baseOptions, + const SkPixmap& gainmap, + const SkJpegEncoder::Options& gainmapOptions, + const SkGainmapInfo& gainmapInfo); + + /** + * Write a Multi Picture Format containing the |imageCount| images specified by |images|. + */ + static bool MakeMPF(SkWStream* dst, const SkData** images, size_t imageCount); +}; + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h new file mode 100644 index 0000000000000..0b8f6ce1f7577 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h @@ -0,0 +1,61 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkJpegMetadataDecoder_DEFINED +#define SkJpegMetadataDecoder_DEFINED + +#include "include/core/SkData.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +#include +#include + +struct SkGainmapInfo; + +/** + * An interface that can be used to extract metadata from an encoded JPEG file. + * TODO(https://crbug.com/1404000): Add interface for ICC profile and EXIF extraction. + */ +class SK_API SkJpegMetadataDecoder { +public: + SkJpegMetadataDecoder() {} + virtual ~SkJpegMetadataDecoder() {} + + SkJpegMetadataDecoder(const SkJpegMetadataDecoder&) = delete; + SkJpegMetadataDecoder& operator=(const SkJpegMetadataDecoder&) = delete; + + /** + * A segment from a JPEG file. This is usually populated from a jpeg_marker_struct. + */ + struct SK_API Segment { + Segment(uint8_t marker, sk_sp data) : fMarker(marker), fData(std::move(data)) {} + + // The segment's marker. + uint8_t fMarker = 0; + + // The segment's parameters (not including the marker and parameter length). + sk_sp fData; + }; + + /** + * Create metadata for the specified segments from a JPEG file's header (defined as all segments + * before the first StartOfScan). This may return nullptr. + */ + static std::unique_ptr Make(std::vector headerSegments); + + /** + * Given a JPEG encoded image |baseImageData|, return in |outGainmapImageData| the JPEG encoded + * gainmap image and return in |outGainmapInfo| its gainmap rendering parameters. Return true if + * both output variables were successfully populated, otherwise return false. + */ + virtual bool findGainmapImage(sk_sp baseImageData, + sk_sp& outGainmapImagedata, + SkGainmapInfo& outGainmapInfo) = 0; +}; + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h index e57dc1433ff50..6e888b77c84c3 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h @@ -8,7 +8,9 @@ #ifndef SkOpts_spi_DEFINED #define SkOpts_spi_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" + +#include // These are exposed as SK_SPI (e.g. SkParagraph), the rest of SkOpts is // declared in src/core diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h index e72651dce7842..c0e0f08aa1bd9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h @@ -8,36 +8,25 @@ #ifndef SkPathRef_DEFINED #define SkPathRef_DEFINED -#include "include/core/SkMatrix.h" #include "include/core/SkPoint.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" #include "include/private/SkIDChangeListener.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" -#include "include/private/SkTemplates.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkTo.h" #include -#include +#include +#include #include +#include -class SkRBuffer; -class SkWBuffer; +class SkMatrix; class SkRRect; -enum class SkPathConvexity { - kConvex, - kConcave, - kUnknown, -}; - -enum class SkPathFirstDirection { - kCW, // == SkPathDirection::kCW - kCCW, // == SkPathDirection::kCCW - kUnknown, -}; - // These are computed from a stream of verbs struct SkPathVerbAnalysis { bool valid; @@ -64,7 +53,13 @@ SkPathVerbAnalysis sk_path_analyze_verbs(const uint8_t verbs[], int count); class SK_API SkPathRef final : public SkNVRefCnt { public: - SkPathRef(SkTDArray points, SkTDArray verbs, SkTDArray weights, + // See https://bugs.chromium.org/p/skia/issues/detail?id=13817 for how these sizes were + // determined. + using PointsArray = skia_private::STArray<4, SkPoint>; + using VerbsArray = skia_private::STArray<4, uint8_t>; + using ConicWeightsArray = skia_private::STArray<2, SkScalar>; + + SkPathRef(PointsArray points, VerbsArray verbs, ConicWeightsArray weights, unsigned segmentMask) : fPoints(std::move(points)) , fVerbs(std::move(verbs)) @@ -320,24 +315,15 @@ class SK_API SkPathRef final : public SkNVRefCnt { bool operator== (const SkPathRef& ref) const; - /** - * Writes the path points and verbs to a buffer. - */ - void writeToBuffer(SkWBuffer* buffer) const; - - /** - * Gets the number of bytes that would be written in writeBuffer() - */ - uint32_t writeSize() const; - void interpolate(const SkPathRef& ending, SkScalar weight, SkPathRef* out) const; /** * Gets an ID that uniquely identifies the contents of the path ref. If two path refs have the * same ID then they have the same verbs and points. However, two path refs may have the same * contents but different genIDs. + * skbug.com/1762 for background on why fillType is necessary (for now). */ - uint32_t genID() const; + uint32_t genID(uint8_t fillType) const; void addGenIDChangeListener(sk_sp); // Threadsafe. int genIDChangeListenerCount(); // Threadsafe @@ -346,6 +332,15 @@ class SK_API SkPathRef final : public SkNVRefCnt { bool isValid() const; SkDEBUGCODE(void validate() const { SkASSERT(this->isValid()); } ) + /** + * Resets this SkPathRef to a clean state. + */ + void reset(); + + bool isInitialEmptyPathRef() const { + return fGenerationID == kEmptyGenID; + } + private: enum SerializationOffsets { kLegacyRRectOrOvalStartIdx_SerializationShift = 28, // requires 3 bits, ignored. @@ -356,7 +351,7 @@ class SK_API SkPathRef final : public SkNVRefCnt { kSegmentMask_SerializationShift = 0 // requires 4 bits (deprecated) }; - SkPathRef() { + SkPathRef(int numVerbs = 0, int numPoints = 0) { fBoundsIsDirty = true; // this also invalidates fIsFinite fGenerationID = kEmptyGenID; fSegmentMask = 0; @@ -365,6 +360,10 @@ class SK_API SkPathRef final : public SkNVRefCnt { // The next two values don't matter unless fIsOval or fIsRRect are true. fRRectOrOvalIsCCW = false; fRRectOrOvalStartIdx = 0xAC; + if (numPoints > 0) + fPoints.reserve_back(numPoints); + if (numVerbs > 0) + fVerbs.reserve_back(numVerbs); SkDEBUGCODE(fEditorsAttached.store(0);) SkDEBUGCODE(this->validate();) } @@ -397,15 +396,20 @@ class SK_API SkPathRef final : public SkNVRefCnt { /** Makes additional room but does not change the counts or change the genID */ void incReserve(int additionalVerbs, int additionalPoints) { SkDEBUGCODE(this->validate();) - fPoints.reserve(fPoints.size() + additionalPoints); - fVerbs.reserve(fVerbs.size() + additionalVerbs); + // Use reserve() so that if there is not enough space, the array will grow with some + // additional space. This ensures repeated calls to grow won't always allocate. + if (additionalPoints > 0) + fPoints.reserve(fPoints.size() + additionalPoints); + if (additionalVerbs > 0) + fVerbs.reserve(fVerbs.size() + additionalVerbs); SkDEBUGCODE(this->validate();) } - /** Resets the path ref with verbCount verbs and pointCount points, all uninitialized. Also - * allocates space for reserveVerb additional verbs and reservePoints additional points.*/ - void resetToSize(int verbCount, int pointCount, int conicCount, - int reserveVerbs = 0, int reservePoints = 0) { + /** + * Resets all state except that of the verbs, points, and conic-weights. + * Intended to be called from other functions that reset state. + */ + void commonReset() { SkDEBUGCODE(this->validate();) this->callGenIDChangeListeners(); fBoundsIsDirty = true; // this also invalidates fIsFinite @@ -414,12 +418,25 @@ class SK_API SkPathRef final : public SkNVRefCnt { fSegmentMask = 0; fIsOval = false; fIsRRect = false; + } - fPoints.reserve(pointCount + reservePoints); - fPoints.resize(pointCount); - fVerbs.reserve(verbCount + reserveVerbs); - fVerbs.resize(verbCount); - fConicWeights.resize(conicCount); + /** Resets the path ref with verbCount verbs and pointCount points, all uninitialized. Also + * allocates space for reserveVerb additional verbs and reservePoints additional points.*/ + void resetToSize(int verbCount, int pointCount, int conicCount, + int reserveVerbs = 0, int reservePoints = 0) { + commonReset(); + // Use reserve_back() so the arrays are sized to exactly fit the data. + const int pointDelta = pointCount + reservePoints - fPoints.size(); + if (pointDelta > 0) { + fPoints.reserve_back(pointDelta); + } + fPoints.resize_back(pointCount); + const int verbDelta = verbCount + reserveVerbs - fVerbs.size(); + if (verbDelta > 0) { + fVerbs.reserve_back(verbDelta); + } + fVerbs.resize_back(verbCount); + fConicWeights.resize_back(conicCount); SkDEBUGCODE(this->validate();) } @@ -489,9 +506,9 @@ class SK_API SkPathRef final : public SkNVRefCnt { mutable SkRect fBounds; - SkTDArray fPoints; - SkTDArray fVerbs; - SkTDArray fConicWeights; + PointsArray fPoints; + VerbsArray fVerbs; + ConicWeightsArray fConicWeights; enum { kEmptyGenID = 1, // GenID reserved for path ref with zero points and zero verbs. diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h index 6e50a5b262594..058b231b138a3 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h @@ -11,7 +11,7 @@ #include #include "include/core/SkTypes.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" using SKSL_INT = int64_t; using SKSL_FLOAT = float; @@ -21,17 +21,17 @@ namespace SkSL { class Expression; class Statement; -using ComponentArray = SkSTArray<4, int8_t>; // for Swizzles +using ComponentArray = skia_private::STArray<4, int8_t>; // for Swizzles -class ExpressionArray : public SkSTArray<2, std::unique_ptr> { +class ExpressionArray : public skia_private::STArray<2, std::unique_ptr> { public: - using SkSTArray::SkSTArray; + using STArray::STArray; /** Returns a new ExpressionArray containing a clone of every element. */ ExpressionArray clone() const; }; -using StatementArray = SkSTArray<2, std::unique_ptr>; +using StatementArray = skia_private::STArray<2, std::unique_ptr>; // Functions larger than this (measured in IR nodes) will not be inlined. This growth factor // accounts for the number of calls being inlined--i.e., a function called five times (that is, with diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h deleted file mode 100644 index c11a56614c42b..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_IRNODE -#define SKSL_IRNODE - -#include "include/private/SkSLString.h" -#include "include/private/SkTArray.h" -#include "include/sksl/SkSLPosition.h" -#include "src/sksl/SkSLLexer.h" -#include "src/sksl/SkSLModifiersPool.h" -#include "src/sksl/SkSLPool.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Expression; -class FunctionDeclaration; -class FunctionDefinition; -class Statement; -class Symbol; -class SymbolTable; -class Type; -class Variable; -class VariableReference; -enum class VariableRefKind : int8_t; -enum class VariableStorage : int8_t; - -/** - * Represents a node in the intermediate representation (IR) tree. The IR is a fully-resolved - * version of the program (all types determined, everything validated), ready for code generation. - */ -class IRNode : public Poolable { -public: - virtual ~IRNode() {} - - virtual std::string description() const = 0; - - // No copy construction or assignment - IRNode(const IRNode&) = delete; - IRNode& operator=(const IRNode&) = delete; - - // position of this element within the program being compiled, for error reporting purposes - Position fPosition; - -protected: - IRNode(Position position, int kind) - : fPosition(position) - , fKind(kind) {} - - int fKind; -}; - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h deleted file mode 100644 index 1b00f0e7c67ed..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_LAYOUT -#define SKSL_LAYOUT - -#include "include/private/SkSLString.h" - -namespace SkSL { - -/** - * Represents a layout block appearing before a variable declaration, as in: - * - * layout (location = 0) int x; - */ -struct Layout { - enum Flag { - kOriginUpperLeft_Flag = 1 << 0, - kPushConstant_Flag = 1 << 1, - kBlendSupportAllEquations_Flag = 1 << 2, - kColor_Flag = 1 << 3, - - // These flags indicate if the qualifier appeared, regardless of the accompanying value. - kLocation_Flag = 1 << 4, - kOffset_Flag = 1 << 5, - kBinding_Flag = 1 << 6, - kIndex_Flag = 1 << 7, - kSet_Flag = 1 << 8, - kBuiltin_Flag = 1 << 9, - kInputAttachmentIndex_Flag = 1 << 10, - }; - - Layout(int flags, int location, int offset, int binding, int index, int set, int builtin, - int inputAttachmentIndex) - : fFlags(flags) - , fLocation(location) - , fOffset(offset) - , fBinding(binding) - , fIndex(index) - , fSet(set) - , fBuiltin(builtin) - , fInputAttachmentIndex(inputAttachmentIndex) {} - - Layout() - : fFlags(0) - , fLocation(-1) - , fOffset(-1) - , fBinding(-1) - , fIndex(-1) - , fSet(-1) - , fBuiltin(-1) - , fInputAttachmentIndex(-1) {} - - static Layout builtin(int builtin) { - Layout result; - result.fBuiltin = builtin; - return result; - } - - std::string description() const { - std::string result; - auto separator = [firstSeparator = true]() mutable -> std::string { - if (firstSeparator) { - firstSeparator = false; - return ""; - } else { - return ", "; - }}; - if (fLocation >= 0) { - result += separator() + "location = " + std::to_string(fLocation); - } - if (fOffset >= 0) { - result += separator() + "offset = " + std::to_string(fOffset); - } - if (fBinding >= 0) { - result += separator() + "binding = " + std::to_string(fBinding); - } - if (fIndex >= 0) { - result += separator() + "index = " + std::to_string(fIndex); - } - if (fSet >= 0) { - result += separator() + "set = " + std::to_string(fSet); - } - if (fBuiltin >= 0) { - result += separator() + "builtin = " + std::to_string(fBuiltin); - } - if (fInputAttachmentIndex >= 0) { - result += separator() + "input_attachment_index = " + - std::to_string(fInputAttachmentIndex); - } - if (fFlags & kOriginUpperLeft_Flag) { - result += separator() + "origin_upper_left"; - } - if (fFlags & kBlendSupportAllEquations_Flag) { - result += separator() + "blend_support_all_equations"; - } - if (fFlags & kPushConstant_Flag) { - result += separator() + "push_constant"; - } - if (fFlags & kColor_Flag) { - result += separator() + "color"; - } - if (result.size() > 0) { - result = "layout (" + result + ")"; - } - return result; - } - - bool operator==(const Layout& other) const { - return fFlags == other.fFlags && - fLocation == other.fLocation && - fOffset == other.fOffset && - fBinding == other.fBinding && - fIndex == other.fIndex && - fSet == other.fSet && - fBuiltin == other.fBuiltin && - fInputAttachmentIndex == other.fInputAttachmentIndex; - } - - bool operator!=(const Layout& other) const { - return !(*this == other); - } - - int fFlags; - int fLocation; - int fOffset; - int fBinding; - int fIndex; - int fSet; - // builtin comes from SPIR-V and identifies which particular builtin value this object - // represents. - int fBuiltin; - // input_attachment_index comes from Vulkan/SPIR-V to connect a shader variable to the a - // corresponding attachment on the subpass in which the shader is being used. - int fInputAttachmentIndex; -}; - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h deleted file mode 100644 index 732810b7da71c..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_MODIFIERS -#define SKSL_MODIFIERS - -#include "include/private/SkSLLayout.h" - -#include -#include -#include - -namespace SkSL { - -class Context; -class Position; - -/** - * A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration. - */ -struct Modifiers { - /** - * OpenGL requires modifiers to be in a strict order: - * - invariant-qualifier: (invariant) - * - interpolation-qualifier: flat, noperspective, (smooth) - * - storage-qualifier: const, uniform - * - parameter-qualifier: in, out, inout - * - precision-qualifier: highp, mediump, lowp - * - * SkSL does not have `invariant` or `smooth`. - */ - - enum Flag { - kNo_Flag = 0, - // Real GLSL modifiers - kFlat_Flag = 1 << 0, - kNoPerspective_Flag = 1 << 1, - kConst_Flag = 1 << 2, - kUniform_Flag = 1 << 3, - kIn_Flag = 1 << 4, - kOut_Flag = 1 << 5, - kHighp_Flag = 1 << 6, - kMediump_Flag = 1 << 7, - kLowp_Flag = 1 << 8, - kReadOnly_Flag = 1 << 9, - kWriteOnly_Flag = 1 << 10, - kBuffer_Flag = 1 << 11, - // We use the Metal name for this one (corresponds to the GLSL 'shared' modifier) - kThreadgroup_Flag = 1 << 12, - // SkSL extensions, not present in GLSL - kExport_Flag = 1 << 13, - kES3_Flag = 1 << 14, - kPure_Flag = 1 << 15, - kInline_Flag = 1 << 16, - kNoInline_Flag = 1 << 17, - }; - - Modifiers() - : fLayout(Layout()) - , fFlags(0) {} - - Modifiers(const Layout& layout, int flags) - : fLayout(layout) - , fFlags(flags) {} - - std::string description() const { - return fLayout.description() + DescribeFlags(fFlags) + " "; - } - - static std::string DescribeFlags(int flags) { - // SkSL extensions - std::string result; - if (flags & kExport_Flag) { - result += "$export "; - } - if (flags & kES3_Flag) { - result += "$es3 "; - } - if (flags & kPure_Flag) { - result += "$pure "; - } - if (flags & kInline_Flag) { - result += "inline "; - } - if (flags & kNoInline_Flag) { - result += "noinline "; - } - - // Real GLSL qualifiers (must be specified in order in GLSL 4.1 and below) - if (flags & kFlat_Flag) { - result += "flat "; - } - if (flags & kNoPerspective_Flag) { - result += "noperspective "; - } - if (flags & kConst_Flag) { - result += "const "; - } - if (flags & kUniform_Flag) { - result += "uniform "; - } - if ((flags & kIn_Flag) && (flags & kOut_Flag)) { - result += "inout "; - } else if (flags & kIn_Flag) { - result += "in "; - } else if (flags & kOut_Flag) { - result += "out "; - } - if (flags & kHighp_Flag) { - result += "highp "; - } - if (flags & kMediump_Flag) { - result += "mediump "; - } - if (flags & kLowp_Flag) { - result += "lowp "; - } - if (flags & kReadOnly_Flag) { - result += "readonly "; - } - if (flags & kWriteOnly_Flag) { - result += "writeonly "; - } - if (flags & kBuffer_Flag) { - result += "buffer "; - } - - // We're using a non-GLSL name for this one; the GLSL equivalent is "shared" - if (flags & kThreadgroup_Flag) { - result += "threadgroup "; - } - - if (!result.empty()) { - result.pop_back(); - } - return result; - } - - bool operator==(const Modifiers& other) const { - return fLayout == other.fLayout && fFlags == other.fFlags; - } - - bool operator!=(const Modifiers& other) const { - return !(*this == other); - } - - /** - * Verifies that only permitted modifiers and layout flags are included. Reports errors and - * returns false in the event of a violation. - */ - bool checkPermitted(const Context& context, - Position pos, - int permittedModifierFlags, - int permittedLayoutFlags) const; - - Layout fLayout; - int fFlags; -}; - -} // namespace SkSL - -namespace std { - -template <> -struct hash { - size_t operator()(const SkSL::Modifiers& key) const { - return (size_t) key.fFlags ^ ((size_t) key.fLayout.fFlags << 8) ^ - ((size_t) key.fLayout.fBuiltin << 16); - } -}; - -} // namespace std - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h deleted file mode 100644 index 8eb0a31aadab6..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_PROGRAMELEMENT -#define SKSL_PROGRAMELEMENT - -#include "include/private/SkSLIRNode.h" - -#include - -namespace SkSL { - -/** - * Represents a top-level element (e.g. function or global variable) in a program. - */ -class ProgramElement : public IRNode { -public: - enum class Kind { - kExtension = 0, - kFunction, - kFunctionPrototype, - kGlobalVar, - kInterfaceBlock, - kModifiers, - kStructDefinition, - - kFirst = kExtension, - kLast = kStructDefinition - }; - - ProgramElement(Position pos, Kind kind) - : INHERITED(pos, (int) kind) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - Kind kind() const { - return (Kind) fKind; - } - - /** - * Use is to check the type of a program element. - * e.g. replace `el.kind() == ProgramElement::Kind::kExtension` with `el.is()`. - */ - template - bool is() const { - return this->kind() == T::kProgramElementKind; - } - - /** - * Use as to downcast program elements. e.g. replace `(Extension&) el` with - * `el.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - - virtual std::unique_ptr clone() const = 0; - -private: - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h deleted file mode 100644 index c240cb7376e60..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSLProgramKind_DEFINED -#define SkSLProgramKind_DEFINED - -#include - -namespace SkSL { - -/** - * SkSL supports several different program kinds. - */ -enum class ProgramKind : int8_t { - kFragment, - kVertex, - kCompute, - kGraphiteFragment, - kGraphiteVertex, - kRuntimeColorFilter, // Runtime effect only suitable as SkColorFilter - kRuntimeShader, // " " " " " SkShader - kRuntimeBlender, // " " " " " SkBlender - kPrivateRuntimeShader, // Runtime shader with public restrictions lifted - kMeshVertex, // Vertex portion of a custom mesh - kMeshFragment, // Fragment " " " " " - kGeneric, -}; - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h index a8d67a025a82d..39d9e258180e8 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h @@ -10,8 +10,6 @@ #include "include/core/SkTypes.h" -#include - namespace SkSL { /** @@ -77,8 +75,6 @@ class SampleUsage { bool isUniformMatrix() const { return fKind == Kind::kUniformMatrix; } bool isFragCoord() const { return fKind == Kind::kFragCoord; } - std::string constructor() const; - private: Kind fKind = Kind::kNone; bool fHasPerspective = false; // Only valid if fKind is kUniformMatrix diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h deleted file mode 100644 index 43a1fdc8f3757..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_STATEMENT -#define SKSL_STATEMENT - -#include "include/private/SkSLIRNode.h" -#include "include/private/SkSLSymbol.h" - -namespace SkSL { - -/** - * Abstract supertype of all statements. - */ -class Statement : public IRNode { -public: - enum Kind { - kBlock = (int) Symbol::Kind::kLast + 1, - kBreak, - kContinue, - kDiscard, - kDo, - kExpression, - kFor, - kIf, - kNop, - kReturn, - kSwitch, - kSwitchCase, - kVarDeclaration, - - kFirst = kBlock, - kLast = kVarDeclaration, - }; - - Statement(Position pos, Kind kind) - : INHERITED(pos, (int) kind) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - Kind kind() const { - return (Kind) fKind; - } - - /** - * Use is to check the type of a statement. - * e.g. replace `s.kind() == Statement::Kind::kReturn` with `s.is()`. - */ - template - bool is() const { - return this->fKind == T::kStatementKind; - } - - /** - * Use as to downcast statements. - * e.g. replace `(ReturnStatement&) s` with `s.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - - virtual bool isEmpty() const { - return false; - } - - virtual std::unique_ptr clone() const = 0; - -private: - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h deleted file mode 100644 index 4458a2f0f5b45..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_STRING -#define SKSL_STRING - -#include "include/core/SkTypes.h" -#include "include/private/SkSLDefines.h" - -#include -#include -#include - -namespace SkSL { - -bool stod(std::string_view s, SKSL_FLOAT* value); -bool stoi(std::string_view s, SKSL_INT* value); - -namespace String { - -std::string printf(const char* fmt, ...) SK_PRINTF_LIKE(1, 2); -void appendf(std::string* str, const char* fmt, ...) SK_PRINTF_LIKE(2, 3); -void vappendf(std::string* str, const char* fmt, va_list va) SK_PRINTF_LIKE(2, 0); - -} // namespace String -} // namespace SkSL - -namespace skstd { - -// We use a custom to_string(float|double) which ignores locale settings and writes `1.0` instead -// of `1.00000`. -std::string to_string(float value); -std::string to_string(double value); - -} // namespace skstd - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h deleted file mode 100644 index d7b40c8d11ae7..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_SYMBOL -#define SKSL_SYMBOL - -#include "include/private/SkSLIRNode.h" -#include "include/private/SkSLProgramElement.h" - -namespace SkSL { - -/** - * Represents a symboltable entry. - */ -class Symbol : public IRNode { -public: - enum class Kind { - kExternal = (int) ProgramElement::Kind::kLast + 1, - kField, - kFunctionDeclaration, - kType, - kVariable, - - kFirst = kExternal, - kLast = kVariable - }; - - Symbol(Position pos, Kind kind, std::string_view name, const Type* type = nullptr) - : INHERITED(pos, (int) kind) - , fName(name) - , fType(type) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - ~Symbol() override {} - - const Type& type() const { - SkASSERT(fType); - return *fType; - } - - Kind kind() const { - return (Kind) fKind; - } - - std::string_view name() const { - return fName; - } - - /** - * Don't call this directly--use SymbolTable::renameSymbol instead! - */ - void setName(std::string_view newName) { - fName = newName; - } - - /** - * Use is to check the type of a symbol. - * e.g. replace `sym.kind() == Symbol::Kind::kVariable` with `sym.is()`. - */ - template - bool is() const { - return this->kind() == T::kSymbolKind; - } - - /** - * Use as to downcast symbols. e.g. replace `(Variable&) sym` with `sym.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - -private: - std::string_view fName; - const Type* fType; - - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h deleted file mode 100644 index 144b28a4a3b3a..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSafe_math_DEFINED -#define SkSafe_math_DEFINED - -// This file protects against known bugs in ucrt\math.h. -// Namely, that header defines inline methods without marking them static, -// which makes it very easy to cause ODR violations and ensuing chaos. -// -// TODO: other headers? Here are some potential problem headers: -// $ grep -R __inline * | grep -v static | cut -f 1 -d: | sort | uniq -// corecrt.h -// corecrt_stdio_config.h -// ctype.h -// fenv.h -// locale.h -// malloc.h -// math.h -// tchar.h -// wchar.h -// I took a quick look through other headers outside math.h. -// Nothing looks anywhere near as likely to be used by Skia as math.h. - -#if defined(_MSC_VER) && !defined(_INC_MATH) - // Our strategy here is to simply inject "static" into the headers - // where it should have been written, just before __inline. - // - // Most inline-but-not-static methods in math.h are 32-bit only, - // but not all of them (see frexpf, hypothf, ldexpf...). So to - // be safe, 32- and 64-bit builds both get this treatment. - - #define __inline static __inline - #include - #undef __inline - - #if !defined(_INC_MATH) - #error Hmm. Looks like math.h has changed its header guards. - #endif - - #define INC_MATH_IS_SAFE_NOW - -#else - #include - -#endif - -#endif//SkSafe_math_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h index e1d5011681e5f..3816dc9dff022 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h @@ -9,7 +9,7 @@ #define SkSpinlock_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkThreadAnnotations.h" #include class SK_CAPABILITY("mutex") SkSpinlock { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h deleted file mode 100644 index bf2f3da25eb60..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkStringView_DEFINED -#define SkStringView_DEFINED - -#include -#include - -namespace skstd { - -// C++20 additions -inline constexpr bool starts_with(std::string_view str, std::string_view prefix) { - if (prefix.length() > str.length()) { - return false; - } - return prefix.length() == 0 || !memcmp(str.data(), prefix.data(), prefix.length()); -} - -inline constexpr bool starts_with(std::string_view str, std::string_view::value_type c) { - return !str.empty() && str.front() == c; -} - -inline constexpr bool ends_with(std::string_view str, std::string_view suffix) { - if (suffix.length() > str.length()) { - return false; - } - return suffix.length() == 0 || !memcmp(str.data() + str.length() - suffix.length(), - suffix.data(), suffix.length()); -} - -inline constexpr bool ends_with(std::string_view str, std::string_view::value_type c) { - return !str.empty() && str.back() == c; -} - -// C++23 additions -inline constexpr bool contains(std::string_view str, std::string_view needle) { - return str.find(needle) != std::string_view::npos; -} - -inline constexpr bool contains(std::string_view str, std::string_view::value_type c) { - return str.find(c) != std::string_view::npos; -} - -} // namespace skstd - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h deleted file mode 100644 index 5082669c4f3d6..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h +++ /dev/null @@ -1,655 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkTArray_DEFINED -#define SkTArray_DEFINED - -#include "include/core/SkMath.h" -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkSafe32.h" -#include "include/private/SkTLogic.h" -#include "include/private/SkTemplates.h" -#include "include/private/SkTo.h" - -#include -#include -#include -#include -#include -#include - -/** SkTArray implements a typical, mostly std::vector-like array. - Each T will be default-initialized on allocation, and ~T will be called on destruction. - - MEM_MOVE controls the behavior when a T needs to be moved (e.g. when the array is resized) - - true: T will be bit-copied via memcpy. - - false: T will be moved via move-constructors. - - Modern implementations of std::vector will generally provide similar performance - characteristics when used with appropriate care. Consider using std::vector in new code. -*/ -template ::value> class SkTArray { -private: - enum ReallocType { kExactFit, kGrowing, kShrinking }; - -public: - using value_type = T; - - /** - * Creates an empty array with no initial storage - */ - SkTArray() { this->init(0); } - - /** - * Creates an empty array that will preallocate space for reserveCount - * elements. - */ - explicit SkTArray(int reserveCount) : SkTArray() { this->reserve_back(reserveCount); } - - /** - * Copies one array to another. The new array will be heap allocated. - */ - SkTArray(const SkTArray& that) - : SkTArray(that.fItemArray, that.fCount) {} - - SkTArray(SkTArray&& that) { - if (that.fOwnMemory) { - fItemArray = that.fItemArray; - fCount = that.fCount; - fAllocCount = that.fAllocCount; - fOwnMemory = true; - fReserved = that.fReserved; - - that.fItemArray = nullptr; - that.fCount = 0; - that.fAllocCount = 0; - that.fOwnMemory = true; - that.fReserved = false; - } else { - this->init(that.fCount); - that.move(fItemArray); - that.fCount = 0; - } - } - - /** - * Creates a SkTArray by copying contents of a standard C array. The new - * array will be heap allocated. Be careful not to use this constructor - * when you really want the (void*, int) version. - */ - SkTArray(const T* array, int count) { - this->init(count); - this->copy(array); - } - /** - * Creates a SkTArray by copying contents of an initializer list. - */ - SkTArray(std::initializer_list data) - : SkTArray(data.begin(), data.size()) {} - - SkTArray& operator=(const SkTArray& that) { - if (this == &that) { - return *this; - } - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(that.count(), kExactFit); - fCount = that.fCount; - this->copy(that.fItemArray); - return *this; - } - SkTArray& operator=(SkTArray&& that) { - if (this == &that) { - return *this; - } - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(that.count(), kExactFit); - fCount = that.fCount; - that.move(fItemArray); - that.fCount = 0; - return *this; - } - - ~SkTArray() { - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - if (fOwnMemory) { - sk_free(fItemArray); - } - } - - /** - * Resets to count() == 0 and resets any reserve count. - */ - void reset() { - this->pop_back_n(fCount); - fReserved = false; - } - - /** - * Resets to count() = n newly constructed T objects and resets any reserve count. - */ - void reset(int n) { - SkASSERT(n >= 0); - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - // Set fCount to 0 before calling checkRealloc so that no elements are moved. - fCount = 0; - this->checkRealloc(n, kExactFit); - fCount = n; - for (int i = 0; i < this->count(); ++i) { - new (fItemArray + i) T; - } - fReserved = false; - } - - /** - * Resets to a copy of a C array and resets any reserve count. - */ - void reset(const T* array, int count) { - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(count, kExactFit); - fCount = count; - this->copy(array); - fReserved = false; - } - - /** - * Ensures there is enough reserved space for n additional elements. The is guaranteed at least - * until the array size grows above n and subsequently shrinks below n, any version of reset() - * is called, or reserve_back() is called again. - */ - void reserve_back(int n) { - SkASSERT(n >= 0); - if (n > 0) { - this->checkRealloc(n, kExactFit); - fReserved = fOwnMemory; - } else { - fReserved = false; - } - } - - void removeShuffle(int n) { - SkASSERT(n < this->count()); - int newCount = fCount - 1; - fCount = newCount; - fItemArray[n].~T(); - if (n != newCount) { - this->move(n, newCount); - } - } - - /** - * Number of elements in the array. - */ - int count() const { return fCount; } - - /** - * Is the array empty. - */ - bool empty() const { return !fCount; } - - /** - * Adds 1 new default-initialized T value and returns it by reference. Note - * the reference only remains valid until the next call that adds or removes - * elements. - */ - T& push_back() { - void* newT = this->push_back_raw(1); - return *new (newT) T; - } - - /** - * Version of above that uses a copy constructor to initialize the new item - */ - T& push_back(const T& t) { - void* newT = this->push_back_raw(1); - return *new (newT) T(t); - } - - /** - * Version of above that uses a move constructor to initialize the new item - */ - T& push_back(T&& t) { - void* newT = this->push_back_raw(1); - return *new (newT) T(std::move(t)); - } - - /** - * Construct a new T at the back of this array. - */ - template T& emplace_back(Args&&... args) { - void* newT = this->push_back_raw(1); - return *new (newT) T(std::forward(args)...); - } - - /** - * Allocates n more default-initialized T values, and returns the address of - * the start of that new range. Note: this address is only valid until the - * next API call made on the array that might add or remove elements. - */ - T* push_back_n(int n) { - SkASSERT(n >= 0); - void* newTs = this->push_back_raw(n); - for (int i = 0; i < n; ++i) { - new (static_cast(newTs) + i * sizeof(T)) T; - } - return static_cast(newTs); - } - - /** - * Version of above that uses a copy constructor to initialize all n items - * to the same T. - */ - T* push_back_n(int n, const T& t) { - SkASSERT(n >= 0); - void* newTs = this->push_back_raw(n); - for (int i = 0; i < n; ++i) { - new (static_cast(newTs) + i * sizeof(T)) T(t); - } - return static_cast(newTs); - } - - /** - * Version of above that uses a copy constructor to initialize the n items - * to separate T values. - */ - T* push_back_n(int n, const T t[]) { - SkASSERT(n >= 0); - this->checkRealloc(n, kGrowing); - for (int i = 0; i < n; ++i) { - new (fItemArray + fCount + i) T(t[i]); - } - fCount += n; - return fItemArray + fCount - n; - } - - /** - * Version of above that uses the move constructor to set n items. - */ - T* move_back_n(int n, T* t) { - SkASSERT(n >= 0); - this->checkRealloc(n, kGrowing); - for (int i = 0; i < n; ++i) { - new (fItemArray + fCount + i) T(std::move(t[i])); - } - fCount += n; - return fItemArray + fCount - n; - } - - /** - * Removes the last element. Not safe to call when count() == 0. - */ - void pop_back() { - SkASSERT(fCount > 0); - --fCount; - fItemArray[fCount].~T(); - this->checkRealloc(0, kShrinking); - } - - /** - * Removes the last n elements. Not safe to call when count() < n. - */ - void pop_back_n(int n) { - SkASSERT(n >= 0); - SkASSERT(this->count() >= n); - fCount -= n; - for (int i = 0; i < n; ++i) { - fItemArray[fCount + i].~T(); - } - this->checkRealloc(0, kShrinking); - } - - /** - * Pushes or pops from the back to resize. Pushes will be default - * initialized. - */ - void resize_back(int newCount) { - SkASSERT(newCount >= 0); - - if (newCount > this->count()) { - this->push_back_n(newCount - fCount); - } else if (newCount < this->count()) { - this->pop_back_n(fCount - newCount); - } - } - - /** Swaps the contents of this array with that array. Does a pointer swap if possible, - otherwise copies the T values. */ - void swap(SkTArray& that) { - using std::swap; - if (this == &that) { - return; - } - if (fOwnMemory && that.fOwnMemory) { - swap(fItemArray, that.fItemArray); - - auto count = fCount; - fCount = that.fCount; - that.fCount = count; - - auto allocCount = fAllocCount; - fAllocCount = that.fAllocCount; - that.fAllocCount = allocCount; - } else { - // This could be more optimal... - SkTArray copy(std::move(that)); - that = std::move(*this); - *this = std::move(copy); - } - } - - T* begin() { - return fItemArray; - } - const T* begin() const { - return fItemArray; - } - T* end() { - return fItemArray ? fItemArray + fCount : nullptr; - } - const T* end() const { - return fItemArray ? fItemArray + fCount : nullptr; - } - T* data() { return fItemArray; } - const T* data() const { return fItemArray; } - size_t size() const { return (size_t)fCount; } - void resize(size_t count) { this->resize_back((int)count); } - - /** - * Get the i^th element. - */ - T& operator[] (int i) { - SkASSERT(i < this->count()); - SkASSERT(i >= 0); - return fItemArray[i]; - } - - const T& operator[] (int i) const { - SkASSERT(i < this->count()); - SkASSERT(i >= 0); - return fItemArray[i]; - } - - T& at(int i) { return (*this)[i]; } - const T& at(int i) const { return (*this)[i]; } - - /** - * equivalent to operator[](0) - */ - T& front() { SkASSERT(fCount > 0); return fItemArray[0];} - - const T& front() const { SkASSERT(fCount > 0); return fItemArray[0];} - - /** - * equivalent to operator[](count() - 1) - */ - T& back() { SkASSERT(fCount); return fItemArray[fCount - 1];} - - const T& back() const { SkASSERT(fCount > 0); return fItemArray[fCount - 1];} - - /** - * equivalent to operator[](count()-1-i) - */ - T& fromBack(int i) { - SkASSERT(i >= 0); - SkASSERT(i < this->count()); - return fItemArray[fCount - i - 1]; - } - - const T& fromBack(int i) const { - SkASSERT(i >= 0); - SkASSERT(i < this->count()); - return fItemArray[fCount - i - 1]; - } - - bool operator==(const SkTArray& right) const { - int leftCount = this->count(); - if (leftCount != right.count()) { - return false; - } - for (int index = 0; index < leftCount; ++index) { - if (fItemArray[index] != right.fItemArray[index]) { - return false; - } - } - return true; - } - - bool operator!=(const SkTArray& right) const { - return !(*this == right); - } - - int capacity() const { - return fAllocCount; - } - -protected: - /** - * Creates an empty array that will use the passed storage block until it - * is insufficiently large to hold the entire array. - */ - template - SkTArray(SkAlignedSTStorage* storage) { - this->initWithPreallocatedStorage(0, storage->get(), N); - } - - /** - * Copy a C array, using preallocated storage if preAllocCount >= - * count. Otherwise storage will only be used when array shrinks - * to fit. - */ - template - SkTArray(const T* array, int count, SkAlignedSTStorage* storage) { - this->initWithPreallocatedStorage(count, storage->get(), N); - this->copy(array); - } - -private: - // We disable Control-Flow Integrity sanitization (go/cfi) when casting item-array buffers. - // CFI flags this code as dangerous because we are casting `buffer` to a T* while the buffer's - // contents might still be uninitialized memory. When T has a vtable, this is especially risky - // because we could hypothetically access a virtual method on fItemArray and jump to an - // unpredictable location in memory. Of course, SkTArray won't actually use fItemArray in this - // way, and we don't want to construct a T before the user requests one. There's no real risk - // here, so disable CFI when doing these casts. - SK_ATTRIBUTE(no_sanitize("cfi")) - static T* TCast(void* buffer) { - return (T*)buffer; - } - - void init(int count) { - fCount = SkToU32(count); - if (!count) { - fAllocCount = 0; - fItemArray = nullptr; - } else { - fAllocCount = SkToU32(std::max(count, kMinHeapAllocCount)); - fItemArray = TCast(sk_malloc_throw((size_t)fAllocCount, sizeof(T))); - } - fOwnMemory = true; - fReserved = false; - } - - void initWithPreallocatedStorage(int count, void* preallocStorage, int preallocCount) { - SkASSERT(count >= 0); - SkASSERT(preallocCount > 0); - SkASSERT(preallocStorage); - fCount = SkToU32(count); - fItemArray = nullptr; - fReserved = false; - if (count > preallocCount) { - fAllocCount = SkToU32(std::max(count, kMinHeapAllocCount)); - fItemArray = TCast(sk_malloc_throw(fAllocCount, sizeof(T))); - fOwnMemory = true; - } else { - fAllocCount = SkToU32(preallocCount); - fItemArray = TCast(preallocStorage); - fOwnMemory = false; - } - } - - /** In the following move and copy methods, 'dst' is assumed to be uninitialized raw storage. - * In the following move methods, 'src' is destroyed leaving behind uninitialized raw storage. - */ - void copy(const T* src) { - // Some types may be trivially copyable, in which case we *could* use memcopy; but - // MEM_MOVE == true implies that the type is trivially movable, and not necessarily - // trivially copyable (think sk_sp<>). So short of adding another template arg, we - // must be conservative and use copy construction. - for (int i = 0; i < this->count(); ++i) { - new (fItemArray + i) T(src[i]); - } - } - - template std::enable_if_t move(int dst, int src) { - memcpy(static_cast(&fItemArray[dst]), - static_cast(&fItemArray[src]), - sizeof(T)); - } - template std::enable_if_t move(void* dst) { - sk_careful_memcpy(dst, fItemArray, fCount * sizeof(T)); - } - - template std::enable_if_t move(int dst, int src) { - new (&fItemArray[dst]) T(std::move(fItemArray[src])); - fItemArray[src].~T(); - } - template std::enable_if_t move(void* dst) { - for (int i = 0; i < this->count(); ++i) { - new (static_cast(dst) + sizeof(T) * (size_t)i) T(std::move(fItemArray[i])); - fItemArray[i].~T(); - } - } - - static constexpr int kMinHeapAllocCount = 8; - - // Helper function that makes space for n objects, adjusts the count, but does not initialize - // the new objects. - void* push_back_raw(int n) { - this->checkRealloc(n, kGrowing); - void* ptr = fItemArray + fCount; - fCount += n; - return ptr; - } - - void checkRealloc(int delta, ReallocType reallocType) { - SkASSERT(fCount >= 0); - SkASSERT(fAllocCount >= 0); - SkASSERT(-delta <= this->count()); - - // Move into 64bit math temporarily, to avoid local overflows - int64_t newCount = fCount + delta; - - // We allow fAllocCount to be in the range [newCount, 3*newCount]. We also never shrink - // when we're currently using preallocated memory, would allocate less than - // kMinHeapAllocCount, or a reserve count was specified that has yet to be exceeded. - bool mustGrow = newCount > fAllocCount; - bool shouldShrink = fAllocCount > 3 * newCount && fOwnMemory && !fReserved; - if (!mustGrow && !shouldShrink) { - return; - } - - int64_t newAllocCount = newCount; - if (reallocType != kExactFit) { - // Whether we're growing or shrinking, leave at least 50% extra space for future growth. - newAllocCount += ((newCount + 1) >> 1); - // Align the new allocation count to kMinHeapAllocCount. - static_assert(SkIsPow2(kMinHeapAllocCount), "min alloc count not power of two."); - newAllocCount = (newAllocCount + (kMinHeapAllocCount - 1)) & ~(kMinHeapAllocCount - 1); - } - - // At small sizes the old and new alloc count can both be kMinHeapAllocCount. - if (newAllocCount == fAllocCount) { - return; - } - - fAllocCount = SkToU32(Sk64_pin_to_s32(newAllocCount)); - SkASSERT(fAllocCount >= newCount); - T* newItemArray = TCast(sk_malloc_throw((size_t)fAllocCount, sizeof(T))); - this->move(newItemArray); - if (fOwnMemory) { - sk_free(fItemArray); - } - fItemArray = newItemArray; - fOwnMemory = true; - fReserved = false; - } - - T* fItemArray; - uint32_t fOwnMemory : 1; - uint32_t fCount : 31; - uint32_t fReserved : 1; - uint32_t fAllocCount : 31; -}; - -template static inline void swap(SkTArray& a, SkTArray& b) { - a.swap(b); -} - -template constexpr int SkTArray::kMinHeapAllocCount; - -/** - * Subclass of SkTArray that contains a preallocated memory block for the array. - */ -template ::value> -class SkSTArray : private SkAlignedSTStorage, public SkTArray { -private: - using STORAGE = SkAlignedSTStorage; - using INHERITED = SkTArray; - -public: - SkSTArray() - : STORAGE{}, INHERITED(static_cast(this)) {} - - SkSTArray(const T* array, int count) - : STORAGE{}, INHERITED(array, count, static_cast(this)) {} - - SkSTArray(std::initializer_list data) - : SkSTArray(data.begin(), data.size()) {} - - explicit SkSTArray(int reserveCount) - : SkSTArray() { - this->reserve_back(reserveCount); - } - - SkSTArray (const SkSTArray& that) : SkSTArray() { *this = that; } - explicit SkSTArray(const INHERITED& that) : SkSTArray() { *this = that; } - SkSTArray ( SkSTArray&& that) : SkSTArray() { *this = std::move(that); } - explicit SkSTArray( INHERITED&& that) : SkSTArray() { *this = std::move(that); } - - SkSTArray& operator=(const SkSTArray& that) { - INHERITED::operator=(that); - return *this; - } - SkSTArray& operator=(const INHERITED& that) { - INHERITED::operator=(that); - return *this; - } - - SkSTArray& operator=(SkSTArray&& that) { - INHERITED::operator=(std::move(that)); - return *this; - } - SkSTArray& operator=(INHERITED&& that) { - INHERITED::operator=(std::move(that)); - return *this; - } -}; - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h deleted file mode 100644 index 2cd89fd2f4df5..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 SkUniquePaintParamsID_DEFINED -#define SkUniquePaintParamsID_DEFINED - -#include "include/core/SkTypes.h" - -// This class boils down to a unique uint that can be used instead of a variable length -// key derived from a PaintParams. -class SkUniquePaintParamsID { -public: - explicit SkUniquePaintParamsID(uint32_t id) : fID(id) { - SkASSERT(id != SK_InvalidUniqueID); - } - - static SkUniquePaintParamsID InvalidID() { return SkUniquePaintParamsID(); } - - SkUniquePaintParamsID() : fID(SK_InvalidUniqueID) {} - - bool operator==(const SkUniquePaintParamsID &that) const { return fID == that.fID; } - bool operator!=(const SkUniquePaintParamsID &that) const { return !(*this == that); } - - bool isValid() const { return fID != SK_InvalidUniqueID; } - uint32_t asUInt() const { return fID; } - -private: - uint32_t fID; -}; - -#endif // SkUniquePaintParamsID_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h deleted file mode 100644 index 74cdabffe2d0c..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h +++ /dev/null @@ -1,1026 +0,0 @@ -/* - * Copyright 2019 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKVX_DEFINED -#define SKVX_DEFINED - -// skvx::Vec are SIMD vectors of N T's, a v1.5 successor to SkNx. -// -// This time we're leaning a bit less on platform-specific intrinsics and a bit -// more on Clang/GCC vector extensions, but still keeping the option open to -// drop in platform-specific intrinsics, actually more easily than before. -// -// We've also fixed a few of the caveats that used to make SkNx awkward to work -// with across translation units. skvx::Vec always has N*sizeof(T) size -// and alignment and is safe to use across translation units freely. -// (Ideally we'd only align to T, but that tanks ARMv7 NEON codegen.) - -// Please try to keep this file independent of Skia headers. -#include // std::min, std::max -#include // assert() -#include // ceilf, floorf, truncf, roundf, sqrtf, etc. -#include // intXX_t -#include // memcpy() -#include // std::initializer_list -#include // std::index_sequence - -// Users may disable SIMD with SKNX_NO_SIMD, which may be set via compiler flags. -// The gn build has no option which sets SKNX_NO_SIMD. -// Use SKVX_USE_SIMD internally to avoid confusing double negation. -// Do not use 'defined' in a macro expansion. -#if !defined(SKNX_NO_SIMD) - #define SKVX_USE_SIMD 1 -#else - #define SKVX_USE_SIMD 0 -#endif - -#if SKVX_USE_SIMD - #if defined(__SSE__) || defined(__AVX__) || defined(__AVX2__) - #include - #elif defined(__ARM_NEON) - #include - #elif defined(__wasm_simd128__) - #include - #endif -#endif - -// To avoid ODR violations, all methods must be force-inlined... -#if defined(_MSC_VER) - #define SKVX_ALWAYS_INLINE __forceinline -#else - #define SKVX_ALWAYS_INLINE __attribute__((always_inline)) -#endif - -// ... and all standalone functions must be static. Please use these helpers: -#define SI static inline -#define SIT template < typename T> SI -#define SIN template SI -#define SINT template SI -#define SINTU template ::value>> SI - -namespace skvx { - -template -struct alignas(N*sizeof(T)) Vec; - -template -SI Vec shuffle(const Vec&); - -template -SI D bit_pun(const S&); - -// All Vec have the same simple memory layout, the same as `T vec[N]`. -template -struct alignas(N*sizeof(T)) VecStorage { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - - Vec lo, hi; -}; - -template -struct VecStorage<4,T> { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y, T z, T w) : lo(x,y), hi(z, w) {} - SKVX_ALWAYS_INLINE VecStorage(Vec<2,T> xy, T z, T w) : lo(xy), hi(z,w) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y, Vec<2,T> zw) : lo(x,y), hi(zw) {} - SKVX_ALWAYS_INLINE VecStorage(Vec<2,T> xy, Vec<2,T> zw) : lo(xy), hi(zw) {} - - SKVX_ALWAYS_INLINE Vec<2,T>& xy() { return lo; } - SKVX_ALWAYS_INLINE Vec<2,T>& zw() { return hi; } - SKVX_ALWAYS_INLINE T& x() { return lo.lo.val; } - SKVX_ALWAYS_INLINE T& y() { return lo.hi.val; } - SKVX_ALWAYS_INLINE T& z() { return hi.lo.val; } - SKVX_ALWAYS_INLINE T& w() { return hi.hi.val; } - - SKVX_ALWAYS_INLINE Vec<2,T> xy() const { return lo; } - SKVX_ALWAYS_INLINE Vec<2,T> zw() const { return hi; } - SKVX_ALWAYS_INLINE T x() const { return lo.lo.val; } - SKVX_ALWAYS_INLINE T y() const { return lo.hi.val; } - SKVX_ALWAYS_INLINE T z() const { return hi.lo.val; } - SKVX_ALWAYS_INLINE T w() const { return hi.hi.val; } - - // Exchange-based swizzles. These should take 1 cycle on NEON and 3 (pipelined) cycles on SSE. - SKVX_ALWAYS_INLINE Vec<4,T> yxwz() const { return shuffle<1,0,3,2>(bit_pun>(*this)); } - SKVX_ALWAYS_INLINE Vec<4,T> zwxy() const { return shuffle<2,3,0,1>(bit_pun>(*this)); } - - Vec<2,T> lo, hi; -}; - -template -struct VecStorage<2,T> { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y) : lo(x), hi(y) {} - - SKVX_ALWAYS_INLINE T& x() { return lo.val; } - SKVX_ALWAYS_INLINE T& y() { return hi.val; } - - SKVX_ALWAYS_INLINE T x() const { return lo.val; } - SKVX_ALWAYS_INLINE T y() const { return hi.val; } - - // This exchange-based swizzle should take 1 cycle on NEON and 3 (pipelined) cycles on SSE. - SKVX_ALWAYS_INLINE Vec<2,T> yx() const { return shuffle<1,0>(bit_pun>(*this)); } - - SKVX_ALWAYS_INLINE Vec<4,T> xyxy() const { - return Vec<4,T>(bit_pun>(*this), bit_pun>(*this)); - } - - Vec<1,T> lo, hi; -}; - -template -struct alignas(N*sizeof(T)) Vec : public VecStorage { - static_assert((N & (N-1)) == 0, "N must be a power of 2."); - static_assert(sizeof(T) >= alignof(T), "What kind of unusual T is this?"); - - // Methods belong here in the class declaration of Vec only if: - // - they must be here, like constructors or operator[]; - // - they'll definitely never want a specialized implementation. - // Other operations on Vec should be defined outside the type. - - SKVX_ALWAYS_INLINE Vec() = default; - - using VecStorage::VecStorage; - - // NOTE: Vec{x} produces x000..., whereas Vec(x) produces xxxx.... since this constructor fills - // unspecified lanes with 0s, whereas the single T constructor fills all lanes with the value. - SKVX_ALWAYS_INLINE Vec(std::initializer_list xs) { - T vals[N] = {0}; - memcpy(vals, xs.begin(), std::min(xs.size(), (size_t)N)*sizeof(T)); - - this->lo = Vec::Load(vals + 0); - this->hi = Vec::Load(vals + N/2); - } - - SKVX_ALWAYS_INLINE T operator[](int i) const { return ilo[i] : this->hi[i-N/2]; } - SKVX_ALWAYS_INLINE T& operator[](int i) { return ilo[i] : this->hi[i-N/2]; } - - SKVX_ALWAYS_INLINE static Vec Load(const void* ptr) { - Vec v; - memcpy(&v, ptr, sizeof(Vec)); - return v; - } - SKVX_ALWAYS_INLINE void store(void* ptr) const { - memcpy(ptr, this, sizeof(Vec)); - } -}; - -template -struct Vec<1,T> { - T val; - - SKVX_ALWAYS_INLINE Vec() = default; - - Vec(T s) : val(s) {} - - SKVX_ALWAYS_INLINE Vec(std::initializer_list xs) : val(xs.size() ? *xs.begin() : 0) {} - - SKVX_ALWAYS_INLINE T operator[](int) const { return val; } - SKVX_ALWAYS_INLINE T& operator[](int) { return val; } - - SKVX_ALWAYS_INLINE static Vec Load(const void* ptr) { - Vec v; - memcpy(&v, ptr, sizeof(Vec)); - return v; - } - SKVX_ALWAYS_INLINE void store(void* ptr) const { - memcpy(ptr, this, sizeof(Vec)); - } -}; - -template -SI D bit_pun(const S& s) { - static_assert(sizeof(D) == sizeof(S)); - D d; - memcpy(&d, &s, sizeof(D)); - return d; -} - -// Translate from a value type T to its corresponding Mask, the result of a comparison. -template struct Mask { using type = T; }; -template <> struct Mask { using type = int32_t; }; -template <> struct Mask { using type = int64_t; }; -template using M = typename Mask::type; - -// Join two Vec into one Vec<2N,T>. -SINT Vec<2*N,T> join(const Vec& lo, const Vec& hi) { - Vec<2*N,T> v; - v.lo = lo; - v.hi = hi; - return v; -} - -// We have three strategies for implementing Vec operations: -// 1) lean on Clang/GCC vector extensions when available; -// 2) use map() to apply a scalar function lane-wise; -// 3) recurse on lo/hi to scalar portable implementations. -// We can slot in platform-specific implementations as overloads for particular Vec, -// or often integrate them directly into the recursion of style 3), allowing fine control. - -#if SKVX_USE_SIMD && (defined(__clang__) || defined(__GNUC__)) - - // VExt types have the same size as Vec and support most operations directly. - #if defined(__clang__) - template - using VExt = T __attribute__((ext_vector_type(N))); - - #elif defined(__GNUC__) - template - struct VExtHelper { - typedef T __attribute__((vector_size(N*sizeof(T)))) type; - }; - - template - using VExt = typename VExtHelper::type; - - // For some reason some (new!) versions of GCC cannot seem to deduce N in the generic - // to_vec() below for N=4 and T=float. This workaround seems to help... - SI Vec<4,float> to_vec(VExt<4,float> v) { return bit_pun>(v); } - #endif - - SINT VExt to_vext(const Vec& v) { return bit_pun>(v); } - SINT Vec to_vec(const VExt& v) { return bit_pun>(v); } - - SINT Vec operator+(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) + to_vext(y)); - } - SINT Vec operator-(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) - to_vext(y)); - } - SINT Vec operator*(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) * to_vext(y)); - } - SINT Vec operator/(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) / to_vext(y)); - } - - SINT Vec operator^(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) ^ to_vext(y)); - } - SINT Vec operator&(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) & to_vext(y)); - } - SINT Vec operator|(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) | to_vext(y)); - } - - SINT Vec operator!(const Vec& x) { return to_vec(!to_vext(x)); } - SINT Vec operator-(const Vec& x) { return to_vec(-to_vext(x)); } - SINT Vec operator~(const Vec& x) { return to_vec(~to_vext(x)); } - - SINT Vec operator<<(const Vec& x, int k) { return to_vec(to_vext(x) << k); } - SINT Vec operator>>(const Vec& x, int k) { return to_vec(to_vext(x) >> k); } - - SINT Vec> operator==(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) == to_vext(y)); - } - SINT Vec> operator!=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) != to_vext(y)); - } - SINT Vec> operator<=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) <= to_vext(y)); - } - SINT Vec> operator>=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) >= to_vext(y)); - } - SINT Vec> operator< (const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) < to_vext(y)); - } - SINT Vec> operator> (const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) > to_vext(y)); - } - -#else - - // Either SKNX_NO_SIMD is defined, or Clang/GCC vector extensions are not available. - // We'll implement things portably with N==1 scalar implementations and recursion onto them. - - // N == 1 scalar implementations. - SIT Vec<1,T> operator+(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val + y.val; } - SIT Vec<1,T> operator-(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val - y.val; } - SIT Vec<1,T> operator*(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val * y.val; } - SIT Vec<1,T> operator/(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val / y.val; } - - SIT Vec<1,T> operator^(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val ^ y.val; } - SIT Vec<1,T> operator&(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val & y.val; } - SIT Vec<1,T> operator|(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val | y.val; } - - SIT Vec<1,T> operator!(const Vec<1,T>& x) { return !x.val; } - SIT Vec<1,T> operator-(const Vec<1,T>& x) { return -x.val; } - SIT Vec<1,T> operator~(const Vec<1,T>& x) { return ~x.val; } - - SIT Vec<1,T> operator<<(const Vec<1,T>& x, int k) { return x.val << k; } - SIT Vec<1,T> operator>>(const Vec<1,T>& x, int k) { return x.val >> k; } - - SIT Vec<1,M> operator==(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val == y.val ? ~0 : 0; - } - SIT Vec<1,M> operator!=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val != y.val ? ~0 : 0; - } - SIT Vec<1,M> operator<=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val <= y.val ? ~0 : 0; - } - SIT Vec<1,M> operator>=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val >= y.val ? ~0 : 0; - } - SIT Vec<1,M> operator< (const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val < y.val ? ~0 : 0; - } - SIT Vec<1,M> operator> (const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val > y.val ? ~0 : 0; - } - - // Recurse on lo/hi down to N==1 scalar implementations. - SINT Vec operator+(const Vec& x, const Vec& y) { - return join(x.lo + y.lo, x.hi + y.hi); - } - SINT Vec operator-(const Vec& x, const Vec& y) { - return join(x.lo - y.lo, x.hi - y.hi); - } - SINT Vec operator*(const Vec& x, const Vec& y) { - return join(x.lo * y.lo, x.hi * y.hi); - } - SINT Vec operator/(const Vec& x, const Vec& y) { - return join(x.lo / y.lo, x.hi / y.hi); - } - - SINT Vec operator^(const Vec& x, const Vec& y) { - return join(x.lo ^ y.lo, x.hi ^ y.hi); - } - SINT Vec operator&(const Vec& x, const Vec& y) { - return join(x.lo & y.lo, x.hi & y.hi); - } - SINT Vec operator|(const Vec& x, const Vec& y) { - return join(x.lo | y.lo, x.hi | y.hi); - } - - SINT Vec operator!(const Vec& x) { return join(!x.lo, !x.hi); } - SINT Vec operator-(const Vec& x) { return join(-x.lo, -x.hi); } - SINT Vec operator~(const Vec& x) { return join(~x.lo, ~x.hi); } - - SINT Vec operator<<(const Vec& x, int k) { return join(x.lo << k, x.hi << k); } - SINT Vec operator>>(const Vec& x, int k) { return join(x.lo >> k, x.hi >> k); } - - SINT Vec> operator==(const Vec& x, const Vec& y) { - return join(x.lo == y.lo, x.hi == y.hi); - } - SINT Vec> operator!=(const Vec& x, const Vec& y) { - return join(x.lo != y.lo, x.hi != y.hi); - } - SINT Vec> operator<=(const Vec& x, const Vec& y) { - return join(x.lo <= y.lo, x.hi <= y.hi); - } - SINT Vec> operator>=(const Vec& x, const Vec& y) { - return join(x.lo >= y.lo, x.hi >= y.hi); - } - SINT Vec> operator< (const Vec& x, const Vec& y) { - return join(x.lo < y.lo, x.hi < y.hi); - } - SINT Vec> operator> (const Vec& x, const Vec& y) { - return join(x.lo > y.lo, x.hi > y.hi); - } -#endif - -// Scalar/vector operations splat the scalar to a vector. -SINTU Vec operator+ (U x, const Vec& y) { return Vec(x) + y; } -SINTU Vec operator- (U x, const Vec& y) { return Vec(x) - y; } -SINTU Vec operator* (U x, const Vec& y) { return Vec(x) * y; } -SINTU Vec operator/ (U x, const Vec& y) { return Vec(x) / y; } -SINTU Vec operator^ (U x, const Vec& y) { return Vec(x) ^ y; } -SINTU Vec operator& (U x, const Vec& y) { return Vec(x) & y; } -SINTU Vec operator| (U x, const Vec& y) { return Vec(x) | y; } -SINTU Vec> operator==(U x, const Vec& y) { return Vec(x) == y; } -SINTU Vec> operator!=(U x, const Vec& y) { return Vec(x) != y; } -SINTU Vec> operator<=(U x, const Vec& y) { return Vec(x) <= y; } -SINTU Vec> operator>=(U x, const Vec& y) { return Vec(x) >= y; } -SINTU Vec> operator< (U x, const Vec& y) { return Vec(x) < y; } -SINTU Vec> operator> (U x, const Vec& y) { return Vec(x) > y; } - -SINTU Vec operator+ (const Vec& x, U y) { return x + Vec(y); } -SINTU Vec operator- (const Vec& x, U y) { return x - Vec(y); } -SINTU Vec operator* (const Vec& x, U y) { return x * Vec(y); } -SINTU Vec operator/ (const Vec& x, U y) { return x / Vec(y); } -SINTU Vec operator^ (const Vec& x, U y) { return x ^ Vec(y); } -SINTU Vec operator& (const Vec& x, U y) { return x & Vec(y); } -SINTU Vec operator| (const Vec& x, U y) { return x | Vec(y); } -SINTU Vec> operator==(const Vec& x, U y) { return x == Vec(y); } -SINTU Vec> operator!=(const Vec& x, U y) { return x != Vec(y); } -SINTU Vec> operator<=(const Vec& x, U y) { return x <= Vec(y); } -SINTU Vec> operator>=(const Vec& x, U y) { return x >= Vec(y); } -SINTU Vec> operator< (const Vec& x, U y) { return x < Vec(y); } -SINTU Vec> operator> (const Vec& x, U y) { return x > Vec(y); } - -SINT Vec& operator+=(Vec& x, const Vec& y) { return (x = x + y); } -SINT Vec& operator-=(Vec& x, const Vec& y) { return (x = x - y); } -SINT Vec& operator*=(Vec& x, const Vec& y) { return (x = x * y); } -SINT Vec& operator/=(Vec& x, const Vec& y) { return (x = x / y); } -SINT Vec& operator^=(Vec& x, const Vec& y) { return (x = x ^ y); } -SINT Vec& operator&=(Vec& x, const Vec& y) { return (x = x & y); } -SINT Vec& operator|=(Vec& x, const Vec& y) { return (x = x | y); } - -SINTU Vec& operator+=(Vec& x, U y) { return (x = x + Vec(y)); } -SINTU Vec& operator-=(Vec& x, U y) { return (x = x - Vec(y)); } -SINTU Vec& operator*=(Vec& x, U y) { return (x = x * Vec(y)); } -SINTU Vec& operator/=(Vec& x, U y) { return (x = x / Vec(y)); } -SINTU Vec& operator^=(Vec& x, U y) { return (x = x ^ Vec(y)); } -SINTU Vec& operator&=(Vec& x, U y) { return (x = x & Vec(y)); } -SINTU Vec& operator|=(Vec& x, U y) { return (x = x | Vec(y)); } - -SINT Vec& operator<<=(Vec& x, int bits) { return (x = x << bits); } -SINT Vec& operator>>=(Vec& x, int bits) { return (x = x >> bits); } - -// Some operations we want are not expressible with Clang/GCC vector extensions. - -// Clang can reason about naive_if_then_else() and optimize through it better -// than if_then_else(), so it's sometimes useful to call it directly when we -// think an entire expression should optimize away, e.g. min()/max(). -SINT Vec naive_if_then_else(const Vec>& cond, const Vec& t, const Vec& e) { - return bit_pun>(( cond & bit_pun>>(t)) | - (~cond & bit_pun>>(e)) ); -} - -SIT Vec<1,T> if_then_else(const Vec<1,M>& cond, const Vec<1,T>& t, const Vec<1,T>& e) { - // In practice this scalar implementation is unlikely to be used. See next if_then_else(). - return bit_pun>(( cond & bit_pun>>(t)) | - (~cond & bit_pun>>(e)) ); -} -SINT Vec if_then_else(const Vec>& cond, const Vec& t, const Vec& e) { - // Specializations inline here so they can generalize what types the apply to. -#if SKVX_USE_SIMD && defined(__AVX2__) - if constexpr (N*sizeof(T) == 32) { - return bit_pun>(_mm256_blendv_epi8(bit_pun<__m256i>(e), - bit_pun<__m256i>(t), - bit_pun<__m256i>(cond))); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE4_1__) - if constexpr (N*sizeof(T) == 16) { - return bit_pun>(_mm_blendv_epi8(bit_pun<__m128i>(e), - bit_pun<__m128i>(t), - bit_pun<__m128i>(cond))); - } -#endif -#if SKVX_USE_SIMD && defined(__ARM_NEON) - if constexpr (N*sizeof(T) == 16) { - return bit_pun>(vbslq_u8(bit_pun(cond), - bit_pun(t), - bit_pun(e))); - } -#endif - // Recurse for large vectors to try to hit the specializations above. - if constexpr (N*sizeof(T) > 16) { - return join(if_then_else(cond.lo, t.lo, e.lo), - if_then_else(cond.hi, t.hi, e.hi)); - } - // This default can lead to better code than the recursing onto scalars. - return naive_if_then_else(cond, t, e); -} - -SIT bool any(const Vec<1,T>& x) { return x.val != 0; } -SINT bool any(const Vec& x) { - // For any(), the _mm_testz intrinsics are correct and don't require comparing 'x' to 0, so it's - // lower latency compared to _mm_movemask + _mm_compneq on plain SSE. -#if SKVX_USE_SIMD && defined(__AVX2__) - if constexpr (N*sizeof(T) == 32) { - return !_mm256_testz_si256(bit_pun<__m256i>(x), _mm256_set1_epi32(-1)); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE_4_1__) - if constexpr (N*sizeof(T) == 16) { - return !_mm_testz_si128(bit_pun<__m128i>(x), _mm_set1_epi32(-1)); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE__) - if constexpr (N*sizeof(T) == 16) { - // On SSE, movemask checks only the MSB in each lane, which is fine if the lanes were set - // directly from a comparison op (which sets all bits to 1 when true), but skvx::Vec<> - // treats any non-zero value as true, so we have to compare 'x' to 0 before calling movemask - return _mm_movemask_ps(_mm_cmpneq_ps(bit_pun<__m128>(x), _mm_set1_ps(0))) != 0b0000; - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - // On 64-bit NEON, take the max across lanes, which will be non-zero if any lane was true. - // The specific lane-size doesn't really matter in this case since it's really any set bit - // that we're looking for. - if constexpr (N*sizeof(T) == 8 ) { return vmaxv_u8 (bit_pun (x)) > 0; } - if constexpr (N*sizeof(T) == 16) { return vmaxvq_u8(bit_pun(x)) > 0; } -#endif -#if SKVX_USE_SIMD && defined(__wasm_simd128__) - if constexpr (N == 4 && sizeof(T) == 4) { - return wasm_i32x4_any_true(bit_pun>(x)); - } -#endif - return any(x.lo) - || any(x.hi); -} - -SIT bool all(const Vec<1,T>& x) { return x.val != 0; } -SINT bool all(const Vec& x) { -// Unlike any(), we have to respect the lane layout, or we'll miss cases where a -// true lane has a mix of 0 and 1 bits. -#if SKVX_USE_SIMD && defined(__SSE__) - // Unfortunately, the _mm_testc intrinsics don't let us avoid the comparison to 0 for all()'s - // correctness, so always just use the plain SSE version. - if constexpr (N == 4 && sizeof(T) == 4) { - return _mm_movemask_ps(_mm_cmpneq_ps(bit_pun<__m128>(x), _mm_set1_ps(0))) == 0b1111; - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - // On 64-bit NEON, take the min across the lanes, which will be non-zero if all lanes are != 0. - if constexpr (sizeof(T)==1 && N==8) {return vminv_u8 (bit_pun (x)) > 0;} - if constexpr (sizeof(T)==1 && N==16) {return vminvq_u8 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==2 && N==4) {return vminv_u16 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==2 && N==8) {return vminvq_u16(bit_pun(x)) > 0;} - if constexpr (sizeof(T)==4 && N==2) {return vminv_u32 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==4 && N==4) {return vminvq_u32(bit_pun(x)) > 0;} -#endif -#if SKVX_USE_SIMD && defined(__wasm_simd128__) - if constexpr (N == 4 && sizeof(T) == 4) { - return wasm_i32x4_all_true(bit_pun>(x)); - } -#endif - return all(x.lo) - && all(x.hi); -} - -// cast() Vec to Vec, as if applying a C-cast to each lane. -// TODO: implement with map()? -template -SI Vec<1,D> cast(const Vec<1,S>& src) { return (D)src.val; } - -template -SI Vec cast(const Vec& src) { -#if SKVX_USE_SIMD && defined(__clang__) - return to_vec(__builtin_convertvector(to_vext(src), VExt)); -#else - return join(cast(src.lo), cast(src.hi)); -#endif -} - -// min/max match logic of std::min/std::max, which is important when NaN is involved. -SIT T min(const Vec<1,T>& x) { return x.val; } -SIT T max(const Vec<1,T>& x) { return x.val; } -SINT T min(const Vec& x) { return std::min(min(x.lo), min(x.hi)); } -SINT T max(const Vec& x) { return std::max(max(x.lo), max(x.hi)); } - -SINT Vec min(const Vec& x, const Vec& y) { return naive_if_then_else(y < x, y, x); } -SINT Vec max(const Vec& x, const Vec& y) { return naive_if_then_else(x < y, y, x); } - -SINTU Vec min(const Vec& x, U y) { return min(x, Vec(y)); } -SINTU Vec max(const Vec& x, U y) { return max(x, Vec(y)); } -SINTU Vec min(U x, const Vec& y) { return min(Vec(x), y); } -SINTU Vec max(U x, const Vec& y) { return max(Vec(x), y); } - -// pin matches the logic of SkTPin, which is important when NaN is involved. It always returns -// values in the range lo..hi, and if x is NaN, it returns lo. -SINT Vec pin(const Vec& x, const Vec& lo, const Vec& hi) { - return max(lo, min(x, hi)); -} - -// Shuffle values from a vector pretty arbitrarily: -// skvx::Vec<4,float> rgba = {R,G,B,A}; -// shuffle<2,1,0,3> (rgba) ~> {B,G,R,A} -// shuffle<2,1> (rgba) ~> {B,G} -// shuffle<2,1,2,1,2,1,2,1>(rgba) ~> {B,G,B,G,B,G,B,G} -// shuffle<3,3,3,3> (rgba) ~> {A,A,A,A} -// The only real restriction is that the output also be a legal N=power-of-two sknx::Vec. -template -SI Vec shuffle(const Vec& x) { -#if SKVX_USE_SIMD && defined(__clang__) - // TODO: can we just always use { x[Ix]... }? - return to_vec(__builtin_shufflevector(to_vext(x), to_vext(x), Ix...)); -#else - return { x[Ix]... }; -#endif -} - -// Call map(fn, x) for a vector with fn() applied to each lane of x, { fn(x[0]), fn(x[1]), ... }, -// or map(fn, x,y) for a vector of fn(x[i], y[i]), etc. - -template -SI auto map(std::index_sequence, - Fn&& fn, const Args&... args) -> skvx::Vec { - auto lane = [&](size_t i) -#if defined(__clang__) - // CFI, specifically -fsanitize=cfi-icall, seems to give a false positive here, - // with errors like "control flow integrity check for type 'float (float) - // noexcept' failed during indirect function call... note: sqrtf.cfi_jt defined - // here". But we can be quite sure fn is the right type: it's all inferred! - // So, stifle CFI in this function. - __attribute__((no_sanitize("cfi"))) -#endif - { return fn(args[i]...); }; - - return { lane(I)... }; -} - -template -auto map(Fn&& fn, const Vec& first, const Rest&... rest) { - // Derive an {0...N-1} index_sequence from the size of the first arg: N lanes in, N lanes out. - return map(std::make_index_sequence{}, fn, first,rest...); -} - -SIN Vec ceil(const Vec& x) { return map( ceilf, x); } -SIN Vec floor(const Vec& x) { return map(floorf, x); } -SIN Vec trunc(const Vec& x) { return map(truncf, x); } -SIN Vec round(const Vec& x) { return map(roundf, x); } -SIN Vec sqrt(const Vec& x) { return map( sqrtf, x); } -SIN Vec abs(const Vec& x) { return map( fabsf, x); } -SIN Vec fma(const Vec& x, - const Vec& y, - const Vec& z) { - // I don't understand why Clang's codegen is terrible if we write map(fmaf, x,y,z) directly. - auto fn = [](float x, float y, float z) { return fmaf(x,y,z); }; - return map(fn, x,y,z); -} - -SI Vec<1,int> lrint(const Vec<1,float>& x) { - return (int)lrintf(x.val); -} -SIN Vec lrint(const Vec& x) { -#if SKVX_USE_SIMD && defined(__AVX__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtps_epi32(bit_pun<__m256>(x))); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE__) - if constexpr (N == 4) { - return bit_pun>(_mm_cvtps_epi32(bit_pun<__m128>(x))); - } -#endif - return join(lrint(x.lo), - lrint(x.hi)); -} - -SIN Vec fract(const Vec& x) { return x - floor(x); } - -// Assumes inputs are finite and treat/flush denorm half floats as/to zero. -// Key constants to watch for: -// - a float is 32-bit, 1-8-23 sign-exponent-mantissa, with 127 exponent bias; -// - a half is 16-bit, 1-5-10 sign-exponent-mantissa, with 15 exponent bias. -SIN Vec to_half_finite_ftz(const Vec& x) { - Vec sem = bit_pun>(x), - s = sem & 0x8000'0000, - em = sem ^ s, - is_norm = em > 0x387f'd000, // halfway between largest f16 denorm and smallest norm - norm = (em>>13) - ((127-15)<<10); - return cast((s>>16) | (is_norm & norm)); -} -SIN Vec from_half_finite_ftz(const Vec& x) { - Vec wide = cast(x), - s = wide & 0x8000, - em = wide ^ s, - is_norm = em > 0x3ff, - norm = (em<<13) + ((127-15)<<23); - return bit_pun>((s<<16) | (is_norm & norm)); -} - -// Like if_then_else(), these N=1 base cases won't actually be used unless explicitly called. -SI Vec<1,uint16_t> to_half(const Vec<1,float>& x) { return to_half_finite_ftz(x); } -SI Vec<1,float> from_half(const Vec<1,uint16_t>& x) { return from_half_finite_ftz(x); } - -SIN Vec to_half(const Vec& x) { -#if SKVX_USE_SIMD && defined(__F16C__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtps_ph(bit_pun<__m256>(x), - _MM_FROUND_TO_NEAREST_INT)); - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - if constexpr (N == 4) { - return bit_pun>(vcvt_f16_f32(bit_pun(x))); - - } -#endif - if constexpr (N > 4) { - return join(to_half(x.lo), - to_half(x.hi)); - } - return to_half_finite_ftz(x); -} - -SIN Vec from_half(const Vec& x) { -#if SKVX_USE_SIMD && defined(__F16C__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtph_ps(bit_pun<__m128i>(x))); - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - if constexpr (N == 4) { - return bit_pun>(vcvt_f32_f16(bit_pun(x))); - } -#endif - if constexpr (N > 4) { - return join(from_half(x.lo), - from_half(x.hi)); - } - return from_half_finite_ftz(x); -} - -// div255(x) = (x + 127) / 255 is a bit-exact rounding divide-by-255, packing down to 8-bit. -SIN Vec div255(const Vec& x) { - return cast( (x+127)/255 ); -} - -// approx_scale(x,y) approximates div255(cast(x)*cast(y)) within a bit, -// and is always perfect when x or y is 0 or 255. -SIN Vec approx_scale(const Vec& x, const Vec& y) { - // All of (x*y+x)/256, (x*y+y)/256, and (x*y+255)/256 meet the criteria above. - // We happen to have historically picked (x*y+x)/256. - auto X = cast(x), - Y = cast(y); - return cast( (X*Y+X)/256 ); -} - -// saturated_add(x,y) sums values and clamps to the maximum value instead of overflowing. -SINT std::enable_if_t, Vec> saturated_add(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && (defined(__SSE__) || defined(__ARM_NEON)) - // Both SSE and ARM have 16-lane saturated adds, so use intrinsics for those and recurse down - // or join up to take advantage. - if constexpr (N == 16 && sizeof(T) == 1) { - #if defined(__SSE__) - return bit_pun>(_mm_adds_epu8(bit_pun<__m128i>(x), bit_pun<__m128i>(y))); - #else // __ARM_NEON - return bit_pun>(vqaddq_u8(bit_pun(x), bit_pun(y))); - #endif - } else if constexpr (N < 16 && sizeof(T) == 1) { - return saturated_add(join(x,x), join(y,y)).lo; - } else if constexpr (sizeof(T) == 1) { - return join(saturated_add(x.lo, y.lo), saturated_add(x.hi, y.hi)); - } -#endif - // Otherwise saturate manually - auto sum = x + y; - return if_then_else(sum < x, Vec(std::numeric_limits::max()), sum); -} - -// The ScaledDividerU32 takes a divisor > 1, and creates a function divide(numerator) that -// calculates a numerator / denominator. For this to be rounded properly, numerator should have -// half added in: -// divide(numerator + half) == floor(numerator/denominator + 1/2). -// -// This gives an answer within +/- 1 from the true value. -// -// Derivation of half: -// numerator/denominator + 1/2 = (numerator + half) / d -// numerator + denominator / 2 = numerator + half -// half = denominator / 2. -// -// Because half is divided by 2, that division must also be rounded. -// half == denominator / 2 = (denominator + 1) / 2. -// -// The divisorFactor is just a scaled value: -// divisorFactor = (1 / divisor) * 2 ^ 32. -// The maximum that can be divided and rounded is UINT_MAX - half. -class ScaledDividerU32 { -public: - explicit ScaledDividerU32(uint32_t divisor) - : fDivisorFactor{(uint32_t)(std::round((1.0 / divisor) * (1ull << 32)))} - , fHalf{(divisor + 1) >> 1} { - assert(divisor > 1); - } - - Vec<4, uint32_t> divide(const Vec<4, uint32_t>& numerator) const { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - uint64x2_t hi = vmull_n_u32(vget_high_u32(to_vext(numerator)), fDivisorFactor); - uint64x2_t lo = vmull_n_u32(vget_low_u32(to_vext(numerator)), fDivisorFactor); - - return to_vec<4, uint32_t>(vcombine_u32(vshrn_n_u64(lo,32), vshrn_n_u64(hi,32))); -#else - return cast((cast(numerator) * fDivisorFactor) >> 32); -#endif - } - - uint32_t half() const { return fHalf; } - -private: - const uint32_t fDivisorFactor; - const uint32_t fHalf; -}; - - -SIN Vec mull(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - // With NEON we can do eight u8*u8 -> u16 in one instruction, vmull_u8 (read, mul-long). - if constexpr (N == 8) { - return to_vec<8,uint16_t>(vmull_u8(to_vext(x), to_vext(y))); - } else if constexpr (N < 8) { - return mull(join(x,x), join(y,y)).lo; - } else { // N > 8 - return join(mull(x.lo, y.lo), mull(x.hi, y.hi)); - } -#else - return cast(x) * cast(y); -#endif -} - -SIN Vec mull(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - // NEON can do four u16*u16 -> u32 in one instruction, vmull_u16 - if constexpr (N == 4) { - return to_vec<4,uint32_t>(vmull_u16(to_vext(x), to_vext(y))); - } else if constexpr (N < 4) { - return mull(join(x,x), join(y,y)).lo; - } else { // N > 4 - return join(mull(x.lo, y.lo), mull(x.hi, y.hi)); - } -#else - return cast(x) * cast(y); -#endif -} - -SIN Vec mulhi(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__SSE__) - // Use _mm_mulhi_epu16 for 8xuint16_t and join or split to get there. - if constexpr (N == 8) { - return bit_pun>(_mm_mulhi_epu16(bit_pun<__m128i>(x), bit_pun<__m128i>(y))); - } else if constexpr (N < 8) { - return mulhi(join(x,x), join(y,y)).lo; - } else { // N > 8 - return join(mulhi(x.lo, y.lo), mulhi(x.hi, y.hi)); - } -#else - return skvx::cast(mull(x, y) >> 16); -#endif -} - -SINT T dot(const Vec& a, const Vec& b) { - auto ab = a*b; - if constexpr (N == 2) { - return ab[0] + ab[1]; - } else if constexpr (N == 4) { - return ab[0] + ab[1] + ab[2] + ab[3]; - } else { - T sum = ab[0]; - for (int i = 1; i < N; ++i) { - sum += ab[i]; - } - return sum; - } -} - -SI float cross(const Vec<2, float>& a, const Vec<2, float>& b) { - auto x = a * shuffle<1,0>(b); - return x[0] - x[1]; -} - -// De-interleaving load of 4 vectors. -// -// WARNING: These are really only supported well on NEON. Consider restructuring your data before -// resorting to these methods. -SIT void strided_load4(const T* v, - Vec<1,T>& a, - Vec<1,T>& b, - Vec<1,T>& c, - Vec<1,T>& d) { - a.val = v[0]; - b.val = v[1]; - c.val = v[2]; - d.val = v[3]; -} -SINT void strided_load4(const T* v, - Vec& a, - Vec& b, - Vec& c, - Vec& d) { - strided_load4(v, a.lo, b.lo, c.lo, d.lo); - strided_load4(v + 4*(N/2), a.hi, b.hi, c.hi, d.hi); -} -#if SKVX_USE_SIMD && defined(__ARM_NEON) -#define IMPL_LOAD4_TRANSPOSED(N, T, VLD) \ -SI void strided_load4(const T* v, \ - Vec& a, \ - Vec& b, \ - Vec& c, \ - Vec& d) { \ - auto mat = VLD(v); \ - a = bit_pun>(mat.val[0]); \ - b = bit_pun>(mat.val[1]); \ - c = bit_pun>(mat.val[2]); \ - d = bit_pun>(mat.val[3]); \ -} -IMPL_LOAD4_TRANSPOSED(2, uint32_t, vld4_u32) -IMPL_LOAD4_TRANSPOSED(4, uint16_t, vld4_u16) -IMPL_LOAD4_TRANSPOSED(8, uint8_t, vld4_u8) -IMPL_LOAD4_TRANSPOSED(2, int32_t, vld4_s32) -IMPL_LOAD4_TRANSPOSED(4, int16_t, vld4_s16) -IMPL_LOAD4_TRANSPOSED(8, int8_t, vld4_s8) -IMPL_LOAD4_TRANSPOSED(2, float, vld4_f32) -IMPL_LOAD4_TRANSPOSED(4, uint32_t, vld4q_u32) -IMPL_LOAD4_TRANSPOSED(8, uint16_t, vld4q_u16) -IMPL_LOAD4_TRANSPOSED(16, uint8_t, vld4q_u8) -IMPL_LOAD4_TRANSPOSED(4, int32_t, vld4q_s32) -IMPL_LOAD4_TRANSPOSED(8, int16_t, vld4q_s16) -IMPL_LOAD4_TRANSPOSED(16, int8_t, vld4q_s8) -IMPL_LOAD4_TRANSPOSED(4, float, vld4q_f32) -#undef IMPL_LOAD4_TRANSPOSED - -#elif SKVX_USE_SIMD && defined(__SSE__) - -SI void strided_load4(const float* v, - Vec<4,float>& a, - Vec<4,float>& b, - Vec<4,float>& c, - Vec<4,float>& d) { - __m128 a_ = _mm_loadu_ps(v); - __m128 b_ = _mm_loadu_ps(v+4); - __m128 c_ = _mm_loadu_ps(v+8); - __m128 d_ = _mm_loadu_ps(v+12); - _MM_TRANSPOSE4_PS(a_, b_, c_, d_); - a = bit_pun>(a_); - b = bit_pun>(b_); - c = bit_pun>(c_); - d = bit_pun>(d_); -} -#endif - -// De-interleaving load of 2 vectors. -// -// WARNING: These are really only supported well on NEON. Consider restructuring your data before -// resorting to these methods. -SIT void strided_load2(const T* v, Vec<1,T>& a, Vec<1,T>& b) { - a.val = v[0]; - b.val = v[1]; -} -SINT void strided_load2(const T* v, Vec& a, Vec& b) { - strided_load2(v, a.lo, b.lo); - strided_load2(v + 2*(N/2), a.hi, b.hi); -} -#if SKVX_USE_SIMD && defined(__ARM_NEON) -#define IMPL_LOAD2_TRANSPOSED(N, T, VLD) \ -SI void strided_load2(const T* v, Vec& a, Vec& b) { \ - auto mat = VLD(v); \ - a = bit_pun>(mat.val[0]); \ - b = bit_pun>(mat.val[1]); \ -} -IMPL_LOAD2_TRANSPOSED(2, uint32_t, vld2_u32) -IMPL_LOAD2_TRANSPOSED(4, uint16_t, vld2_u16) -IMPL_LOAD2_TRANSPOSED(8, uint8_t, vld2_u8) -IMPL_LOAD2_TRANSPOSED(2, int32_t, vld2_s32) -IMPL_LOAD2_TRANSPOSED(4, int16_t, vld2_s16) -IMPL_LOAD2_TRANSPOSED(8, int8_t, vld2_s8) -IMPL_LOAD2_TRANSPOSED(2, float, vld2_f32) -IMPL_LOAD2_TRANSPOSED(4, uint32_t, vld2q_u32) -IMPL_LOAD2_TRANSPOSED(8, uint16_t, vld2q_u16) -IMPL_LOAD2_TRANSPOSED(16, uint8_t, vld2q_u8) -IMPL_LOAD2_TRANSPOSED(4, int32_t, vld2q_s32) -IMPL_LOAD2_TRANSPOSED(8, int16_t, vld2q_s16) -IMPL_LOAD2_TRANSPOSED(16, int8_t, vld2q_s8) -IMPL_LOAD2_TRANSPOSED(4, float, vld2q_f32) -#undef IMPL_LOAD2_TRANSPOSED -#endif - -// Define commonly used aliases -using float2 = Vec< 2, float>; -using float4 = Vec< 4, float>; -using float8 = Vec< 8, float>; - -using double2 = Vec< 2, double>; -using double4 = Vec< 4, double>; -using double8 = Vec< 8, double>; - -using byte2 = Vec< 2, uint8_t>; -using byte4 = Vec< 4, uint8_t>; -using byte8 = Vec< 8, uint8_t>; -using byte16 = Vec<16, uint8_t>; - -using int2 = Vec< 2, int32_t>; -using int4 = Vec< 4, int32_t>; -using int8 = Vec< 8, int32_t>; - -using uint2 = Vec< 2, uint32_t>; -using uint4 = Vec< 4, uint32_t>; -using uint8 = Vec< 8, uint32_t>; - -using long2 = Vec< 2, int64_t>; -using long4 = Vec< 4, int64_t>; -using long8 = Vec< 8, int64_t>; - -// Use with from_half and to_half to convert between floatX, and use these for storage. -using half2 = Vec< 2, uint16_t>; -using half4 = Vec< 4, uint16_t>; -using half8 = Vec< 8, uint16_t>; - -} // namespace skvx - -#undef SINTU -#undef SINT -#undef SIN -#undef SIT -#undef SI -#undef SKVX_ALWAYS_INLINE -#undef SKVX_USE_SIMD - -#endif//SKVX_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h index 2b577342f4cd2..058a18652ba51 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h @@ -9,7 +9,10 @@ #define SkWeakRefCnt_DEFINED #include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + #include +#include /** \class SkWeakRefCnt diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h similarity index 86% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h index f60f7c83b969c..473981e1fb83f 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h @@ -8,16 +8,19 @@ #ifndef skgpu_SingleOwner_DEFINED #define skgpu_SingleOwner_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkDebug.h" // IWYU pragma: keep + +#if defined(SK_DEBUG) +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkThreadAnnotations.h" +#include "include/private/base/SkThreadID.h" -#ifdef SK_DEBUG -#include "include/private/SkMutex.h" -#include "include/private/SkThreadID.h" #endif namespace skgpu { -#ifdef SK_DEBUG +#if defined(SK_DEBUG) #define SKGPU_ASSERT_SINGLE_OWNER(obj) \ skgpu::SingleOwner::AutoEnforce debug_SingleOwner(obj, __FILE__, __LINE__); diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h new file mode 100644 index 0000000000000..4028f95d87d2b --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h @@ -0,0 +1,52 @@ +/* + * 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 SkAPI_DEFINED +#define SkAPI_DEFINED + +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +// If SKIA_IMPLEMENTATION is defined as 1, that signals we are building Skia and should +// export our symbols. If it is not set (or set to 0), then Skia is being used by a client +// and we should not export our symbols. +#if !defined(SKIA_IMPLEMENTATION) + #define SKIA_IMPLEMENTATION 0 +#endif + +// If we are compiling Skia is being as a DLL, we need to be sure to export all of our public +// APIs to that DLL. If a client is using Skia which was compiled as a DLL, we need to instruct +// the linker to use the symbols from that DLL. This is the goal of the SK_API define. +#if !defined(SK_API) + #if defined(SKIA_DLL) + #if defined(_MSC_VER) + #if SKIA_IMPLEMENTATION + #define SK_API __declspec(dllexport) + #else + #define SK_API __declspec(dllimport) + #endif + #else + #define SK_API __attribute__((visibility("default"))) + #endif + #else + #define SK_API + #endif +#endif + +// SK_SPI is functionally identical to SK_API, but used within src to clarify that it's less stable +#if !defined(SK_SPI) + #define SK_SPI SK_API +#endif + +// See https://clang.llvm.org/docs/AttributeReference.html#availability +// The API_AVAILABLE macro comes from on MacOS +#if defined(SK_ENABLE_API_AVAILABLE) +# define SK_API_AVAILABLE API_AVAILABLE +#else +# define SK_API_AVAILABLE(...) +#endif + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h new file mode 100644 index 0000000000000..2b2138ddd49c2 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h @@ -0,0 +1,39 @@ +/* + * 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 SkAlign_DEFINED +#define SkAlign_DEFINED + +#include "include/private/base/SkAssert.h" + +#include + +template static constexpr T SkAlign2(T x) { return (x + 1) >> 1 << 1; } +template static constexpr T SkAlign4(T x) { return (x + 3) >> 2 << 2; } +template static constexpr T SkAlign8(T x) { return (x + 7) >> 3 << 3; } + +template static constexpr bool SkIsAlign2(T x) { return 0 == (x & 1); } +template static constexpr bool SkIsAlign4(T x) { return 0 == (x & 3); } +template static constexpr bool SkIsAlign8(T x) { return 0 == (x & 7); } + +template static constexpr T SkAlignPtr(T x) { + return sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x); +} +template static constexpr bool SkIsAlignPtr(T x) { + return sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x); +} + +/** + * align up to a power of 2 + */ +static inline constexpr size_t SkAlignTo(size_t x, size_t alignment) { + // The same as alignment && SkIsPow2(value), w/o a dependency cycle. + SkASSERT(alignment && (alignment & (alignment - 1)) == 0); + return (x + alignment - 1) & ~(alignment - 1); +} + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h new file mode 100644 index 0000000000000..532ad03978fac --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h @@ -0,0 +1,32 @@ +// 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 SkAlignedStorage_DEFINED +#define SkAlignedStorage_DEFINED + +#include +#include + +template class SkAlignedSTStorage { +public: + SkAlignedSTStorage() {} + SkAlignedSTStorage(SkAlignedSTStorage&&) = delete; + SkAlignedSTStorage(const SkAlignedSTStorage&) = delete; + SkAlignedSTStorage& operator=(SkAlignedSTStorage&&) = delete; + SkAlignedSTStorage& operator=(const SkAlignedSTStorage&) = delete; + + // Returns void* because this object does not initialize the + // memory. Use placement new for types that require a constructor. + void* get() { return fStorage; } + const void* get() const { return fStorage; } + + // Act as a container of bytes because the storage is uninitialized. + std::byte* data() { return fStorage; } + const std::byte* data() const { return fStorage; } + size_t size() const { return std::size(fStorage); } + +private: + alignas(T) std::byte fStorage[sizeof(T) * N]; +}; + +#endif // SkAlignedStorage_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h new file mode 100644 index 0000000000000..97d43d4f64ff4 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h @@ -0,0 +1,92 @@ +/* + * 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 SkAssert_DEFINED +#define SkAssert_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" // IWYU pragma: keep + +/** Called internally if we hit an unrecoverable error. + The platform implementation must not return, but should either throw + an exception or otherwise exit. +*/ +[[noreturn]] SK_API extern void sk_abort_no_print(void); + +#if defined(SK_BUILD_FOR_GOOGLE3) + void SkDebugfForDumpStackTrace(const char* data, void* unused); + namespace base { + void DumpStackTrace(int skip_count, void w(const char*, void*), void* arg); + } +# define SK_DUMP_GOOGLE3_STACK() ::base::DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr) +#else +# define SK_DUMP_GOOGLE3_STACK() +#endif + +#if !defined(SK_ABORT) +# if defined(SK_BUILD_FOR_WIN) + // This style lets Visual Studio follow errors back to the source file. +# define SK_DUMP_LINE_FORMAT "%s(%d)" +# else +# define SK_DUMP_LINE_FORMAT "%s:%d" +# endif +# define SK_ABORT(message, ...) \ + do { \ + SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \ + __FILE__, __LINE__, ##__VA_ARGS__); \ + SK_DUMP_GOOGLE3_STACK(); \ + sk_abort_no_print(); \ + } while (false) +#endif + +// SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g. +// uint32_t foo(int x) { +// SkASSERT(x > 4); +// return x - 4; +// } +// and are also written to be compatible with constexpr functions: +// constexpr uint32_t foo(int x) { +// return SkASSERT(x > 4), +// x - 4; +// } +#define SkASSERT_RELEASE(cond) \ + static_cast( (cond) ? (void)0 : []{ SK_ABORT("assert(%s)", #cond); }() ) + +#if defined(SK_DEBUG) + #define SkASSERT(cond) SkASSERT_RELEASE(cond) + #define SkASSERTF(cond, fmt, ...) static_cast( (cond) ? (void)0 : [&]{ \ + SkDebugf(fmt"\n", ##__VA_ARGS__); \ + SK_ABORT("assert(%s)", #cond); \ + }() ) + #define SkDEBUGFAIL(message) SK_ABORT("%s", message) + #define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__) + #define SkAssertResult(cond) SkASSERT(cond) +#else + #define SkASSERT(cond) static_cast(0) + #define SkASSERTF(cond, fmt, ...) static_cast(0) + #define SkDEBUGFAIL(message) + #define SkDEBUGFAILF(fmt, ...) + + // unlike SkASSERT, this macro executes its condition in the non-debug build. + // The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT. + #define SkAssertResult(cond) if (cond) {} do {} while(false) +#endif + +#if !defined(SkUNREACHABLE) +# if defined(_MSC_VER) && !defined(__clang__) +# include +# define FAST_FAIL_INVALID_ARG 5 +// See https://developercommunity.visualstudio.com/content/problem/1128631/code-flow-doesnt-see-noreturn-with-extern-c.html +// for why this is wrapped. Hopefully removable after msvc++ 19.27 is no longer supported. +[[noreturn]] static inline void sk_fast_fail() { __fastfail(FAST_FAIL_INVALID_ARG); } +# define SkUNREACHABLE sk_fast_fail() +# else +# define SkUNREACHABLE __builtin_trap() +# endif +#endif + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h new file mode 100644 index 0000000000000..34fdf0e09c92e --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h @@ -0,0 +1,102 @@ +/* + * 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 SkAttributes_DEFINED +#define SkAttributes_DEFINED + +#include "include/private/base/SkFeatures.h" // IWYU pragma: keep +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +#if defined(__clang__) || defined(__GNUC__) +# define SK_ATTRIBUTE(attr) __attribute__((attr)) +#else +# define SK_ATTRIBUTE(attr) +#endif + +#if !defined(SK_UNUSED) +# if !defined(__clang__) && defined(_MSC_VER) +# define SK_UNUSED __pragma(warning(suppress:4189)) +# else +# define SK_UNUSED SK_ATTRIBUTE(unused) +# endif +#endif + +#if !defined(SK_WARN_UNUSED_RESULT) + #define SK_WARN_UNUSED_RESULT SK_ATTRIBUTE(warn_unused_result) +#endif + +/** + * If your judgment is better than the compiler's (i.e. you've profiled it), + * you can use SK_ALWAYS_INLINE to force inlining. E.g. + * inline void someMethod() { ... } // may not be inlined + * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined + */ +#if !defined(SK_ALWAYS_INLINE) +# if defined(SK_BUILD_FOR_WIN) +# define SK_ALWAYS_INLINE __forceinline +# else +# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline +# endif +#endif + +/** + * If your judgment is better than the compiler's (i.e. you've profiled it), + * you can use SK_NEVER_INLINE to prevent inlining. + */ +#if !defined(SK_NEVER_INLINE) +# if defined(SK_BUILD_FOR_WIN) +# define SK_NEVER_INLINE __declspec(noinline) +# else +# define SK_NEVER_INLINE SK_ATTRIBUTE(noinline) +# endif +#endif + +/** + * Used to annotate a function as taking printf style arguments. + * `A` is the (1 based) index of the format string argument. + * `B` is the (1 based) index of the first argument used by the format string. + */ +#if !defined(SK_PRINTF_LIKE) +# define SK_PRINTF_LIKE(A, B) SK_ATTRIBUTE(format(printf, (A), (B))) +#endif + +/** + * Used to ignore sanitizer warnings. + */ +#if !defined(SK_NO_SANITIZE) +# define SK_NO_SANITIZE(A) SK_ATTRIBUTE(no_sanitize(A)) +#endif + +/** + * Helper macro to define no_sanitize attributes only with clang. + */ +#if defined(__clang__) && defined(__has_attribute) + #if __has_attribute(no_sanitize) + #define SK_CLANG_NO_SANITIZE(A) SK_NO_SANITIZE(A) + #endif +#endif + +#if !defined(SK_CLANG_NO_SANITIZE) + #define SK_CLANG_NO_SANITIZE(A) +#endif + +/** + * Annotates a class' non-trivial special functions as trivial for the purposes of calls. + * Allows a class with a non-trivial destructor to be __is_trivially_relocatable. + * Use of this attribute on a public API breaks platform ABI. + * Annotated classes may not hold pointers derived from `this`. + * Annotated classes must implement move+delete as equivalent to memcpy+free. + * Use may require more complete types, as callee destroys. + * + * https://clang.llvm.org/docs/AttributeReference.html#trivial-abi + * https://libcxx.llvm.org/DesignDocs/UniquePtrTrivialAbi.html + */ +#if !defined(SK_TRIVIAL_ABI) +# define SK_TRIVIAL_ABI +#endif + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h new file mode 100644 index 0000000000000..a5f60fd3ef191 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h @@ -0,0 +1,25 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkCPUTypes_DEFINED +#define SkCPUTypes_DEFINED + +// TODO(bungeman,kjlubick) There are a lot of assumptions throughout the codebase that +// these types are 32 bits, when they could be more or less. Public APIs should stop +// using these. Internally, we could use uint_fast8_t and uint_fast16_t, but not in +// public APIs due to ABI incompatibilities. + +/** Fast type for unsigned 8 bits. Use for parameter passing and local + variables, not for storage +*/ +typedef unsigned U8CPU; + +/** Fast type for unsigned 16 bits. Use for parameter passing and local + variables, not for storage +*/ +typedef unsigned U16CPU; + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h new file mode 100644 index 0000000000000..2ece73e28761b --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h @@ -0,0 +1,46 @@ +// 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 SkContainers_DEFINED +#define SkContainers_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkSpan_impl.h" + +#include +#include + +class SK_SPI SkContainerAllocator { +public: + SkContainerAllocator(size_t sizeOfT, int maxCapacity) + : fSizeOfT{sizeOfT} + , fMaxCapacity{maxCapacity} {} + + // allocate will abort on failure. Given a capacity of 0, it will return the empty span. + // The bytes allocated are freed using sk_free(). + SkSpan allocate(int capacity, double growthFactor = 1.0); + +private: + friend struct SkContainerAllocatorTestingPeer; + // All capacity counts will be rounded up to kCapacityMultiple. + // TODO: this is a constant from the original SkTArray code. This should be checked some how. + static constexpr int64_t kCapacityMultiple = 8; + + // Rounds up capacity to next multiple of kCapacityMultiple and pin to fMaxCapacity. + size_t roundUpCapacity(int64_t capacity) const; + + // Grows the capacity by growthFactor being sure to stay with in kMinBytes and fMaxCapacity. + size_t growthFactorCapacity(int capacity, double growthFactor) const; + + const size_t fSizeOfT; + const int64_t fMaxCapacity; +}; + +// sk_allocate_canfail returns the empty span on failure. Parameter size must be > 0. +SkSpan sk_allocate_canfail(size_t size); + +// Returns the empty span if size is 0. sk_allocate_throw aborts on failure. +SkSpan sk_allocate_throw(size_t size); + +SK_SPI void sk_report_container_overflow_and_die(); +#endif // SkContainers_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h new file mode 100644 index 0000000000000..2e4810fc1c961 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.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 SkDebug_DEFINED +#define SkDebug_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +#if !defined(SkDebugf) + void SK_SPI SkDebugf(const char format[], ...) SK_PRINTF_LIKE(1, 2); +#endif + +#if defined(SK_DEBUG) + #define SkDEBUGCODE(...) __VA_ARGS__ + #define SkDEBUGF(...) SkDebugf(__VA_ARGS__) +#else + #define SkDEBUGCODE(...) + #define SkDEBUGF(...) +#endif + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h similarity index 98% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h index 8adc39c1c71f2..fbc61673131b4 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h @@ -10,7 +10,9 @@ #ifndef SkDeque_DEFINED #define SkDeque_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" + +#include /* * The deque class works by blindly creating memory space of a specified element diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h new file mode 100644 index 0000000000000..662bf0321161e --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h @@ -0,0 +1,151 @@ +/* + * 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 SkFeatures_DEFINED +#define SkFeatures_DEFINED + +#if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && \ + !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) + + #ifdef __APPLE__ + #include + #endif + + #if defined(_WIN32) || defined(__SYMBIAN32__) + #define SK_BUILD_FOR_WIN + #elif defined(ANDROID) || defined(__ANDROID__) + #define SK_BUILD_FOR_ANDROID + #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || \ + defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || \ + defined(__DragonFly__) || defined(__Fuchsia__) || \ + defined(__GLIBC__) || defined(__GNU__) || defined(__unix__) + #define SK_BUILD_FOR_UNIX + #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR + #define SK_BUILD_FOR_IOS + #else + #define SK_BUILD_FOR_MAC + #endif +#endif // end SK_BUILD_FOR_* + + +#if defined(SK_BUILD_FOR_WIN) && !defined(__clang__) + #if !defined(SK_RESTRICT) + #define SK_RESTRICT __restrict + #endif + #if !defined(SK_WARN_UNUSED_RESULT) + #define SK_WARN_UNUSED_RESULT + #endif +#endif + +#if !defined(SK_RESTRICT) + #define SK_RESTRICT __restrict__ +#endif + +#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) + #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) + #define SK_CPU_BENDIAN + #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) + #define SK_CPU_LENDIAN + #elif defined(__sparc) || defined(__sparc__) || \ + defined(_POWER) || defined(__powerpc__) || \ + defined(__ppc__) || defined(__hppa) || \ + defined(__PPC__) || defined(__PPC64__) || \ + defined(_MIPSEB) || defined(__ARMEB__) || \ + defined(__s390__) || \ + (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ + (defined(__ia64) && defined(__BIG_ENDIAN__)) + #define SK_CPU_BENDIAN + #else + #define SK_CPU_LENDIAN + #endif +#endif + +#if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) + #define SK_CPU_X86 1 +#endif + +/** + * SK_CPU_SSE_LEVEL + * + * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. + * On non-intel CPU this should be undefined. + */ +#define SK_CPU_SSE_LEVEL_SSE1 10 +#define SK_CPU_SSE_LEVEL_SSE2 20 +#define SK_CPU_SSE_LEVEL_SSE3 30 +#define SK_CPU_SSE_LEVEL_SSSE3 31 +#define SK_CPU_SSE_LEVEL_SSE41 41 +#define SK_CPU_SSE_LEVEL_SSE42 42 +#define SK_CPU_SSE_LEVEL_AVX 51 +#define SK_CPU_SSE_LEVEL_AVX2 52 +#define SK_CPU_SSE_LEVEL_SKX 60 + +// TODO(brianosman,kjlubick) clean up these checks + +// Are we in GCC/Clang? +#ifndef SK_CPU_SSE_LEVEL + // These checks must be done in descending order to ensure we set the highest + // available SSE level. + #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ + defined(__AVX512BW__) && defined(__AVX512VL__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX + #elif defined(__AVX2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 + #elif defined(__AVX__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX + #elif defined(__SSE4_2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42 + #elif defined(__SSE4_1__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41 + #elif defined(__SSSE3__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 + #elif defined(__SSE3__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 + #elif defined(__SSE2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #endif +#endif + +// Are we in VisualStudio? +#ifndef SK_CPU_SSE_LEVEL + // These checks must be done in descending order to ensure we set the highest + // available SSE level. 64-bit intel guarantees at least SSE2 support. + #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ + defined(__AVX512BW__) && defined(__AVX512VL__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX + #elif defined(__AVX2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 + #elif defined(__AVX__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX + #elif defined(_M_X64) || defined(_M_AMD64) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #elif defined(_M_IX86_FP) + #if _M_IX86_FP >= 2 + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #elif _M_IX86_FP == 1 + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 + #endif + #endif +#endif + +// ARM defines +#if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) + #define SK_CPU_ARM32 +#elif defined(__aarch64__) + #define SK_CPU_ARM64 +#endif + +// All 64-bit ARM chips have NEON. Many 32-bit ARM chips do too. +#if !defined(SK_ARM_HAS_NEON) && defined(__ARM_NEON) + #define SK_ARM_HAS_NEON +#endif + +#if defined(__ARM_FEATURE_CRC32) + #define SK_ARM_HAS_CRC32 +#endif + +#endif // SkFeatures_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h similarity index 94% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h index e34c19f2ac867..2c8f2fb56c188 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h @@ -8,11 +8,12 @@ #ifndef SkFixed_DEFINED #define SkFixed_DEFINED -#include "include/core/SkScalar.h" -#include "include/core/SkTypes.h" -#include "include/private/SkSafe_math.h" -#include "include/private/SkTPin.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMath.h" // IWYU pragma: keep +#include "include/private/base/SkTPin.h" // IWYU pragma: keep + +#include /** \file SkFixed.h @@ -86,7 +87,6 @@ static inline SkFixed SkFixedFloorToFixed(SkFixed x) { return (SkFixed)( (uint32_t)x & 0xFFFF0000 ); } -#define SkFixedAbs(x) SkAbs32(x) #define SkFixedAve(a, b) (((a) + (b)) >> 1) // The divide may exceed 32 bits. Clamp to a signed 32 bit result. @@ -102,6 +102,8 @@ static inline SkFixed SkFixedMul(SkFixed a, SkFixed b) { // The VCVT float-to-fixed instruction is part of the VFPv3 instruction set. #if defined(__ARM_VFPV3__) + #include + /* This does not handle NaN or other obscurities, but is faster than than (int)(x*65536). When built on Android with -Os, needs forcing to inline or we lose the speed benefit. @@ -110,7 +112,7 @@ static inline SkFixed SkFixedMul(SkFixed a, SkFixed b) { { int32_t y; asm("vcvt.s32.f32 %0, %0, #16": "+w"(x)); - memcpy(&y, &x, sizeof(y)); + std::memcpy(&y, &x, sizeof(y)); return y; } #undef SkFloatToFixed diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h similarity index 96% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h index 89eea4b9e3495..37a7b271aee12 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h @@ -8,10 +8,9 @@ #ifndef SkFloatBits_DEFINED #define SkFloatBits_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkSafe_math.h" +#include "include/private/base/SkMath.h" -#include +#include /** Convert a sign-bit int (i.e. float interpreted as int) into a 2s compliement int. This also converts -0 (0x80000000) to 0. Doing this to a float allows diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h similarity index 89% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h index 8135abbfe1952..7aa8909f3a5eb 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h @@ -8,14 +8,14 @@ #ifndef SkFloatingPoint_DEFINED #define SkFloatingPoint_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkFloatBits.h" -#include "include/private/SkSafe_math.h" -#include -#include +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkFloatBits.h" +#include "include/private/base/SkMath.h" + +#include #include +#include #include -#include constexpr float SK_FloatSqrt2 = 1.41421356f; constexpr float SK_FloatPI = 3.14159265f; @@ -150,7 +150,7 @@ static inline int64_t sk_float_saturate2int64(float x) { // Cast double to float, ignoring any warning about too-large finite values being cast to float. // Clang thinks this is undefined, but it's actually implementation defined to return either // the largest float or infinity (one of the two bracketing representable floats). Good enough! -SK_ATTRIBUTE(no_sanitize("float-cast-overflow")) +SK_NO_SANITIZE("float-cast-overflow") static inline float sk_double_to_float(double x) { return static_cast(x); } @@ -196,12 +196,12 @@ static inline int sk_float_nextlog2(float x) { // IEEE defines how float divide behaves for non-finite values and zero-denoms, but C does not // so we have a helper that suppresses the possible undefined-behavior warnings. -SK_ATTRIBUTE(no_sanitize("float-divide-by-zero")) +SK_NO_SANITIZE("float-divide-by-zero") static inline float sk_ieee_float_divide(float numer, float denom) { return numer / denom; } -SK_ATTRIBUTE(no_sanitize("float-divide-by-zero")) +SK_NO_SANITIZE("float-divide-by-zero") static inline double sk_ieee_double_divide(double numer, double denom) { return numer / denom; } @@ -219,4 +219,13 @@ static inline float sk_fmaf(float f, float m, float a) { #endif } +// Returns true iff the provided number is within a small epsilon of 0. +bool sk_double_nearly_zero(double a); + +// Comparing floating point numbers is complicated. This helper only works if one or none +// of the two inputs is not very close to zero. It also does not work if both inputs could be NaN. +// The term "ulps" stands for "units of least precision". Read the following for more nuance: +// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ +bool sk_doubles_nearly_equal_ulps(double a, double b, uint8_t max_ulps_diff=16); + #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h new file mode 100644 index 0000000000000..b212ada86b0e5 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h @@ -0,0 +1,63 @@ +/* + * 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 SK_USER_CONFIG_WAS_LOADED + +// Include this to set reasonable defaults (e.g. for SK_CPU_LENDIAN) +#include "include/private/base/SkFeatures.h" + +// Allows embedders that want to disable macros that take arguments to just +// define that symbol to be one of these +#define SK_NOTHING_ARG1(arg1) +#define SK_NOTHING_ARG2(arg1, arg2) +#define SK_NOTHING_ARG3(arg1, arg2, arg3) + +// IWYU pragma: begin_exports + +// Note: SK_USER_CONFIG_HEADER will not work with Bazel builds and some C++ compilers. +#if defined(SK_USER_CONFIG_HEADER) + #include SK_USER_CONFIG_HEADER +#elif defined(SK_USE_BAZEL_CONFIG_HEADER) + // The Bazel config file is presumed to be in the root directory of its Bazel Workspace. + // This is achieved in Skia by having a nested WORKSPACE in include/config and a cc_library + // defined in that folder. As a result, we do not try to include SkUserConfig.h from the + // top of Skia because Bazel sandboxing will move it to a different location. + #include "SkUserConfig.h" +#else + #include "include/config/SkUserConfig.h" +#endif +// IWYU pragma: end_exports + +// Checks to make sure the SkUserConfig options do not conflict. +#if !defined(SK_DEBUG) && !defined(SK_RELEASE) + #ifdef NDEBUG + #define SK_RELEASE + #else + #define SK_DEBUG + #endif +#endif + +#if defined(SK_DEBUG) && defined(SK_RELEASE) +# error "cannot define both SK_DEBUG and SK_RELEASE" +#elif !defined(SK_DEBUG) && !defined(SK_RELEASE) +# error "must define either SK_DEBUG or SK_RELEASE" +#endif + +#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) +# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" +#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) +# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" +#endif + +#if defined(SK_CPU_BENDIAN) && !defined(I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN) + #error "The Skia team is not endian-savvy enough to support big-endian CPUs." + #error "If you still want to use Skia," + #error "please define I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN." +#endif + +#define SK_USER_CONFIG_WAS_LOADED +#endif // SK_USER_CONFIG_WAS_LOADED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h similarity index 77% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h index 308c5d05fd4a7..5d1835d013096 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h @@ -7,8 +7,6 @@ #ifndef SkMacros_DEFINED #define SkMacros_DEFINED -#include - /* * Usage: SK_MACRO_CONCAT(a, b) to construct the symbol ab * @@ -40,6 +38,23 @@ #define SK_END_REQUIRE_DENSE #endif +#if defined(__clang__) && defined(__has_feature) + // Some compilers have a preprocessor that does not appear to do short-circuit + // evaluation as expected + #if __has_feature(leak_sanitizer) || __has_feature(address_sanitizer) + // Chrome had issues if we tried to include lsan_interface.h ourselves. + // https://github.com/llvm/llvm-project/blob/10a35632d55bb05004fe3d0c2d4432bb74897ee7/compiler-rt/include/sanitizer/lsan_interface.h#L26 +extern "C" { + void __lsan_ignore_object(const void *p); +} + #define SK_INTENTIONALLY_LEAKED(X) __lsan_ignore_object(X) + #else + #define SK_INTENTIONALLY_LEAKED(X) ((void)0) + #endif +#else + #define SK_INTENTIONALLY_LEAKED(X) ((void)0) +#endif + #define SK_INIT_TO_AVOID_WARNING = 0 //////////////////////////////////////////////////////////////////////////////// diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h similarity index 94% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h index 206bf14e2f877..1c0c2e73da625 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h @@ -8,10 +8,9 @@ #ifndef SkMalloc_DEFINED #define SkMalloc_DEFINED -#include #include -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" /* memory wrappers to be implemented by the porting layer (platform) @@ -51,7 +50,9 @@ enum { SK_API extern void* sk_malloc_flags(size_t size, unsigned flags); /** Same as standard realloc(), but this one never returns null on failure. It will throw - * an exception if it fails. + * if it fails. + * If size is 0, it will call sk_free on buffer and return null. (This behavior is implementation- + * defined for normal realloc. We follow what glibc does.) */ SK_API extern void* sk_realloc_throw(void* buffer, size_t size); @@ -78,10 +79,6 @@ SK_API extern void* sk_calloc_throw(size_t count, size_t elemSize); SK_API extern void* sk_malloc_throw(size_t count, size_t elemSize); SK_API extern void* sk_realloc_throw(void* buffer, size_t count, size_t elemSize); -// Returns the true usable size provided by the underlying allocator, or 0 if -// querying the allocation size is not supported. -SK_API extern size_t sk_malloc_usable_size(void* buffer); - /** * These variants return nullptr on failure */ diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h similarity index 64% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h index 97352afab9d6f..34bfa739f7a97 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h @@ -8,7 +8,22 @@ #ifndef SkMath_DEFINED #define SkMath_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkCPUTypes.h" + +#include +#include + +// Max Signed 16 bit value +static constexpr int16_t SK_MaxS16 = INT16_MAX; +static constexpr int16_t SK_MinS16 = -SK_MaxS16; + +static constexpr int32_t SK_MaxS32 = INT32_MAX; +static constexpr int32_t SK_MinS32 = -SK_MaxS32; +static constexpr int32_t SK_NaN32 = INT32_MIN; + +static constexpr int64_t SK_MaxS64 = INT64_MAX; +static constexpr int64_t SK_MinS64 = -SK_MaxS64; // 64bit -> 32bit utilities @@ -19,6 +34,14 @@ static inline int64_t sk_64_mul(int64_t a, int64_t b) { return a * b; } +static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { + return (int32_t) ((uint32_t) value << shift); +} + +static inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) { + return (int64_t) ((uint64_t) value << shift); +} + /////////////////////////////////////////////////////////////////////////////// /** @@ -48,7 +71,7 @@ static inline unsigned SkMul16ShiftRound(U16CPU a, U16CPU b, int shift) { * Only valid if a and b are unsigned and <= 32767. */ static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { - return SkMul16ShiftRound(a,b,8); + return SkMul16ShiftRound(a, b, 8); } #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h similarity index 86% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h index b7cdceb1e1d8d..4452beb912f56 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h @@ -8,11 +8,11 @@ #ifndef SkMutex_DEFINED #define SkMutex_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMacros.h" -#include "include/private/SkSemaphore.h" -#include "include/private/SkThreadAnnotations.h" -#include "include/private/SkThreadID.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkSemaphore.h" +#include "include/private/base/SkThreadAnnotations.h" +#include "include/private/base/SkThreadID.h" class SK_CAPABILITY("mutex") SkMutex { public: diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h similarity index 89% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h index bda5d50bb6804..ec4a4e5161199 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h @@ -8,9 +8,9 @@ #ifndef SkNoncopyable_DEFINED #define SkNoncopyable_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" -/** \class SkNoncopyable +/** \class SkNoncopyable (DEPRECATED) SkNoncopyable is the base class for objects that do not want to be copied. It hides its copy-constructor and its assignment-operator. diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h similarity index 96% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h index edf3e833582b5..97ce6b6311e0b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h @@ -8,8 +8,10 @@ #ifndef SkOnce_DEFINED #define SkOnce_DEFINED -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkThreadAnnotations.h" + #include +#include #include // SkOnce provides call-once guarantees for Skia, much like std::once_flag/std::call_once(). diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h new file mode 100644 index 0000000000000..642bbb3489f7e --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h @@ -0,0 +1,25 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * This file contains private enums related to paths. See also skbug.com/10670 + */ + +#ifndef SkPathEnums_DEFINED +#define SkPathEnums_DEFINED + +enum class SkPathConvexity { + kConvex, + kConcave, + kUnknown, +}; + +enum class SkPathFirstDirection { + kCW, // == SkPathDirection::kCW + kCCW, // == SkPathDirection::kCCW + kUnknown, +}; + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h similarity index 64% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h index 7e59f2b0040ad..5ba4c2f9a48e2 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h @@ -8,7 +8,10 @@ #ifndef SkSafe32_DEFINED #define SkSafe32_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkMath.h" + +#include static constexpr int32_t Sk64_pin_to_s32(int64_t x) { return x < SK_MinS32 ? SK_MinS32 : (x > SK_MaxS32 ? SK_MaxS32 : (int32_t)x); @@ -31,4 +34,16 @@ static constexpr int32_t Sk32_can_overflow_sub(int32_t a, int32_t b) { return (int32_t)((uint32_t)a - (uint32_t)b); } +/** + * This is a 'safe' abs for 32-bit integers that asserts when undefined behavior would occur. + * SkTAbs (in SkTemplates.h) is a general purpose absolute-value function. + */ +static inline int32_t SkAbs32(int32_t value) { + SkASSERT(value != SK_NaN32); // The most negative int32_t can't be negated. + if (value < 0) { + value = -value; + } + return value; +} + #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h similarity index 95% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h index d7318be577919..f78ee86625a42 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h @@ -8,9 +8,10 @@ #ifndef SkSemaphore_DEFINED #define SkSemaphore_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkOnce.h" -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkThreadAnnotations.h" + #include #include diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h new file mode 100644 index 0000000000000..5f31a651bb375 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h @@ -0,0 +1,129 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkSpan_DEFINED +#define SkSpan_DEFINED + +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTo.h" + +#include +#include +#include +#include +#include + +// Having this be an export works around IWYU churn related to +// https://github.com/include-what-you-use/include-what-you-use/issues/1121 +#include // IWYU pragma: export + +// Add macro to check the lifetime of initializer_list arguments. initializer_list has a very +// short life span, and can only be used as a parameter, and not as a variable. +#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::lifetimebound) +#define SK_CHECK_IL_LIFETIME [[clang::lifetimebound]] +#else +#define SK_CHECK_IL_LIFETIME +#endif + +/** + * SkSpan holds a reference to contiguous data of type T along with a count. SkSpan does not own + * the data itself but is merely a reference, therefore you must take care with the lifetime of + * the underlying data. + * + * SkSpan is a count and a pointer into existing array or data type that stores its data in + * contiguous memory like std::vector. Any container that works with std::size() and std::data() + * can be used. + * + * SkSpan makes a convenient parameter for a routine to accept array like things. This allows you to + * write the routine without overloads for all different container types. + * + * Example: + * void routine(SkSpan a) { ... } + * + * std::vector v = {1, 2, 3, 4, 5}; + * + * routine(a); + * + * A word of caution when working with initializer_list, initializer_lists have a lifetime that is + * limited to the current statement. The following is correct and safe: + * + * Example: + * routine({1,2,3,4,5}); + * + * The following is undefined, and will result in erratic execution: + * + * Bad Example: + * initializer_list l = {1, 2, 3, 4, 5}; // The data behind l dies at the ;. + * routine(l); + */ +template +class SkSpan { +public: + constexpr SkSpan() : fPtr{nullptr}, fSize{0} {} + + template , bool> = true> + constexpr SkSpan(T* ptr, Integer size) : fPtr{ptr}, fSize{SkToSizeT(size)} { + SkASSERT(ptr || fSize == 0); // disallow nullptr + a nonzero size + SkASSERT(fSize < kMaxSize); + } + template >> + constexpr SkSpan(const SkSpan& that) : fPtr(std::data(that)), fSize(std::size(that)) {} + constexpr SkSpan(const SkSpan& o) = default; + template constexpr SkSpan(T(&a)[N]) : SkSpan(a, N) { } + template + constexpr SkSpan(Container& c) : SkSpan(std::data(c), std::size(c)) { } + SkSpan(std::initializer_list il SK_CHECK_IL_LIFETIME) + : SkSpan(std::data(il), std::size(il)) {} + + constexpr SkSpan& operator=(const SkSpan& that) = default; + + constexpr T& operator [] (size_t i) const { + SkASSERT(i < this->size()); + return fPtr[i]; + } + constexpr T& front() const { return fPtr[0]; } + constexpr T& back() const { return fPtr[fSize - 1]; } + constexpr T* begin() const { return fPtr; } + constexpr T* end() const { return fPtr + fSize; } + constexpr auto rbegin() const { return std::make_reverse_iterator(this->end()); } + constexpr auto rend() const { return std::make_reverse_iterator(this->begin()); } + constexpr T* data() const { return this->begin(); } + constexpr size_t size() const { return fSize; } + constexpr bool empty() const { return fSize == 0; } + constexpr size_t size_bytes() const { return fSize * sizeof(T); } + constexpr SkSpan first(size_t prefixLen) const { + SkASSERT(prefixLen <= this->size()); + return SkSpan{fPtr, prefixLen}; + } + constexpr SkSpan last(size_t postfixLen) const { + SkASSERT(postfixLen <= this->size()); + return SkSpan{fPtr + (this->size() - postfixLen), postfixLen}; + } + constexpr SkSpan subspan(size_t offset) const { + return this->subspan(offset, this->size() - offset); + } + constexpr SkSpan subspan(size_t offset, size_t count) const { + SkASSERT(offset <= this->size()); + SkASSERT(count <= this->size() - offset); + return SkSpan{fPtr + offset, count}; + } + +private: + static const constexpr size_t kMaxSize = std::numeric_limits::max() / sizeof(T); + T* fPtr; + size_t fSize; +}; + +template +SkSpan(Container&) -> + SkSpan()))>>; + +template +SkSpan(std::initializer_list) -> + SkSpan>()))>>; + +#endif // SkSpan_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h new file mode 100644 index 0000000000000..de8e276513b2e --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h @@ -0,0 +1,694 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkTArray_DEFINED +#define SkTArray_DEFINED + +#include "include/private/base/SkAlignedStorage.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkContainers.h" +#include "include/private/base/SkMalloc.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkSpan_impl.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" // IWYU pragma: keep + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace skia_private { +/** TArray implements a typical, mostly std::vector-like array. + Each T will be default-initialized on allocation, and ~T will be called on destruction. + + MEM_MOVE controls the behavior when a T needs to be moved (e.g. when the array is resized) + - true: T will be bit-copied via memcpy. + - false: T will be moved via move-constructors. +*/ +template > class TArray { +public: + using value_type = T; + + /** + * Creates an empty array with no initial storage + */ + TArray() : fOwnMemory(true), fCapacity{0} {} + + /** + * Creates an empty array that will preallocate space for reserveCount + * elements. + */ + explicit TArray(int reserveCount) : TArray() { this->reserve_back(reserveCount); } + + /** + * Copies one array to another. The new array will be heap allocated. + */ + TArray(const TArray& that) : TArray(that.fData, that.fSize) {} + + TArray(TArray&& that) { + if (that.fOwnMemory) { + this->setData(that); + that.setData({}); + } else { + this->initData(that.fSize); + that.move(fData); + } + fSize = std::exchange(that.fSize, 0); + } + + /** + * Creates a TArray by copying contents of a standard C array. The new + * array will be heap allocated. Be careful not to use this constructor + * when you really want the (void*, int) version. + */ + TArray(const T* array, int count) { + this->initData(count); + this->copy(array); + } + + /** + * Creates a TArray by copying contents of an initializer list. + */ + TArray(std::initializer_list data) : TArray(data.begin(), data.size()) {} + + TArray& operator=(const TArray& that) { + if (this == &that) { + return *this; + } + this->clear(); + this->checkRealloc(that.size(), kExactFit); + fSize = that.fSize; + this->copy(that.fData); + return *this; + } + TArray& operator=(TArray&& that) { + if (this != &that) { + this->clear(); + if (that.fOwnMemory) { + // The storage is on the heap, so move the data pointer. + if (fOwnMemory) { + sk_free(fData); + } + + fData = std::exchange(that.fData, nullptr); + + // Can't use exchange with bitfields. + fCapacity = that.fCapacity; + that.fCapacity = 0; + + fOwnMemory = true; + } else { + // The data is stored inline in that, so move it element-by-element. + this->checkRealloc(that.size(), kExactFit); + that.move(fData); + } + fSize = std::exchange(that.fSize, 0); + } + return *this; + } + + ~TArray() { + this->destroyAll(); + if (fOwnMemory) { + sk_free(fData); + } + } + + /** + * Resets to size() = n newly constructed T objects and resets any reserve count. + */ + void reset(int n) { + SkASSERT(n >= 0); + this->clear(); + this->checkRealloc(n, kExactFit); + fSize = n; + for (int i = 0; i < this->size(); ++i) { + new (fData + i) T; + } + } + + /** + * Resets to a copy of a C array and resets any reserve count. + */ + void reset(const T* array, int count) { + SkASSERT(count >= 0); + this->clear(); + this->checkRealloc(count, kExactFit); + fSize = count; + this->copy(array); + } + + /** + * Ensures there is enough reserved space for n elements. + */ + void reserve(int n) { + SkASSERT(n >= 0); + if (n > this->size()) { + this->checkRealloc(n - this->size(), kGrowing); + } + } + + /** + * Ensures there is enough reserved space for n additional elements. The is guaranteed at least + * until the array size grows above n and subsequently shrinks below n, any version of reset() + * is called, or reserve_back() is called again. + */ + void reserve_back(int n) { + SkASSERT(n >= 0); + if (n > 0) { + this->checkRealloc(n, kExactFit); + } + } + + void removeShuffle(int n) { + SkASSERT(n < this->size()); + int newCount = fSize - 1; + fSize = newCount; + fData[n].~T(); + if (n != newCount) { + this->move(n, newCount); + } + } + + // Is the array empty. + bool empty() const { return fSize == 0; } + + /** + * Adds 1 new default-initialized T value and returns it by reference. Note + * the reference only remains valid until the next call that adds or removes + * elements. + */ + T& push_back() { + void* newT = this->push_back_raw(1); + return *new (newT) T; + } + + /** + * Version of above that uses a copy constructor to initialize the new item + */ + T& push_back(const T& t) { + void* newT = this->push_back_raw(1); + return *new (newT) T(t); + } + + /** + * Version of above that uses a move constructor to initialize the new item + */ + T& push_back(T&& t) { + void* newT = this->push_back_raw(1); + return *new (newT) T(std::move(t)); + } + + /** + * Construct a new T at the back of this array. + */ + template T& emplace_back(Args&&... args) { + void* newT = this->push_back_raw(1); + return *new (newT) T(std::forward(args)...); + } + + /** + * Allocates n more default-initialized T values, and returns the address of + * the start of that new range. Note: this address is only valid until the + * next API call made on the array that might add or remove elements. + */ + T* push_back_n(int n) { + SkASSERT(n >= 0); + T* newTs = TCast(this->push_back_raw(n)); + for (int i = 0; i < n; ++i) { + new (&newTs[i]) T; + } + return newTs; + } + + /** + * Version of above that uses a copy constructor to initialize all n items + * to the same T. + */ + T* push_back_n(int n, const T& t) { + SkASSERT(n >= 0); + T* newTs = TCast(this->push_back_raw(n)); + for (int i = 0; i < n; ++i) { + new (&newTs[i]) T(t); + } + return static_cast(newTs); + } + + /** + * Version of above that uses a copy constructor to initialize the n items + * to separate T values. + */ + T* push_back_n(int n, const T t[]) { + SkASSERT(n >= 0); + this->checkRealloc(n, kGrowing); + T* end = this->end(); + for (int i = 0; i < n; ++i) { + new (end + i) T(t[i]); + } + fSize += n; + return end; + } + + /** + * Version of above that uses the move constructor to set n items. + */ + T* move_back_n(int n, T* t) { + SkASSERT(n >= 0); + this->checkRealloc(n, kGrowing); + T* end = this->end(); + for (int i = 0; i < n; ++i) { + new (end + i) T(std::move(t[i])); + } + fSize += n; + return end; + } + + /** + * Removes the last element. Not safe to call when size() == 0. + */ + void pop_back() { + SkASSERT(fSize > 0); + --fSize; + fData[fSize].~T(); + } + + /** + * Removes the last n elements. Not safe to call when size() < n. + */ + void pop_back_n(int n) { + SkASSERT(n >= 0); + SkASSERT(this->size() >= n); + int i = fSize; + while (i-- > fSize - n) { + (*this)[i].~T(); + } + fSize -= n; + } + + /** + * Pushes or pops from the back to resize. Pushes will be default + * initialized. + */ + void resize_back(int newCount) { + SkASSERT(newCount >= 0); + + if (newCount > this->size()) { + this->push_back_n(newCount - fSize); + } else if (newCount < this->size()) { + this->pop_back_n(fSize - newCount); + } + } + + /** Swaps the contents of this array with that array. Does a pointer swap if possible, + otherwise copies the T values. */ + void swap(TArray& that) { + using std::swap; + if (this == &that) { + return; + } + if (fOwnMemory && that.fOwnMemory) { + swap(fData, that.fData); + swap(fSize, that.fSize); + + // Can't use swap because fCapacity is a bit field. + auto allocCount = fCapacity; + fCapacity = that.fCapacity; + that.fCapacity = allocCount; + } else { + // This could be more optimal... + TArray copy(std::move(that)); + that = std::move(*this); + *this = std::move(copy); + } + } + + T* begin() { + return fData; + } + const T* begin() const { + return fData; + } + + // It's safe to use fItemArray + fSize because if fItemArray is nullptr then adding 0 is + // valid and returns nullptr. See [expr.add] in the C++ standard. + T* end() { + if (fData == nullptr) { + SkASSERT(fSize == 0); + } + return fData + fSize; + } + const T* end() const { + if (fData == nullptr) { + SkASSERT(fSize == 0); + } + return fData + fSize; + } + T* data() { return fData; } + const T* data() const { return fData; } + int size() const { return fSize; } + size_t size_bytes() const { return this->bytes(fSize); } + void resize(size_t count) { this->resize_back((int)count); } + + void clear() { + this->destroyAll(); + fSize = 0; + } + + void shrink_to_fit() { + if (!fOwnMemory || fSize == fCapacity) { + return; + } + if (fSize == 0) { + sk_free(fData); + fData = nullptr; + fCapacity = 0; + } else { + SkSpan allocation = Allocate(fSize); + this->move(TCast(allocation.data())); + if (fOwnMemory) { + sk_free(fData); + } + this->setDataFromBytes(allocation); + } + } + + /** + * Get the i^th element. + */ + T& operator[] (int i) { + SkASSERT(i < this->size()); + SkASSERT(i >= 0); + return fData[i]; + } + + const T& operator[] (int i) const { + SkASSERT(i < this->size()); + SkASSERT(i >= 0); + return fData[i]; + } + + T& at(int i) { return (*this)[i]; } + const T& at(int i) const { return (*this)[i]; } + + /** + * equivalent to operator[](0) + */ + T& front() { SkASSERT(fSize > 0); return fData[0];} + + const T& front() const { SkASSERT(fSize > 0); return fData[0];} + + /** + * equivalent to operator[](size() - 1) + */ + T& back() { SkASSERT(fSize); return fData[fSize - 1];} + + const T& back() const { SkASSERT(fSize > 0); return fData[fSize - 1];} + + /** + * equivalent to operator[](size()-1-i) + */ + T& fromBack(int i) { + SkASSERT(i >= 0); + SkASSERT(i < this->size()); + return fData[fSize - i - 1]; + } + + const T& fromBack(int i) const { + SkASSERT(i >= 0); + SkASSERT(i < this->size()); + return fData[fSize - i - 1]; + } + + bool operator==(const TArray& right) const { + int leftCount = this->size(); + if (leftCount != right.size()) { + return false; + } + for (int index = 0; index < leftCount; ++index) { + if (fData[index] != right.fData[index]) { + return false; + } + } + return true; + } + + bool operator!=(const TArray& right) const { + return !(*this == right); + } + + int capacity() const { + return fCapacity; + } + +protected: + // Creates an empty array that will use the passed storage block until it is insufficiently + // large to hold the entire array. + template + TArray(SkAlignedSTStorage* storage, int size = 0) { + static_assert(InitialCapacity >= 0); + SkASSERT(size >= 0); + SkASSERT(storage->get() != nullptr); + if (size > InitialCapacity) { + this->initData(size); + } else { + this->setDataFromBytes(*storage); + fSize = size; + + // setDataFromBytes always sets fOwnMemory to true, but we are actually using static + // storage here, which shouldn't ever be freed. + fOwnMemory = false; + } + } + + // Copy a C array, using pre-allocated storage if preAllocCount >= count. Otherwise, storage + // will only be used when array shrinks to fit. + template + TArray(const T* array, int size, SkAlignedSTStorage* storage) + : TArray{storage, size} + { + this->copy(array); + } + +private: + // Growth factors for checkRealloc. + static constexpr double kExactFit = 1.0; + static constexpr double kGrowing = 1.5; + + static constexpr int kMinHeapAllocCount = 8; + static_assert(SkIsPow2(kMinHeapAllocCount), "min alloc count not power of two."); + + // Note for 32-bit machines kMaxCapacity will be <= SIZE_MAX. For 64-bit machines it will + // just be INT_MAX if the sizeof(T) < 2^32. + static constexpr int kMaxCapacity = SkToInt(std::min(SIZE_MAX / sizeof(T), (size_t)INT_MAX)); + + void setDataFromBytes(SkSpan allocation) { + T* data = TCast(allocation.data()); + // We have gotten extra bytes back from the allocation limit, pin to kMaxCapacity. It + // would seem like the SkContainerAllocator should handle the divide, but it would have + // to a full divide instruction. If done here the size is known at compile, and usually + // can be implemented by a right shift. The full divide takes ~50X longer than the shift. + size_t size = std::min(allocation.size() / sizeof(T), SkToSizeT(kMaxCapacity)); + setData(SkSpan(data, size)); + } + + void setData(SkSpan array) { + fData = array.data(); + fCapacity = SkToU32(array.size()); + fOwnMemory = true; + } + + // We disable Control-Flow Integrity sanitization (go/cfi) when casting item-array buffers. + // CFI flags this code as dangerous because we are casting `buffer` to a T* while the buffer's + // contents might still be uninitialized memory. When T has a vtable, this is especially risky + // because we could hypothetically access a virtual method on fItemArray and jump to an + // unpredictable location in memory. Of course, TArray won't actually use fItemArray in this + // way, and we don't want to construct a T before the user requests one. There's no real risk + // here, so disable CFI when doing these casts. + SK_CLANG_NO_SANITIZE("cfi") + static T* TCast(void* buffer) { + return (T*)buffer; + } + + size_t bytes(int n) const { + SkASSERT(n <= kMaxCapacity); + return SkToSizeT(n) * sizeof(T); + } + + static SkSpan Allocate(int capacity, double growthFactor = 1.0) { + return SkContainerAllocator{sizeof(T), kMaxCapacity}.allocate(capacity, growthFactor); + } + + void initData(int count) { + this->setDataFromBytes(Allocate(count)); + fSize = count; + } + + void destroyAll() { + if (!this->empty()) { + T* cursor = this->begin(); + T* const end = this->end(); + do { + cursor->~T(); + cursor++; + } while (cursor < end); + } + } + + /** In the following move and copy methods, 'dst' is assumed to be uninitialized raw storage. + * In the following move methods, 'src' is destroyed leaving behind uninitialized raw storage. + */ + void copy(const T* src) { + if constexpr (std::is_trivially_copyable_v) { + if (!this->empty() && src != nullptr) { + sk_careful_memcpy(fData, src, this->size_bytes()); + } + } else { + for (int i = 0; i < this->size(); ++i) { + new (fData + i) T(src[i]); + } + } + } + + void move(int dst, int src) { + if constexpr (MEM_MOVE) { + memcpy(static_cast(&fData[dst]), + static_cast(&fData[src]), + sizeof(T)); + } else { + new (&fData[dst]) T(std::move(fData[src])); + fData[src].~T(); + } + } + + void move(void* dst) { + if constexpr (MEM_MOVE) { + sk_careful_memcpy(dst, fData, this->bytes(fSize)); + } else { + for (int i = 0; i < this->size(); ++i) { + new (static_cast(dst) + this->bytes(i)) T(std::move(fData[i])); + fData[i].~T(); + } + } + } + + // Helper function that makes space for n objects, adjusts the count, but does not initialize + // the new objects. + void* push_back_raw(int n) { + this->checkRealloc(n, kGrowing); + void* ptr = fData + fSize; + fSize += n; + return ptr; + } + + void checkRealloc(int delta, double growthFactor) { + // This constant needs to be declared in the function where it is used to work around + // MSVC's persnickety nature about template definitions. + SkASSERT(delta >= 0); + SkASSERT(fSize >= 0); + SkASSERT(fCapacity >= 0); + + // Return if there are enough remaining allocated elements to satisfy the request. + if (this->capacity() - fSize >= delta) { + return; + } + + // Don't overflow fSize or size_t later in the memory allocation. Overflowing memory + // allocation really only applies to fSizes on 32-bit machines; on 64-bit machines this + // will probably never produce a check. Since kMaxCapacity is bounded above by INT_MAX, + // this also checks the bounds of fSize. + if (delta > kMaxCapacity - fSize) { + sk_report_container_overflow_and_die(); + } + const int newCount = fSize + delta; + + SkSpan allocation = Allocate(newCount, growthFactor); + + this->move(TCast(allocation.data())); + if (fOwnMemory) { + sk_free(fData); + } + this->setDataFromBytes(allocation); + SkASSERT(this->capacity() >= newCount); + SkASSERT(fData != nullptr); + } + + T* fData{nullptr}; + int fSize{0}; + uint32_t fOwnMemory : 1; + uint32_t fCapacity : 31; +}; + +template static inline void swap(TArray& a, TArray& b) { + a.swap(b); +} + +// Subclass of TArray that contains a pre-allocated memory block for the array. +template > +class STArray : private SkAlignedSTStorage, public TArray { + static_assert(N > 0); + using Storage = SkAlignedSTStorage; + +public: + STArray() + : Storage{} + , TArray(this) {} // Must use () to avoid confusion with initializer_list + // when T=bool because * are convertable to bool. + + STArray(const T* array, int count) + : Storage{} + , TArray{array, count, this} {} + + STArray(std::initializer_list data) + : STArray{data.begin(), SkToInt(data.size())} {} + + explicit STArray(int reserveCount) + : STArray() { this->reserve_back(reserveCount); } + + STArray(const STArray& that) + : STArray() { *this = that; } + + explicit STArray(const TArray& that) + : STArray() { *this = that; } + + STArray(STArray&& that) + : STArray() { *this = std::move(that); } + + explicit STArray(TArray&& that) + : STArray() { *this = std::move(that); } + + STArray& operator=(const STArray& that) { + TArray::operator=(that); + return *this; + } + + STArray& operator=(const TArray& that) { + TArray::operator=(that); + return *this; + } + + STArray& operator=(STArray&& that) { + TArray::operator=(std::move(that)); + return *this; + } + + STArray& operator=(TArray&& that) { + TArray::operator=(std::move(that)); + return *this; + } + + // Force the use of TArray for data() and size(). + using TArray::data; + using TArray::size; +}; +} // namespace skia_private +#endif // SkTArray_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h similarity index 81% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h index 1b56266535a56..b08d285378b10 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h @@ -8,21 +8,18 @@ #ifndef SkTDArray_DEFINED #define SkTDArray_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTo.h" #include #include -#include #include -#include -#include class SK_SPI SkTDStorage { public: explicit SkTDStorage(int sizeOfT); - SkTDStorage(const void* src, int count, int sizeOfT); + SkTDStorage(const void* src, int size, int sizeOfT); // Copy SkTDStorage(const SkTDStorage& that); @@ -38,15 +35,15 @@ class SK_SPI SkTDStorage { void swap(SkTDStorage& that); // Size routines - bool empty() const { return fCount == 0; } - void clear() { fCount = 0; } - int size() const { return fCount; } - void resize(int newCount); - size_t size_bytes() const { return this->bytes(fCount); } + bool empty() const { return fSize == 0; } + void clear() { fSize = 0; } + int size() const { return fSize; } + void resize(int newSize); + size_t size_bytes() const { return this->bytes(fSize); } // Capacity routines - int capacity() const { return fReserve; } - void reserve(int newReserve); + int capacity() const { return fCapacity; } + void reserve(int newCapacity); void shrink_to_fit(); void* data() { return fStorage; } @@ -68,8 +65,8 @@ class SK_SPI SkTDStorage { void* insert(int index, int count, const void* src); void pop_back() { - SkASSERT(fCount > 0); - fCount--; + SkASSERT(fSize > 0); + fSize--; } friend bool operator==(const SkTDStorage& a, const SkTDStorage& b); @@ -81,7 +78,7 @@ class SK_SPI SkTDStorage { size_t bytes(int n) const { return SkToSizeT(n * fSizeOfT); } void* address(int n) { return fStorage + this->bytes(n); } - // Adds delta to fCount. Crash if outside [0, INT_MAX] + // Adds delta to fSize. Crash if outside [0, INT_MAX] int calculateSizeOrDie(int delta); // Move the tail of the array defined by the indexes tailStart and tailEnd to dstIndex. The @@ -93,8 +90,8 @@ class SK_SPI SkTDStorage { const int fSizeOfT; std::byte* fStorage{nullptr}; - int fReserve{0}; // size of the allocation in fArray (#elements) - int fCount{0}; // logical number of elements (fCount <= fReserve) + int fCapacity{0}; // size of the allocation in fArray (#elements) + int fSize{0}; // logical number of elements (fSize <= fCapacity) }; static inline void swap(SkTDStorage& a, SkTDStorage& b) { @@ -188,7 +185,7 @@ template class SkTDArray { fStorage.resize(count); } - void reserve(size_t n) { + void reserve(int n) { fStorage.reserve(n); } @@ -219,18 +216,6 @@ template class SkTDArray { fStorage.removeShuffle(index); } - int find(const T& elem) const { - const T* iter = this->begin(); - const T* stop = this->end(); - - for (; iter < stop; iter++) { - if (*iter == elem) { - return SkToInt(iter - this->begin()); - } - } - return -1; - } - // routines to treat the array like a stack void push_back(const T& v) { this->append(); @@ -238,28 +223,6 @@ template class SkTDArray { } void pop_back() { fStorage.pop_back(); } - void deleteAll() { - for (T p : *this) { - delete p; - } - this->reset(); - } - - void freeAll() { - for (T p : *this) { - sk_free(p); - } - - this->reset(); - } - - void unrefAll() { - for (T p : *this) { - p->unref(); - } - this->reset(); - } - void shrink_to_fit() { fStorage.shrink_to_fit(); } diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h similarity index 82% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h index a912f13e08c01..365748abef483 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h @@ -8,8 +8,10 @@ #ifndef SkTFitsIn_DEFINED #define SkTFitsIn_DEFINED +#include "include/private/base/SkDebug.h" + +#include #include -#include #include /** @@ -71,28 +73,32 @@ static constexpr inline typename std::enable_if<(std::is_integral::value || std::is_enum::value) && (std::is_integral::value || std::is_enum::value), bool>::type /*bool*/ SkTFitsIn(S src) { + // Ensure that is_signed and is_unsigned are passed the arithmetic underlyng types of enums. + using Sa = typename sk_strip_enum::type; + using Da = typename sk_strip_enum::type; + // SkTFitsIn() is used in public headers, so needs to be written targeting at most C++11. return // E.g. (int8_t)(uint8_t) int8_t(-1) == -1, but the uint8_t == 255, not -1. - (std::is_signed::value && std::is_unsigned::value && sizeof(S) <= sizeof(D)) ? + (std::is_signed::value && std::is_unsigned::value && sizeof(Sa) <= sizeof(Da)) ? (S)0 <= src : // E.g. (uint8_t)(int8_t) uint8_t(255) == 255, but the int8_t == -1. - (std::is_signed::value && std::is_unsigned::value && sizeof(D) <= sizeof(S)) ? - src <= (S)std::numeric_limits::type>::max() : + (std::is_signed::value && std::is_unsigned::value && sizeof(Da) <= sizeof(Sa)) ? + src <= (S)std::numeric_limits::max() : #if !defined(SK_DEBUG) && !defined(__MSVC_RUNTIME_CHECKS ) // Correct (simple) version. This trips up MSVC's /RTCc run-time checking. (S)(D)src == src; #else // More complex version that's safe with /RTCc. Used in all debug builds, for coverage. - (std::is_signed::value) ? - (intmax_t)src >= (intmax_t)std::numeric_limits::type>::min() && - (intmax_t)src <= (intmax_t)std::numeric_limits::type>::max() : + (std::is_signed::value) ? + (intmax_t)src >= (intmax_t)std::numeric_limits::min() && + (intmax_t)src <= (intmax_t)std::numeric_limits::max() : // std::is_unsigned ? - (uintmax_t)src <= (uintmax_t)std::numeric_limits::type>::max(); + (uintmax_t)src <= (uintmax_t)std::numeric_limits::max(); #endif } diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h similarity index 98% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h index dce0dc804becd..26f363c94699e 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h @@ -14,7 +14,7 @@ #include #include -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" // The sknonstd namespace contains things we would like to be proposed and feel std-ish. namespace sknonstd { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTPin.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTPin.h similarity index 100% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTPin.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTPin.h diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h similarity index 73% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h index 16b0e0e586a29..cbcf36c5943b8 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h @@ -8,18 +8,21 @@ #ifndef SkTemplates_DEFINED #define SkTemplates_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkAlign.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMalloc.h" +#include "include/private/base/SkTLogic.h" -#include #include #include +#include +#include #include -#include #include #include + /** \file SkTemplates.h This file contains light-weight template classes for type-safe and exception-safe @@ -32,6 +35,17 @@ */ template inline void sk_ignore_unused_variable(const T&) { } +/** + * This is a general purpose absolute-value function. + * See SkAbs32 in (SkSafe32.h) for a 32-bit int specific version that asserts. + */ +template static inline T SkTAbs(T value) { + if (value < 0) { + value = -value; + } + return value; +} + /** * Returns a pointer to a D which comes immediately after S[count]. */ @@ -48,14 +62,16 @@ template inline D* SkTAddOffset(S* ptr, ptrdiff_t byteO return reinterpret_cast(reinterpret_cast*>(ptr) + byteOffset); } -// TODO: when C++17 the language is available, use template -template struct SkFunctionWrapper { +template struct SkOverloadedFunctionObject { template auto operator()(Args&&... args) const -> decltype(P(std::forward(args)...)) { return P(std::forward(args)...); } }; +template using SkFunctionObject = + SkOverloadedFunctionObject, F>; + /** \class SkAutoTCallVProc Call a function when this goes out of scope. The template uses two @@ -65,8 +81,8 @@ template struct SkFunctionWrapper { function. */ template class SkAutoTCallVProc - : public std::unique_ptr, P>> { - using inherited = std::unique_ptr, P>>; + : public std::unique_ptr> { + using inherited = std::unique_ptr>; public: using inherited::inherited; SkAutoTCallVProc(const SkAutoTCallVProc&) = delete; @@ -75,14 +91,16 @@ template class SkAutoTCallVProc operator T*() const { return this->get(); } }; + +namespace skia_private { /** Allocate an array of T elements, and free the array in the destructor */ -template class SkAutoTArray { +template class AutoTArray { public: - SkAutoTArray() {} + AutoTArray() {} /** Allocate count number of T elements */ - explicit SkAutoTArray(int count) { + explicit AutoTArray(int count) { SkASSERT(count >= 0); if (count) { fArray.reset(new T[count]); @@ -90,10 +108,10 @@ template class SkAutoTArray { SkDEBUGCODE(fCount = count;) } - SkAutoTArray(SkAutoTArray&& other) : fArray(std::move(other.fArray)) { + AutoTArray(AutoTArray&& other) : fArray(std::move(other.fArray)) { SkDEBUGCODE(fCount = other.fCount; other.fCount = 0;) } - SkAutoTArray& operator=(SkAutoTArray&& other) { + AutoTArray& operator=(AutoTArray&& other) { if (this != &other) { fArray = std::move(other.fArray); SkDEBUGCODE(fCount = other.fCount; other.fCount = 0;) @@ -103,7 +121,7 @@ template class SkAutoTArray { /** Reallocates given a new count. Reallocation occurs even if new count equals old count. */ - void reset(int count = 0) { *this = SkAutoTArray(count); } + void reset(int count = 0) { *this = AutoTArray(count); } /** Return the array of T elements. Will be NULL if count == 0 */ @@ -125,30 +143,30 @@ template class SkAutoTArray { SkDEBUGCODE(int fCount = 0;) }; -/** Wraps SkAutoTArray, with room for kCountRequested elements preallocated. +/** Wraps AutoTArray, with room for kCountRequested elements preallocated. */ -template class SkAutoSTArray { +template class AutoSTArray { public: - SkAutoSTArray(SkAutoSTArray&&) = delete; - SkAutoSTArray(const SkAutoSTArray&) = delete; - SkAutoSTArray& operator=(SkAutoSTArray&&) = delete; - SkAutoSTArray& operator=(const SkAutoSTArray&) = delete; + AutoSTArray(AutoSTArray&&) = delete; + AutoSTArray(const AutoSTArray&) = delete; + AutoSTArray& operator=(AutoSTArray&&) = delete; + AutoSTArray& operator=(const AutoSTArray&) = delete; /** Initialize with no objects */ - SkAutoSTArray() { + AutoSTArray() { fArray = nullptr; fCount = 0; } /** Allocate count number of T elements */ - SkAutoSTArray(int count) { + AutoSTArray(int count) { fArray = nullptr; fCount = 0; this->reset(count); } - ~SkAutoSTArray() { + ~AutoSTArray() { this->reset(0); } @@ -216,8 +234,8 @@ template class SkAutoSTArray { private: #if defined(SK_BUILD_FOR_GOOGLE3) - // Stack frame size is limited for SK_BUILD_FOR_GOOGLE3. 4k is less than the actual max, but some functions - // have multiple large stack allocations. + // Stack frame size is limited for SK_BUILD_FOR_GOOGLE3. 4k is less than the actual max, + // but some functions have multiple large stack allocations. static const int kMaxBytes = 4 * 1024; static const int kCount = kCountRequested * sizeof(T) > kMaxBytes ? kMaxBytes / sizeof(T) @@ -226,10 +244,9 @@ template class SkAutoSTArray { static const int kCount = kCountRequested; #endif - int fCount; - T* fArray; - // since we come right after fArray, fStorage should be properly aligned - char fStorage[kCount * sizeof(T)]; + int fCount; + T* fArray; + alignas(T) char fStorage[kCount * sizeof(T)]; }; /** Manages an array of T elements, freeing the array in the destructor. @@ -238,17 +255,17 @@ template class SkAutoSTArray { template ::value && std::is_trivially_destructible::value>> -class SkAutoTMalloc { +class AutoTMalloc { public: /** Takes ownership of the ptr. The ptr must be a value which can be passed to sk_free. */ - explicit SkAutoTMalloc(T* ptr = nullptr) : fPtr(ptr) {} + explicit AutoTMalloc(T* ptr = nullptr) : fPtr(ptr) {} /** Allocates space for 'count' Ts. */ - explicit SkAutoTMalloc(size_t count) + explicit AutoTMalloc(size_t count) : fPtr(count ? (T*)sk_malloc_throw(count, sizeof(T)) : nullptr) {} - SkAutoTMalloc(SkAutoTMalloc&&) = default; - SkAutoTMalloc& operator=(SkAutoTMalloc&&) = default; + AutoTMalloc(AutoTMalloc&&) = default; + AutoTMalloc& operator=(AutoTMalloc&&) = default; /** Resize the memory area pointed to by the current ptr preserving contents. */ void realloc(size_t count) { @@ -283,18 +300,18 @@ class SkAutoTMalloc { T* release() { return fPtr.release(); } private: - std::unique_ptr> fPtr; + std::unique_ptr> fPtr; }; template ::value && std::is_trivially_destructible::value>> -class SkAutoSTMalloc { +class AutoSTMalloc { public: - SkAutoSTMalloc() : fPtr(fTStorage) {} + AutoSTMalloc() : fPtr(fTStorage) {} - SkAutoSTMalloc(size_t count) { + AutoSTMalloc(size_t count) { if (count > kCount) { fPtr = (T*)sk_malloc_throw(count, sizeof(T)); } else if (count) { @@ -304,12 +321,12 @@ class SkAutoSTMalloc { } } - SkAutoSTMalloc(SkAutoSTMalloc&&) = delete; - SkAutoSTMalloc(const SkAutoSTMalloc&) = delete; - SkAutoSTMalloc& operator=(SkAutoSTMalloc&&) = delete; - SkAutoSTMalloc& operator=(const SkAutoSTMalloc&) = delete; + AutoSTMalloc(AutoSTMalloc&&) = delete; + AutoSTMalloc(const AutoSTMalloc&) = delete; + AutoSTMalloc& operator=(AutoSTMalloc&&) = delete; + AutoSTMalloc& operator=(const AutoSTMalloc&) = delete; - ~SkAutoSTMalloc() { + ~AutoSTMalloc() { if (fPtr != fTStorage) { sk_free(fPtr); } @@ -391,27 +408,9 @@ class SkAutoSTMalloc { }; }; -////////////////////////////////////////////////////////////////////////////////////////////////// +using UniqueVoidPtr = std::unique_ptr>; -template class SkAlignedSTStorage { -public: - SkAlignedSTStorage() {} - SkAlignedSTStorage(SkAlignedSTStorage&&) = delete; - SkAlignedSTStorage(const SkAlignedSTStorage&) = delete; - SkAlignedSTStorage& operator=(SkAlignedSTStorage&&) = delete; - SkAlignedSTStorage& operator=(const SkAlignedSTStorage&) = delete; - - /** - * Returns void* because this object does not initialize the - * memory. Use placement new for types that require a constructor. - */ - void* get() { return fStorage; } - const void* get() const { return fStorage; } -private: - alignas(T) char fStorage[sizeof(T)*N]; -}; - -using SkAutoFree = std::unique_ptr>; +} // namespace skia_private template constexpr auto SkMakeArrayFromIndexSequence(C c, std::index_sequence is) @@ -424,28 +423,4 @@ template constexpr auto SkMakeArray(C c) return SkMakeArrayFromIndexSequence(c, std::make_index_sequence{}); } -/** - * Trait for identifying types which are relocatable via memcpy, for container optimizations. - * - */ -template -struct sk_has_trivially_relocatable_member : std::false_type {}; - -// Types can declare themselves trivially relocatable with a public -// using sk_is_trivially_relocatable = std::true_type; -template -struct sk_has_trivially_relocatable_member> - : T::sk_is_trivially_relocatable {}; - -// By default, all trivially copyable types are trivially relocatable. -template -struct sk_is_trivially_relocatable - : std::disjunction, sk_has_trivially_relocatable_member ->{}; - -// Here be some dragons: while technically not guaranteed, we count on all sane unique_ptr -// implementations to be trivially relocatable. -template -struct sk_is_trivially_relocatable> : std::true_type {}; - #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkThreadAnnotations.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadAnnotations.h similarity index 100% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkThreadAnnotations.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadAnnotations.h diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h similarity index 69% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h index e14388b3de5bd..18984884c96f7 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h @@ -8,11 +8,14 @@ #ifndef SkThreadID_DEFINED #define SkThreadID_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" + +#include typedef int64_t SkThreadID; -// SkMutex.h uses SkGetThredID in debug only code. +// SkMutex.h uses SkGetThreadID in debug only code. SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID(); const SkThreadID kIllegalThreadID = 0; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h similarity index 71% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h index d788f7b269dad..51ccafeeaf754 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h @@ -7,8 +7,11 @@ #ifndef SkTo_DEFINED #define SkTo_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkTFitsIn.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTFitsIn.h" + +#include +#include template constexpr D SkTo(S s) { return SkASSERT(SkTFitsIn(s)), @@ -21,8 +24,16 @@ template constexpr int16_t SkToS16(S x) { return SkTo(x template constexpr uint16_t SkToU16(S x) { return SkTo(x); } template constexpr int32_t SkToS32(S x) { return SkTo(x); } template constexpr uint32_t SkToU32(S x) { return SkTo(x); } +template constexpr int64_t SkToS64(S x) { return SkTo(x); } +template constexpr uint64_t SkToU64(S x) { return SkTo(x); } template constexpr int SkToInt(S x) { return SkTo(x); } template constexpr unsigned SkToUInt(S x) { return SkTo(x); } template constexpr size_t SkToSizeT(S x) { return SkTo(x); } +/** @return false or true based on the condition +*/ +template static constexpr bool SkToBool(const T& x) { + return (bool)x; +} + #endif // SkTo_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h new file mode 100644 index 0000000000000..736f7897763d5 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h @@ -0,0 +1,33 @@ +// 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 SkTypeTraits_DEFINED +#define SkTypeTraits_DEFINED + +#include +#include + +// Trait for identifying types which are relocatable via memcpy, for container optimizations. +template +struct sk_has_trivially_relocatable_member : std::false_type {}; + +// Types can declare themselves trivially relocatable with a public +// using sk_is_trivially_relocatable = std::true_type; +template +struct sk_has_trivially_relocatable_member> + : T::sk_is_trivially_relocatable {}; + +// By default, all trivially copyable types are trivially relocatable. +template +struct sk_is_trivially_relocatable + : std::disjunction, sk_has_trivially_relocatable_member>{}; + +// Here be some dragons: while technically not guaranteed, we count on all sane unique_ptr +// implementations to be trivially relocatable. +template +struct sk_is_trivially_relocatable> : std::true_type {}; + +template +inline constexpr bool sk_is_trivially_relocatable_v = sk_is_trivially_relocatable::value; + +#endif // SkTypeTraits_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h new file mode 100644 index 0000000000000..51ed8a804defe --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h @@ -0,0 +1,130 @@ +/* + * Copyright 2019 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrVkSecondaryCBDrawContext_DEFINED +#define GrVkSecondaryCBDrawContext_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/core/SkSurfaceProps.h" +#include "include/core/SkTypes.h" + +#include + +class GrBackendSemaphore; +class GrRecordingContext; +struct GrVkDrawableInfo; +namespace skgpu::ganesh { +class Device; +} +class SkCanvas; +class SkDeferredDisplayList; +struct SkImageInfo; +class SkSurfaceCharacterization; +class SkSurfaceProps; + +/** + * This class is a private header that is intended to only be used inside of Chromium. This requires + * Chromium to burrow in and include this specifically since it is not part of skia's public include + * directory. + */ + +/** + * This class is used to draw into an external Vulkan secondary command buffer that is imported + * by the client. The secondary command buffer that gets imported must already have had begin called + * on it with VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT. Thus any draws to the imported + * command buffer cannot require changing the render pass. This requirement means that certain types + * of draws will not be supported when using a GrVkSecondaryCBDrawContext. This includes: + * Draws that require a dst copy for blending will be dropped + * Text draws will be dropped (these may require intermediate uploads of text data) + * Read and Write pixels will not work + * Any other draw that requires a copy will fail (this includes using backdrop filter with save + * layer). + * Stenciling is also disabled, but that should not restrict any actual draws from working. + * + * While using a GrVkSecondaryCBDrawContext, the client can also draw into normal SkSurfaces and + * then draw those SkSufaces (as SkImages) into the GrVkSecondaryCBDrawContext. If any of the + * previously mentioned unsupported draws are needed by the client, they can draw them into an + * offscreen surface, and then draw that into the GrVkSecondaryCBDrawContext. + * + * After all drawing to the GrVkSecondaryCBDrawContext has been done, the client must call flush() + * on the GrVkSecondaryCBDrawContext to actually fill in the secondary VkCommandBuffer with the + * draws. + * + * Additionally, the client must keep the GrVkSecondaryCBDrawContext alive until the secondary + * VkCommandBuffer has been submitted and all work finished on the GPU. Before deleting the + * GrVkSecondaryCBDrawContext, the client must call releaseResources() so that Skia can cleanup + * any internal objects that were created for the draws into the secondary command buffer. + */ +class SK_SPI GrVkSecondaryCBDrawContext : public SkRefCnt { +public: + static sk_sp Make(GrRecordingContext*, + const SkImageInfo&, + const GrVkDrawableInfo&, + const SkSurfaceProps* props); + + ~GrVkSecondaryCBDrawContext() override; + + SkCanvas* getCanvas(); + + // Records all the draws to the imported secondary command buffer and sets any dependent + // offscreen draws to the GPU. + void flush(); + + /** Inserts a list of GPU semaphores that Skia will have the driver wait on before executing + commands for this secondary CB. The wait semaphores will get added to the VkCommandBuffer + owned by this GrContext when flush() is called, and not the command buffer which the + Secondary CB is from. This will guarantee that the driver waits on the semaphores before + the secondary command buffer gets executed. If this call returns false, then the GPU + back end will not wait on any passed in semaphores, and the client will still own the + semaphores, regardless of the value of deleteSemaphoresAfterWait. + + If deleteSemaphoresAfterWait is false then Skia will not delete the semaphores. In this case + it is the client's responsibility to not destroy or attempt to reuse the semaphores until it + knows that Skia has finished waiting on them. This can be done by using finishedProcs + on flush calls. + + @param numSemaphores size of waitSemaphores array + @param waitSemaphores array of semaphore containers + @paramm deleteSemaphoresAfterWait who owns and should delete the semaphores + @return true if GPU is waiting on semaphores + */ + bool wait(int numSemaphores, + const GrBackendSemaphore waitSemaphores[], + bool deleteSemaphoresAfterWait = true); + + // This call will release all resources held by the draw context. The client must call + // releaseResources() before deleting the drawing context. However, the resources also include + // any Vulkan resources that were created and used for draws. Therefore the client must only + // call releaseResources() after submitting the secondary command buffer, and waiting for it to + // finish on the GPU. If it is called earlier then some vulkan objects may be deleted while they + // are still in use by the GPU. + void releaseResources(); + + const SkSurfaceProps& props() const { return fProps; } + + // TODO: Fill out these calls to support DDL + bool characterize(SkSurfaceCharacterization* characterization) const; + +#ifndef SK_DDL_IS_UNIQUE_POINTER + bool draw(sk_sp deferredDisplayList); +#else + bool draw(const SkDeferredDisplayList* deferredDisplayList); +#endif + + bool isCompatible(const SkSurfaceCharacterization& characterization) const; + +private: + explicit GrVkSecondaryCBDrawContext(sk_sp, const SkSurfaceProps*); + + sk_sp fDevice; + std::unique_ptr fCachedCanvas; + const SkSurfaceProps fProps; + + using INHERITED = SkRefCnt; +}; + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h index 55568b9af75a9..962d183b2d979 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h @@ -13,6 +13,7 @@ #include "include/core/SkData.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTypeface.h" #include "include/utils/SkNoDrawCanvas.h" struct SkPackedGlyphID; @@ -21,7 +22,6 @@ class SkStrikeCache; class SkStrikeClientImpl; class SkStrikeServer; class SkStrikeServerImpl; -class SkTypeface; namespace sktext::gpu { class Slug; } using SkDiscardableHandleId = uint32_t; @@ -62,9 +62,6 @@ class SkStrikeServer { bool DFTSupport, bool DFTPerspSupport = true); - // Serializes the typeface to be transmitted using this server. - SK_SPI sk_sp serializeTypeface(SkTypeface*); - // Serializes the strike data captured using a canvas returned by ::makeAnalysisCanvas. Any // handles locked using the DiscardableHandleManager will be assumed to be // unlocked after this call. @@ -128,10 +125,6 @@ class SkStrikeClient { SkStrikeCache* strikeCache = nullptr); SK_SPI ~SkStrikeClient(); - // Deserializes the typeface previously serialized using the SkStrikeServer. Returns null if the - // data is invalid. - SK_SPI sk_sp deserializeTypeface(const void* data, size_t length); - // Deserializes the strike data from a SkStrikeServer. All messages generated // from a server when serializing the ops must be deserialized before the op // is rasterized. @@ -142,9 +135,12 @@ class SkStrikeClient { // corresponding typefaceID on the GPU. SK_SPI bool translateTypefaceID(SkAutoDescriptor* descriptor) const; + // Testing helpers + sk_sp retrieveTypefaceUsingServerIDForTest(SkTypefaceID) const; + // Given a buffer, unflatten into a slug making sure to do the typefaceID translation from // renderer to GPU. Returns nullptr if there was a problem. - sk_sp deserializeSlug(const void* data, size_t size) const; + sk_sp deserializeSlugForTest(const void* data, size_t size) const; private: std::unique_ptr fImpl; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h new file mode 100644 index 0000000000000..ade4d71aa7497 --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h @@ -0,0 +1,70 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkDiscardableMemory_DEFINED +#define SkDiscardableMemory_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +/** + * Interface for discardable memory. Implementation is provided by the + * embedder. + */ +class SK_SPI SkDiscardableMemory { +public: + /** + * Factory method that creates, initializes and locks an SkDiscardableMemory + * object. If either of these steps fails, a nullptr pointer will be returned. + */ + static SkDiscardableMemory* Create(size_t bytes); + + /** + * Factory class that creates, initializes and locks an SkDiscardableMemory + * object. If either of these steps fails, a nullptr pointer will be returned. + */ + class Factory : public SkRefCnt { + public: + virtual SkDiscardableMemory* create(size_t bytes) = 0; + private: + using INHERITED = SkRefCnt; + }; + + /** Must not be called while locked. + */ + virtual ~SkDiscardableMemory() {} + + /** + * Locks the memory, prevent it from being discarded. Once locked. you may + * obtain a pointer to that memory using the data() method. + * + * lock() may return false, indicating that the underlying memory was + * discarded and that the lock failed. + * + * Nested calls to lock are not allowed. + */ + virtual bool SK_WARN_UNUSED_RESULT lock() = 0; + + /** + * Returns the current pointer for the discardable memory. This call is ONLY + * valid when the discardable memory object is locked. + */ + virtual void* data() = 0; + + /** + * Unlock the memory so that it can be purged by the system. Must be called + * after every successful lock call. + */ + virtual void unlock() = 0; + +protected: + SkDiscardableMemory() = default; + SkDiscardableMemory(const SkDiscardableMemory&) = delete; + SkDiscardableMemory& operator=(const SkDiscardableMemory&) = delete; +}; + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h index 0f4d9773db776..6775af0fc6966 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h @@ -21,14 +21,6 @@ class SkStrikeClient; class SkWriteBuffer; namespace sktext::gpu { - -// You can use Slug to simulate drawTextBlob by defining the following at compile time. -// SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG -// You can use Slug serialization to simulate drawTextBlob by defining the following: -// SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE -// For Skia, add this to your args.gn file. -// extra_cflags = ["-D", "SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG"] - // Slug encapsulates an SkTextBlob at a specific origin, using a specific paint. It can be // manipulated using matrix and clip changes to the canvas. If the canvas is transformed, then // the Slug will also transform with smaller glyphs using bi-linear interpolation to render. You @@ -70,7 +62,6 @@ class SK_API Slug : public SkRefCnt { static uint32_t NextUniqueID(); const uint32_t fUniqueID{NextUniqueID()}; }; - } // namespace sktext::gpu #endif // sktext_gpu_Slug_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h index 847e76f23252e..ba7172e005ae5 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h @@ -19,6 +19,7 @@ class GrContextThreadSafeProxy; class GrDirectContext; class GrImageContext; class GrRecordingContext; +enum class SkTextureCompressionType; class GrContext_Base : public SkRefCnt { public: @@ -43,7 +44,7 @@ class GrContext_Base : public SkRefCnt { */ SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const; - SK_API GrBackendFormat compressedBackendFormat(SkImage::CompressionType) const; + SK_API GrBackendFormat compressedBackendFormat(SkTextureCompressionType) const; /** * Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h index 049c07bff63be..26b75344760ee 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h @@ -65,7 +65,7 @@ struct GrD3DTextureResourceSpecHolder { GrD3DSurfaceInfo getSurfaceInfo(uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected) const; + skgpu::Protected isProtected) const; private: GrD3DTextureResourceSpec* fSpec; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h index 5eacf2ea2d263..ffcdc0eaaf49e 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h @@ -20,7 +20,7 @@ struct GrDawnTextureSpec { GrDawnSurfaceInfo GrDawnTextureSpecToSurfaceInfo(const GrDawnTextureSpec& dawnSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h index e951fbd17cfa5..7db777487aecc 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h @@ -103,6 +103,6 @@ struct GrGLTextureSpec { GrGLSurfaceInfo GrGLTextureSpecToSurfaceInfo(const GrGLTextureSpec& glSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h index 5a1a7a32d6241..72fdd4433d065 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h @@ -8,7 +8,7 @@ #ifndef GrImageContext_DEFINED #define GrImageContext_DEFINED -#include "include/private/SingleOwner.h" +#include "include/private/base/SingleOwner.h" #include "include/private/gpu/ganesh/GrContext_Base.h" class GrImageContextPriv; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h index fc72c7fd93bed..59a608dcfca0d 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h @@ -8,18 +8,19 @@ #ifndef GrMockTypesPriv_DEFINED #define GrMockTypesPriv_DEFINED +#include "include/core/SkTextureCompressionType.h" #include "include/gpu/mock/GrMockTypes.h" struct GrMockTextureSpec { GrMockTextureSpec() : fColorType(GrColorType::kUnknown) - , fCompressionType(SkImage::CompressionType::kNone) {} + , fCompressionType(SkTextureCompressionType::kNone) {} GrMockTextureSpec(const GrMockSurfaceInfo& info) : fColorType(info.fColorType) , fCompressionType(info.fCompressionType) {} GrColorType fColorType = GrColorType::kUnknown; - SkImage::CompressionType fCompressionType = SkImage::CompressionType::kNone; + SkTextureCompressionType fCompressionType = SkTextureCompressionType::kNone; }; GrMockSurfaceInfo GrMockTextureSpecToSurfaceInfo(const GrMockTextureSpec& mockSpec, diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h index 550d01760f946..ef65848b5e15a 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h @@ -68,7 +68,7 @@ struct GrMtlTextureSpec { GrMtlSurfaceInfo GrMtlTextureSpecToSurfaceInfo(const GrMtlTextureSpec& mtlSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif // __APPLE__ diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h index b663ff2b193ee..84e2346348503 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h @@ -8,28 +8,21 @@ #ifndef GrTypesPriv_DEFINED #define GrTypesPriv_DEFINED -#include -#include "include/core/SkImage.h" +#include "include/core/SkColor.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPath.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTextureCompressionType.h" #include "include/gpu/GrTypes.h" -#include "include/private/SkImageInfoPriv.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" +#include "include/private/base/SkTypeTraits.h" + +#include class GrBackendFormat; class GrCaps; class GrSurfaceProxy; -// The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might -// not actually be monotonic, depending on how libstdc++ was built. However, this is only currently -// used for idle resource purging so it shouldn't cause a correctness problem. -#if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000) -using GrStdSteadyClock = std::chrono::monotonic_clock; -#else -using GrStdSteadyClock = std::chrono::steady_clock; -#endif - /** * divide, rounding up */ @@ -643,6 +636,7 @@ static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct) { case kRGB_101010x_SkColorType: return GrColorType::kUnknown; case kBGRA_1010102_SkColorType: return GrColorType::kBGRA_1010102; case kBGR_101010x_SkColorType: return GrColorType::kUnknown; + case kBGR_101010x_XR_SkColorType: return GrColorType::kUnknown; case kRGBA_F32_SkColorType: return GrColorType::kRGBA_F32; case kR8G8_unorm_SkColorType: return GrColorType::kRG_88; case kA16_unorm_SkColorType: return GrColorType::kAlpha_16; @@ -924,12 +918,12 @@ static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct) { // In general we try to not mix CompressionType and ColorType, but currently SkImage still requires // an SkColorType even for CompressedTypes so we need some conversion. -static constexpr SkColorType GrCompressionTypeToSkColorType(SkImage::CompressionType compression) { +static constexpr SkColorType GrCompressionTypeToSkColorType(SkTextureCompressionType compression) { switch (compression) { - case SkImage::CompressionType::kNone: return kUnknown_SkColorType; - case SkImage::CompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType; - case SkImage::CompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType; - case SkImage::CompressionType::kBC1_RGBA8_UNORM: return kRGBA_8888_SkColorType; + case SkTextureCompressionType::kNone: return kUnknown_SkColorType; + case SkTextureCompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType; + case SkTextureCompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType; + case SkTextureCompressionType::kBC1_RGBA8_UNORM: return kRGBA_8888_SkColorType; } SkUNREACHABLE; @@ -995,12 +989,12 @@ static constexpr const char* GrColorTypeToStr(GrColorType ct) { SkUNREACHABLE; } -static constexpr const char* GrCompressionTypeToStr(SkImage::CompressionType compression) { +static constexpr const char* GrCompressionTypeToStr(SkTextureCompressionType compression) { switch (compression) { - case SkImage::CompressionType::kNone: return "kNone"; - case SkImage::CompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM"; - case SkImage::CompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM"; - case SkImage::CompressionType::kBC1_RGBA8_UNORM: return "kBC1_RGBA8_UNORM"; + case SkTextureCompressionType::kNone: return "kNone"; + case SkTextureCompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM"; + case SkTextureCompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM"; + case SkTextureCompressionType::kBC1_RGBA8_UNORM: return "kBC1_RGBA8_UNORM"; } SkUNREACHABLE; } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h index a68d467dd8c92..f300a7139632b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h @@ -35,7 +35,7 @@ struct GrVkBackendSurfaceInfo { GrVkImageInfo snapImageInfo(const skgpu::MutableTextureStateRef*) const; - bool isProtected() const { return fImageInfo.fProtected == GrProtected::kYes; } + bool isProtected() const { return fImageInfo.fProtected == skgpu::Protected::kYes; } #if GR_TEST_UTILS bool operator==(const GrVkBackendSurfaceInfo& that) const; #endif @@ -68,6 +68,6 @@ struct GrVkImageSpec { GrVkSurfaceInfo GrVkImageSpecToSurfaceInfo(const GrVkImageSpec& vkSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h new file mode 100644 index 0000000000000..bbf401c95e48d --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h @@ -0,0 +1,38 @@ +/* + * 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 skgpu_graphite_DawnTypesPriv_DEFINED +#define skgpu_graphite_DawnTypesPriv_DEFINED + +#include "include/gpu/graphite/dawn/DawnTypes.h" + +namespace skgpu::graphite { + +struct DawnTextureSpec { + DawnTextureSpec() + : fFormat(wgpu::TextureFormat::Undefined) + , fUsage(wgpu::TextureUsage::None) {} + DawnTextureSpec(const DawnTextureInfo& info) + : fFormat(info.fFormat) + , fUsage(info.fUsage) {} + + bool operator==(const DawnTextureSpec& that) const { + return fUsage == that.fUsage && + fFormat == that.fFormat; + } + + wgpu::TextureFormat fFormat; + wgpu::TextureUsage fUsage; +}; + +DawnTextureInfo DawnTextureSpecToTextureInfo(const DawnTextureSpec& dawnSpec, + uint32_t sampleCount, + Mipmapped mipmapped); + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_DawnTypesPriv_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h similarity index 87% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h index 697628a84d939..bf26aa2a78ad3 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h @@ -5,11 +5,11 @@ * found in the LICENSE file. */ -#ifndef skgpu_graphite_MtlTypesPriv_DEFINED -#define skgpu_graphite_MtlTypesPriv_DEFINED +#ifndef skgpu_graphite_MtlGraphiteTypesPriv_DEFINED +#define skgpu_graphite_MtlGraphiteTypesPriv_DEFINED #include "include/gpu/graphite/GraphiteTypes.h" -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" /////////////////////////////////////////////////////////////////////////////// @@ -67,8 +67,8 @@ struct MtlTextureSpec { MtlTextureInfo MtlTextureSpecToTextureInfo(const MtlTextureSpec& mtlSpec, uint32_t sampleCount, - uint32_t levelCount); + Mipmapped mipmapped); } // namespace skgpu::graphite -#endif // skgpu_graphite_MtlTypesPriv_DEFINED +#endif // skgpu_graphite_MtlGraphiteTypesPriv_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h index e0703d7ef1c86..b4304e3ae8988 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h @@ -19,8 +19,6 @@ struct VulkanTextureSpec { , fImageTiling(VK_IMAGE_TILING_OPTIMAL) , fImageUsageFlags(0) , fSharingMode(VK_SHARING_MODE_EXCLUSIVE) - , fCurrentQueueFamily(VK_QUEUE_FAMILY_IGNORED) - , fImageLayout(VK_IMAGE_LAYOUT_UNDEFINED) , fAspectMask(VK_IMAGE_ASPECT_COLOR_BIT) {} VulkanTextureSpec(const VulkanTextureInfo& info) : fFlags(info.fFlags) @@ -28,8 +26,6 @@ struct VulkanTextureSpec { , fImageTiling(info.fImageTiling) , fImageUsageFlags(info.fImageUsageFlags) , fSharingMode(info.fSharingMode) - , fCurrentQueueFamily(info.fCurrentQueueFamily) - , fImageLayout(info.fImageLayout) , fAspectMask(info.fAspectMask) {} bool operator==(const VulkanTextureSpec& that) const { @@ -38,8 +34,6 @@ struct VulkanTextureSpec { fImageTiling == that.fImageTiling && fImageUsageFlags == that.fImageUsageFlags && fSharingMode == that.fSharingMode && - fCurrentQueueFamily == that.fCurrentQueueFamily && - fImageLayout == that.fImageLayout && fAspectMask == that.fAspectMask; } @@ -48,15 +42,13 @@ struct VulkanTextureSpec { VkImageTiling fImageTiling; VkImageUsageFlags fImageUsageFlags; VkSharingMode fSharingMode; - uint32_t fCurrentQueueFamily; - VkImageLayout fImageLayout; VkImageAspectFlags fAspectMask; // GrVkYcbcrConversionInfo fYcbcrConversionInfo; }; VulkanTextureInfo VulkanTextureSpecToTextureInfo(const VulkanTextureSpec& vkSpec, uint32_t sampleCount, - uint32_t levelCount); + Mipmapped mipmapped); } // namespace skgpu::graphite diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h index c0a9b03bdaa02..ca4bcf108bf45 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h @@ -10,6 +10,8 @@ #include "include/core/SkTypes.h" +// IWYU pragma: begin_exports + #if SKIA_IMPLEMENTATION || !defined(SK_VULKAN) #include "include/third_party/vulkan/vulkan/vulkan_core.h" #else @@ -29,4 +31,6 @@ #endif #endif +// IWYU pragma: end_exports + #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h deleted file mode 100644 index 6b9ebd4727730..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL -#define SKSL_DSL - -#include "include/sksl/DSLBlock.h" -#include "include/sksl/DSLCore.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLFunction.h" -#include "include/sksl/DSLType.h" - -namespace SkSL { - -namespace dsl { - -using Block = DSLBlock; -using Case = DSLCase; -using Expression = DSLExpression; -using Field = DSLField; -using Function = DSLFunction; -using GlobalVar = DSLGlobalVar; -using Layout = DSLLayout; -using Modifiers = DSLModifiers; -using Parameter = DSLParameter; -using Statement = DSLStatement; -using Var = DSLVar; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h deleted file mode 100644 index 959ea2235bacd..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_BLOCK -#define SKSL_DSL_BLOCK - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include - -namespace SkSL { - -class Block; -class SymbolTable; - -namespace dsl { - -class DSLBlock { -public: - template - DSLBlock(Statements... statements) { - fStatements.reserve_back(sizeof...(statements)); - ((void)fStatements.push_back(DSLStatement(statements.release()).release()), ...); - } - - DSLBlock(SkSL::StatementArray statements, std::shared_ptr symbols = nullptr, - Position pos = {}); - - DSLBlock(SkTArray statements, std::shared_ptr symbols = nullptr, - Position pos = {}); - - DSLBlock(DSLBlock&& other) = default; - DSLBlock& operator=(DSLBlock&& other) = default; - - ~DSLBlock() = default; - - void append(DSLStatement stmt); - - std::unique_ptr release(); - -private: - SkSL::StatementArray fStatements; - std::shared_ptr fSymbols; - Position fPosition; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h deleted file mode 100644 index 16780e644a2c9..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_CASE -#define SKSL_DSL_CASE - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include - -namespace SkSL { - -namespace dsl { - -class DSLCase { -public: - // An empty expression means 'default:'. - template - DSLCase(DSLExpression value, Statements... statements) - : fValue(std::move(value)) { - fStatements.reserve_back(sizeof...(statements)); - ((void)fStatements.push_back(DSLStatement(std::move(statements)).release()), ...); - } - - DSLCase(DSLExpression value, SkTArray statements, - Position pos = {}); - - DSLCase(DSLExpression value, SkSL::StatementArray statements, - Position pos = {}); - - DSLCase(DSLCase&&); - - ~DSLCase(); - - DSLCase& operator=(DSLCase&&); - - void append(DSLStatement stmt); - -private: - DSLExpression fValue; - SkSL::StatementArray fStatements; - Position fPosition; - - friend class DSLCore; - - template - friend DSLStatement Switch(DSLExpression value, Cases... cases); -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h deleted file mode 100644 index 72441d4dee15a..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h +++ /dev/null @@ -1,492 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_CORE -#define SKSL_DSL_CORE - -#include "include/private/SkSLDefines.h" -#include "include/private/SkSLProgramKind.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLCase.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/DSLVar.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Compiler; -class ErrorReporter; -struct Program; -struct ProgramSettings; - -namespace dsl { - -class DSLField; -class DSLModifiers; - -// When users import the DSL namespace via `using namespace SkSL::dsl`, we want the SwizzleComponent -// Type enum to come into scope as well, so `Swizzle(var, X, Y, ONE)` can work as expected. -// `namespace SkSL::SwizzleComponent` contains only an `enum Type`; this `using namespace` directive -// shouldn't pollute the SkSL::dsl namespace with anything else. -using namespace SkSL::SwizzleComponent; - -/** - * Starts DSL output on the current thread using the specified compiler. This must be called - * prior to any other DSL functions. - */ -void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment); - -void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind, const SkSL::ProgramSettings& settings); - -/** - * Signals the end of DSL output. This must be called sometime between a call to Start() and the - * termination of the thread. - */ -void End(); - -/** - * Returns all global elements (functions and global variables) as a self-contained Program. The - * optional source string is retained as the program's source. DSL programs do not normally have - * sources, but when a DSL program is produced from parsed program text (as in Parser), it may be - * important to retain it so that any std::string_views derived from it remain valid. - */ -std::unique_ptr ReleaseProgram(std::unique_ptr source = nullptr); - -/** - * Returns the ErrorReporter which will be notified of any errors that occur during DSL calls. The - * default error reporter aborts on any error. - */ -ErrorReporter& GetErrorReporter(); - -/** - * Installs an ErrorReporter which will be notified of any errors that occur during DSL calls. - */ -void SetErrorReporter(ErrorReporter* errorReporter); - -DSLGlobalVar sk_FragColor(); - -DSLGlobalVar sk_FragCoord(); - -DSLExpression sk_Position(); - -/** - * #extension : enable - */ -void AddExtension(std::string_view name, Position pos = {}); - -/** - * break; - */ -DSLStatement Break(Position pos = {}); - -/** - * continue; - */ -DSLStatement Continue(Position pos = {}); - -/** - * Adds a modifiers declaration to the current program. - */ -void Declare(const DSLModifiers& modifiers, Position pos = {}); - -/** - * Creates a local variable declaration statement. - */ -DSLStatement Declare(DSLVar& var, Position pos = {}); - -/** - * Creates a local variable declaration statement containing multiple variables. - */ -DSLStatement Declare(SkTArray& vars, Position pos = {}); - -/** - * Declares a global variable. - */ -void Declare(DSLGlobalVar& var, Position pos = {}); - -/** - * Declares a set of global variables. - */ -void Declare(SkTArray& vars, Position pos = {}); - -/** - * default: statements - */ -template -DSLCase Default(Statements... statements) { - return DSLCase(DSLExpression(), std::move(statements)...); -} - -/** - * discard; - */ -DSLStatement Discard(Position pos = {}); - -/** - * do stmt; while (test); - */ -DSLStatement Do(DSLStatement stmt, DSLExpression test, Position pos = {}); - -/** - * for (initializer; test; next) stmt; - */ -DSLStatement For(DSLStatement initializer, DSLExpression test, DSLExpression next, - DSLStatement stmt, Position pos = {}, ForLoopPositions positions = {}); - -/** - * if (test) ifTrue; [else ifFalse;] - */ -DSLStatement If(DSLExpression test, DSLStatement ifTrue, DSLStatement ifFalse = DSLStatement(), - Position pos = {}); - -DSLGlobalVar InterfaceBlock(const DSLModifiers& modifiers, std::string_view typeName, - SkTArray fields, std::string_view varName = "", - int arraySize = 0, Position pos = {}); - -/** - * return [value]; - */ -DSLStatement Return(DSLExpression value = DSLExpression(), - Position pos = {}); - -/** - * test ? ifTrue : ifFalse - */ -DSLExpression Select(DSLExpression test, DSLExpression ifTrue, DSLExpression ifFalse, - Position = {}); - -DSLStatement StaticIf(DSLExpression test, DSLStatement ifTrue, - DSLStatement ifFalse = DSLStatement(), - Position pos = {}); - -// Internal use only -DSLStatement StaticSwitch(DSLExpression value, SkTArray cases, Position pos = {}); - -/** - * @switch (value) { cases } - */ -template -DSLStatement StaticSwitch(DSLExpression value, Cases... cases) { - SkTArray caseArray; - caseArray.reserve_back(sizeof...(cases)); - (caseArray.push_back(std::move(cases)), ...); - return StaticSwitch(std::move(value), std::move(caseArray), Position{}); -} - -// Internal use only -DSLStatement Switch(DSLExpression value, SkTArray cases, Position pos = {}); - -/** - * switch (value) { cases } - */ -template -DSLStatement Switch(DSLExpression value, Cases... cases) { - SkTArray caseArray; - caseArray.reserve_back(sizeof...(cases)); - (caseArray.push_back(std::move(cases)), ...); - return Switch(std::move(value), std::move(caseArray), Position{}); -} - -/** - * while (test) stmt; - */ -DSLStatement While(DSLExpression test, DSLStatement stmt, - Position pos = {}); - -/** - * expression.xyz1 - */ -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - SkSL::SwizzleComponent::Type c, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - SkSL::SwizzleComponent::Type c, - SkSL::SwizzleComponent::Type d, - Position pos = {}, - Position maskPos = {}); - -/** - * Returns the absolute value of x. If x is a vector, operates componentwise. - */ -DSLExpression Abs(DSLExpression x, Position pos = {}); - -/** - * Returns true if all of the components of boolean vector x are true. - */ -DSLExpression All(DSLExpression x, Position pos = {}); - -/** - * Returns true if any of the components of boolean vector x are true. - */ -DSLExpression Any(DSLExpression x, Position pos = {}); - -/** - * Returns the arctangent of y over x. Operates componentwise on vectors. - */ -DSLExpression Atan(DSLExpression y_over_x, Position pos = {}); -DSLExpression Atan(DSLExpression y, DSLExpression x, Position pos = {}); - -/** - * Returns x rounded towards positive infinity. If x is a vector, operates componentwise. - */ -DSLExpression Ceil(DSLExpression x, Position pos = {}); - -/** - * Returns x clamped to between min and max. If x is a vector, operates componentwise. - */ -DSLExpression Clamp(DSLExpression x, DSLExpression min, DSLExpression max, - Position pos = {}); - -/** - * Returns the cosine of x. If x is a vector, operates componentwise. - */ -DSLExpression Cos(DSLExpression x, Position pos = {}); - -/** - * Returns the cross product of x and y. - */ -DSLExpression Cross(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns x converted from radians to degrees. If x is a vector, operates componentwise. - */ -DSLExpression Degrees(DSLExpression x, Position pos = {}); - -/** - * Returns the distance between x and y. - */ -DSLExpression Distance(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the dot product of x and y. - */ -DSLExpression Dot(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are equal to the corresponding - * components of y. - */ -DSLExpression Equal(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns e^x. If x is a vector, operates componentwise. - */ -DSLExpression Exp(DSLExpression x, Position pos = {}); - -/** - * Returns 2^x. If x is a vector, operates componentwise. - */ -DSLExpression Exp2(DSLExpression x, Position pos = {}); - -/** - * If dot(i, nref) >= 0, returns n, otherwise returns -n. - */ -DSLExpression Faceforward(DSLExpression n, DSLExpression i, DSLExpression nref, - Position pos = {}); - -/** - * Returns x rounded towards negative infinity. If x is a vector, operates componentwise. - */ -DSLExpression Floor(DSLExpression x, Position pos = {}); - -/** - * Returns the fractional part of x. If x is a vector, operates componentwise. - */ -DSLExpression Fract(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are greater than the corresponding - * components of y. - */ -DSLExpression GreaterThan(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are greater than or equal to the - * corresponding components of y. - */ -DSLExpression GreaterThanEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the 1/sqrt(x). If x is a vector, operates componentwise. - */ -DSLExpression Inversesqrt(DSLExpression x, Position pos = {}); - -/** - * Returns the inverse of the matrix x. - */ -DSLExpression Inverse(DSLExpression x, Position pos = {}); - -/** - * Returns the length of the vector x. - */ -DSLExpression Length(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are less than the corresponding - * components of y. - */ -DSLExpression LessThan(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are less than or equal to the - * corresponding components of y. - */ -DSLExpression LessThanEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the log base e of x. If x is a vector, operates componentwise. - */ -DSLExpression Log(DSLExpression x, Position pos = {}); - -/** - * Returns the log base 2 of x. If x is a vector, operates componentwise. - */ -DSLExpression Log2(DSLExpression x, Position pos = {}); - -/** - * Returns the larger (closer to positive infinity) of x and y. If x is a vector, operates - * componentwise. y may be either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Max(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns the smaller (closer to negative infinity) of x and y. If x is a vector, operates - * componentwise. y may be either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Min(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns a linear intepolation between x and y at position a, where a=0 results in x and a=1 - * results in y. If x and y are vectors, operates componentwise. a may be either a vector of the - * same dimensions as x and y, or a scalar. - */ -DSLExpression Mix(DSLExpression x, DSLExpression y, DSLExpression a, - Position pos = {}); - -/** - * Returns x modulo y. If x is a vector, operates componentwise. y may be either a vector of the - * same dimensions as x, or a scalar. - */ -DSLExpression Mod(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns the vector x normalized to a length of 1. - */ -DSLExpression Normalize(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are not equal to the corresponding - * components of y. - */ -DSLExpression NotEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns x raised to the power y. If x is a vector, operates componentwise. y may be either a - * vector of the same dimensions as x, or a scalar. - */ -DSLExpression Pow(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns x converted from degrees to radians. If x is a vector, operates componentwise. - */ -DSLExpression Radians(DSLExpression x, Position pos = {}); - -/** - * Returns i reflected from a surface with normal n. - */ -DSLExpression Reflect(DSLExpression i, DSLExpression n, Position pos = {}); - -/** - * Returns i refracted across a surface with normal n and ratio of indices of refraction eta. - */ -DSLExpression Refract(DSLExpression i, DSLExpression n, DSLExpression eta, - Position pos = {}); - -/** - * Returns x, rounded to the nearest integer. If x is a vector, operates componentwise. - */ -DSLExpression Round(DSLExpression x, Position pos = {}); - -/** - * Returns x clamped to the range [0, 1]. If x is a vector, operates componentwise. - */ -DSLExpression Saturate(DSLExpression x, Position pos = {}); - -/** - * Returns -1, 0, or 1 depending on whether x is negative, zero, or positive, respectively. If x is - * a vector, operates componentwise. - */ -DSLExpression Sign(DSLExpression x, Position pos = {}); - -/** - * Returns the sine of x. If x is a vector, operates componentwise. - */ -DSLExpression Sin(DSLExpression x, Position pos = {}); - -/** - * Returns a smooth interpolation between 0 (at x=edge1) and 1 (at x=edge2). If x is a vector, - * operates componentwise. edge1 and edge2 may either be both vectors of the same dimensions as x or - * scalars. - */ -DSLExpression Smoothstep(DSLExpression edge1, DSLExpression edge2, DSLExpression x, - Position pos = {}); - -/** - * Returns the square root of x. If x is a vector, operates componentwise. - */ -DSLExpression Sqrt(DSLExpression x, Position pos = {}); - -/** - * Returns 0 if x < edge or 1 if x >= edge. If x is a vector, operates componentwise. edge may be - * either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Step(DSLExpression edge, DSLExpression x, Position pos = {}); - -/** - * Returns the tangent of x. If x is a vector, operates componentwise. - */ -DSLExpression Tan(DSLExpression x, Position pos = {}); - -/** - * Returns x converted from premultipled to unpremultiplied alpha. - */ -DSLExpression Unpremul(DSLExpression x, Position pos = {}); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h deleted file mode 100644 index bdb5f2fe24691..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_EXPRESSION -#define SKSL_DSL_EXPRESSION - -#include "include/private/SkTArray.h" -#include "include/sksl/SkSLOperator.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include -#include - -#if defined(__has_cpp_attribute) && __has_cpp_attribute(clang::reinitializes) -#define SK_CLANG_REINITIALIZES [[clang::reinitializes]] -#else -#define SK_CLANG_REINITIALIZES -#endif - -namespace SkSL { - -class Expression; -class ExpressionArray; - -namespace dsl { - -class DSLType; -class DSLVarBase; - -/** - * Represents an expression such as 'cos(x)' or 'a + b'. - */ -class DSLExpression { -public: - DSLExpression(const DSLExpression&) = delete; - - DSLExpression(DSLExpression&&); - - DSLExpression(); - - /** - * Creates an expression representing a literal float. - */ - DSLExpression(float value, Position pos = {}); - - /** - * Creates an expression representing a literal float. - */ - DSLExpression(double value, Position pos = {}) - : DSLExpression((float) value) {} - - /** - * Creates an expression representing a literal int. - */ - DSLExpression(int value, Position pos = {}); - - /** - * Creates an expression representing a literal int. - */ - DSLExpression(int64_t value, Position pos = {}); - - /** - * Creates an expression representing a literal uint. - */ - DSLExpression(unsigned int value, Position pos = {}); - - /** - * Creates an expression representing a literal bool. - */ - DSLExpression(bool value, Position pos = {}); - - /** - * Creates an expression representing a variable reference. - */ - DSLExpression(DSLVarBase& var, Position pos = {}); - - DSLExpression(DSLVarBase&& var, Position pos = {}); - - // If expression is null, returns Poison - explicit DSLExpression(std::unique_ptr expression, Position pos = {}); - - static DSLExpression Poison(Position pos = {}); - - ~DSLExpression(); - - DSLType type() const; - - std::string description() const; - - Position position() const; - - void setPosition(Position pos); - - /** - * Performs assignment, like the '=' operator. - */ - DSLExpression assign(DSLExpression other); - - DSLExpression x(Position pos = {}); - - DSLExpression y(Position pos = {}); - - DSLExpression z(Position pos = {}); - - DSLExpression w(Position pos = {}); - - DSLExpression r(Position pos = {}); - - DSLExpression g(Position pos = {}); - - DSLExpression b(Position pos = {}); - - DSLExpression a(Position pos = {}); - - /** - * Creates an SkSL struct field access expression. - */ - DSLExpression field(std::string_view name, Position pos = {}); - - /** - * Creates an SkSL array index expression. - */ - DSLExpression operator[](DSLExpression index); - - DSLExpression operator()(SkTArray args, Position pos = {}); - - DSLExpression operator()(ExpressionArray args, Position pos = {}); - - /** - * Invokes a prefix operator. - */ - DSLExpression prefix(Operator::Kind op, Position pos); - - /** - * Invokes a postfix operator. - */ - DSLExpression postfix(Operator::Kind op, Position pos); - - /** - * Invokes a binary operator. - */ - DSLExpression binary(Operator::Kind op, DSLExpression right, Position pos); - - /** - * Equivalent to operator[]. - */ - DSLExpression index(DSLExpression index, Position pos); - - /** - * Returns true if this object contains an expression. DSLExpressions which were created with - * the empty constructor or which have already been release()ed do not have a value. - * DSLExpressions created with errors are still considered to have a value (but contain poison). - */ - bool hasValue() const { - return fExpression != nullptr; - } - - /** - * Returns true if this object contains an expression which is not poison. - */ - bool isValid() const; - - SK_CLANG_REINITIALIZES void swap(DSLExpression& other); - - /** - * Invalidates this object and returns the SkSL expression it represents. It is an error to call - * this on an invalid DSLExpression. - */ - std::unique_ptr release(); - -private: - /** - * Calls release if this expression has a value, otherwise returns null. - */ - std::unique_ptr releaseIfPossible(); - - std::unique_ptr fExpression; - - friend DSLExpression SampleChild(int index, DSLExpression coords); - - friend class DSLCore; - friend class DSLVarBase; - friend class DSLWriter; -}; - -DSLExpression operator+(DSLExpression left, DSLExpression right); -DSLExpression operator+(DSLExpression expr); -DSLExpression operator+=(DSLExpression left, DSLExpression right); -DSLExpression operator-(DSLExpression left, DSLExpression right); -DSLExpression operator-(DSLExpression expr); -DSLExpression operator-=(DSLExpression left, DSLExpression right); -DSLExpression operator*(DSLExpression left, DSLExpression right); -DSLExpression operator*=(DSLExpression left, DSLExpression right); -DSLExpression operator/(DSLExpression left, DSLExpression right); -DSLExpression operator/=(DSLExpression left, DSLExpression right); -DSLExpression operator%(DSLExpression left, DSLExpression right); -DSLExpression operator%=(DSLExpression left, DSLExpression right); -DSLExpression operator<<(DSLExpression left, DSLExpression right); -DSLExpression operator<<=(DSLExpression left, DSLExpression right); -DSLExpression operator>>(DSLExpression left, DSLExpression right); -DSLExpression operator>>=(DSLExpression left, DSLExpression right); -DSLExpression operator&&(DSLExpression left, DSLExpression right); -DSLExpression operator||(DSLExpression left, DSLExpression right); -DSLExpression operator&(DSLExpression left, DSLExpression right); -DSLExpression operator&=(DSLExpression left, DSLExpression right); -DSLExpression operator|(DSLExpression left, DSLExpression right); -DSLExpression operator|=(DSLExpression left, DSLExpression right); -DSLExpression operator^(DSLExpression left, DSLExpression right); -DSLExpression operator^=(DSLExpression left, DSLExpression right); -DSLExpression LogicalXor(DSLExpression left, DSLExpression right); -DSLExpression operator,(DSLExpression left, DSLExpression right); -DSLExpression operator==(DSLExpression left, DSLExpression right); -DSLExpression operator!=(DSLExpression left, DSLExpression right); -DSLExpression operator>(DSLExpression left, DSLExpression right); -DSLExpression operator<(DSLExpression left, DSLExpression right); -DSLExpression operator>=(DSLExpression left, DSLExpression right); -DSLExpression operator<=(DSLExpression left, DSLExpression right); -DSLExpression operator!(DSLExpression expr); -DSLExpression operator~(DSLExpression expr); -DSLExpression operator++(DSLExpression expr); -DSLExpression operator++(DSLExpression expr, int); -DSLExpression operator--(DSLExpression expr); -DSLExpression operator--(DSLExpression expr, int); - -} // namespace dsl - -} // namespace SkSL - -template struct sk_is_trivially_relocatable; - -template <> -struct sk_is_trivially_relocatable : std::true_type {}; - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h deleted file mode 100644 index de7b8f1fbcb6d..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_FUNCTION -#define SKSL_DSL_FUNCTION - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLBlock.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/DSLVar.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include - -namespace SkSL { - -class FunctionDeclaration; - -namespace dsl { - -class DSLType; - -class DSLFunction { -public: - template - DSLFunction(const DSLType& returnType, std::string_view name, Parameters&... parameters) - : DSLFunction(DSLModifiers(), returnType, name, parameters...) {} - - template - DSLFunction(const DSLModifiers& modifiers, const DSLType& returnType, std::string_view name, - Parameters&... parameters) { - SkTArray parameterArray; - parameterArray.reserve_back(sizeof...(parameters)); - (parameterArray.push_back(¶meters), ...); - - // We can't have a default parameter and a template parameter pack at the same time, so - // unfortunately we can't capture position from this overload. - this->init(modifiers, returnType, name, std::move(parameterArray), Position()); - } - - DSLFunction(std::string_view name, const DSLModifiers& modifiers, const DSLType& returnType, - SkTArray parameters, Position pos = {}) { - this->init(modifiers, returnType, name, std::move(parameters), pos); - } - - DSLFunction(SkSL::FunctionDeclaration* decl) - : fDecl(decl) {} - - virtual ~DSLFunction() = default; - - template - void define(Stmt... stmts) { - DSLBlock block = DSLBlock(DSLStatement(std::move(stmts))...); - this->define(std::move(block)); - } - - void define(DSLBlock block, Position pos = {}); - - void prototype(); - - /** - * Invokes the function with the given arguments. - */ - template - DSLExpression operator()(Args&&... args) { - ExpressionArray argArray; - argArray.reserve_back(sizeof...(args)); - this->collectArgs(argArray, std::forward(args)...); - return this->call(std::move(argArray)); - } - - /** - * Invokes the function with the given arguments. - */ - DSLExpression call(SkTArray args, Position pos = {}); - - DSLExpression call(ExpressionArray args, Position pos = {}); - -private: - void collectArgs(ExpressionArray& args) {} - - template - void collectArgs(ExpressionArray& args, DSLVar& var, RemainingArgs&&... remaining) { - args.push_back(DSLExpression(var).release()); - collectArgs(args, std::forward(remaining)...); - } - - template - void collectArgs(ExpressionArray& args, DSLExpression expr, RemainingArgs&&... remaining) { - args.push_back(expr.release()); - collectArgs(args, std::forward(remaining)...); - } - - void init(DSLModifiers modifiers, const DSLType& returnType, std::string_view name, - SkTArray params, Position pos); - - SkSL::FunctionDeclaration* fDecl = nullptr; - SkSL::Position fPosition; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h deleted file mode 100644 index a1c963a74eacd..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_LAYOUT -#define SKSL_DSL_LAYOUT - -#include "include/private/SkSLLayout.h" -#include "include/sksl/SkSLPosition.h" - -namespace SkSL { - -namespace dsl { - -class DSLLayout { -public: - DSLLayout() {} - - DSLLayout& originUpperLeft(Position pos = {}) { - return this->flag(SkSL::Layout::kOriginUpperLeft_Flag, "origin_upper_left", pos); - } - - DSLLayout& pushConstant(Position pos = {}) { - return this->flag(SkSL::Layout::kPushConstant_Flag, "push_constant", pos); - } - - DSLLayout& blendSupportAllEquations(Position pos = {}) { - return this->flag(SkSL::Layout::kBlendSupportAllEquations_Flag, - "blend_support_all_equations", pos); - } - - DSLLayout& color(Position pos = {}) { - return this->flag(SkSL::Layout::kColor_Flag, "color", pos); - } - - DSLLayout& location(int location, Position pos = {}) { - return this->intValue(&fSkSLLayout.fLocation, location, SkSL::Layout::kLocation_Flag, - "location", pos); - } - - DSLLayout& offset(int offset, Position pos = {}) { - return this->intValue(&fSkSLLayout.fOffset, offset, SkSL::Layout::kOffset_Flag, "offset", - pos); - } - - DSLLayout& binding(int binding, Position pos = {}) { - return this->intValue(&fSkSLLayout.fBinding, binding, SkSL::Layout::kBinding_Flag, - "binding", pos); - } - - DSLLayout& index(int index, Position pos = {}) { - return this->intValue(&fSkSLLayout.fIndex, index, SkSL::Layout::kIndex_Flag, "index", pos); - } - - DSLLayout& set(int set, Position pos = {}) { - return this->intValue(&fSkSLLayout.fSet, set, SkSL::Layout::kSet_Flag, "set", pos); - } - - DSLLayout& builtin(int builtin, Position pos = {}) { - return this->intValue(&fSkSLLayout.fBuiltin, builtin, SkSL::Layout::kBuiltin_Flag, - "builtin", pos); - } - - DSLLayout& inputAttachmentIndex(int inputAttachmentIndex, - Position pos = {}) { - return this->intValue(&fSkSLLayout.fInputAttachmentIndex, inputAttachmentIndex, - SkSL::Layout::kInputAttachmentIndex_Flag, "input_attachment_index", - pos); - } - -private: - explicit DSLLayout(SkSL::Layout skslLayout) - : fSkSLLayout(skslLayout) {} - - DSLLayout& flag(SkSL::Layout::Flag mask, const char* name, Position pos); - - DSLLayout& intValue(int* target, int value, SkSL::Layout::Flag flag, const char* name, - Position pos); - - SkSL::Layout fSkSLLayout; - - friend class DSLModifiers; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h deleted file mode 100644 index 01fb0623376d8..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_MODIFIERS -#define SKSL_DSL_MODIFIERS - -#include "include/core/SkSpan.h" -#include "include/private/SkSLModifiers.h" -#include "include/sksl/DSLLayout.h" - -namespace SkSL { - -namespace dsl { - -class DSLField; -class DSLType; - -enum Modifier { - kNo_Modifier = SkSL::Modifiers::kNo_Flag, - kConst_Modifier = SkSL::Modifiers::kConst_Flag, - kIn_Modifier = SkSL::Modifiers::kIn_Flag, - kOut_Modifier = SkSL::Modifiers::kOut_Flag, - kInOut_Modifier = SkSL::Modifiers::kIn_Flag | SkSL::Modifiers::kOut_Flag, - kUniform_Modifier = SkSL::Modifiers::kUniform_Flag, - kFlat_Modifier = SkSL::Modifiers::kFlat_Flag, - kNoPerspective_Modifier = SkSL::Modifiers::kNoPerspective_Flag, -}; - -class DSLModifiers { -public: - DSLModifiers(int flags = 0, Position pos = {}) - : DSLModifiers(DSLLayout(), flags, pos) {} - - DSLModifiers(DSLLayout layout, int flags = 0, Position pos = {}) - : fModifiers(layout.fSkSLLayout, flags) - , fPosition(pos) {} - - int& flags() { - return fModifiers.fFlags; - } - - const int& flags() const { - return fModifiers.fFlags; - } - - DSLLayout layout() const { - return DSLLayout(fModifiers.fLayout); - } - -private: - SkSL::Modifiers fModifiers; - Position fPosition; - - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); - friend class DSLCore; - friend class DSLFunction; - friend class DSLType; - friend class DSLWriter; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h deleted file mode 100644 index 391e911d3aac9..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_STATEMENT -#define SKSL_DSL_STATEMENT - -#include "include/core/SkTypes.h" -#include "include/private/SkSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include - -namespace SkSL { - -class Expression; - -namespace dsl { - -class DSLBlock; -class DSLExpression; - -class DSLStatement { -public: - DSLStatement(); - - DSLStatement(DSLExpression expr); - - DSLStatement(DSLBlock block); - - DSLStatement(DSLStatement&&) = default; - - DSLStatement(std::unique_ptr expr); - - DSLStatement(std::unique_ptr stmt, Position pos); - - DSLStatement(std::unique_ptr stmt); - - ~DSLStatement(); - - DSLStatement& operator=(DSLStatement&& other) = default; - - Position position() { - SkASSERT(this->hasValue()); - return fStatement->fPosition; - } - - void setPosition(Position pos) { - SkASSERT(this->hasValue()); - fStatement->fPosition = pos; - } - - bool hasValue() { return fStatement != nullptr; } - - std::unique_ptr release() { - SkASSERT(this->hasValue()); - return std::move(fStatement); - } - -private: - std::unique_ptr releaseIfPossible() { - return std::move(fStatement); - } - - std::unique_ptr fStatement; - - friend class DSLCore; - friend class DSLWriter; - friend DSLStatement operator,(DSLStatement left, DSLStatement right); -}; - -DSLStatement operator,(DSLStatement left, DSLStatement right); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h deleted file mode 100644 index dfd45d1b34280..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_SYMBOLS -#define SKSL_DSL_SYMBOLS - -#include "include/sksl/DSLExpression.h" - -#include -#include - -namespace SkSL { - -class Position; -class SymbolTable; - -namespace dsl { - -class DSLVarBase; - -// This header provides methods for manually managing symbol tables in DSL code. They should not be -// used by normal hand-written DSL code, where we rely on C++ to manage symbols, but are instead -// needed when DSL objects are being constructed programmatically (as in Parser). - -/** - * Pushes a new symbol table onto the symbol table stack. - */ -void PushSymbolTable(); - -/** - * Pops the top symbol table from the stack. As symbol tables are shared pointers, this will only - * destroy the symbol table if it was never attached to anything (e.g. passed into a Block - * constructor). - */ -void PopSymbolTable(); - -/** - * Returns the current symbol table. Outside of SkSL itself, this is an opaque pointer, used only - * for passing it to DSL methods that require it. - */ -std::shared_ptr CurrentSymbolTable(); - -/** - * Returns an expression referring to the named symbol. - */ -DSLExpression Symbol(std::string_view name, Position pos = {}); - -/** - * Adds a variable to the current symbol table. - */ -void AddToSymbolTable(DSLVarBase& var, Position pos = {}); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h deleted file mode 100644 index d15e01b3a3eac..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_TYPE -#define SKSL_DSL_TYPE - -#include "include/core/SkSpan.h" -#include "include/core/SkTypes.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include - -namespace SkSL { - -class Compiler; -class Type; - -namespace dsl { - -class DSLField; -class DSLVarBase; - -enum TypeConstant : uint8_t { - kBool_Type, - kBool2_Type, - kBool3_Type, - kBool4_Type, - kHalf_Type, - kHalf2_Type, - kHalf3_Type, - kHalf4_Type, - kHalf2x2_Type, - kHalf3x2_Type, - kHalf4x2_Type, - kHalf2x3_Type, - kHalf3x3_Type, - kHalf4x3_Type, - kHalf2x4_Type, - kHalf3x4_Type, - kHalf4x4_Type, - kFloat_Type, - kFloat2_Type, - kFloat3_Type, - kFloat4_Type, - kFragmentProcessor_Type, - kFloat2x2_Type, - kFloat3x2_Type, - kFloat4x2_Type, - kFloat2x3_Type, - kFloat3x3_Type, - kFloat4x3_Type, - kFloat2x4_Type, - kFloat3x4_Type, - kFloat4x4_Type, - kInt_Type, - kInt2_Type, - kInt3_Type, - kInt4_Type, - kShader_Type, - kShort_Type, - kShort2_Type, - kShort3_Type, - kShort4_Type, - kUInt_Type, - kUInt2_Type, - kUInt3_Type, - kUInt4_Type, - kUShort_Type, - kUShort2_Type, - kUShort3_Type, - kUShort4_Type, - kVoid_Type, - kPoison_Type, -}; - -class DSLType { -public: - DSLType(TypeConstant tc, Position pos = {}); - - DSLType(const SkSL::Type* type, Position pos = {}); - - DSLType(std::string_view name, Position pos = {}); - - DSLType(std::string_view name, - DSLModifiers* modifiers, - Position pos = {}); - - /** - * Returns true if the SkSL type is non-null. - */ - bool hasValue() const { return fSkSLType != nullptr; } - - /** - * Returns true if this type is a bool. - */ - bool isBoolean() const; - - /** - * Returns true if this is a numeric scalar type. - */ - bool isNumber() const; - - /** - * Returns true if this is a floating-point scalar type (float or half). - */ - bool isFloat() const; - - /** - * Returns true if this is a signed scalar type (int or short). - */ - bool isSigned() const; - - /** - * Returns true if this is an unsigned scalar type (uint or ushort). - */ - bool isUnsigned() const; - - /** - * Returns true if this is a signed or unsigned integer. - */ - bool isInteger() const; - - /** - * Returns true if this is a scalar type. - */ - bool isScalar() const; - - /** - * Returns true if this is a vector type. - */ - bool isVector() const; - - /** - * Returns true if this is a matrix type. - */ - bool isMatrix() const; - - /** - * Returns true if this is a array type. - */ - bool isArray() const; - - /** - * Returns true if this is a struct type. - */ - bool isStruct() const; - - /** - * Returns true if this is a Skia object type (shader, colorFilter, blender). - */ - bool isEffectChild() const; - - template - static DSLExpression Construct(DSLType type, DSLVarBase& var, Args&&... args) { - DSLExpression argArray[] = {var, args...}; - return Construct(type, SkSpan(argArray)); - } - - template - static DSLExpression Construct(DSLType type, DSLExpression expr, Args&&... args) { - DSLExpression argArray[] = {std::move(expr), std::move(args)...}; - return Construct(type, SkSpan(argArray)); - } - - static DSLExpression Construct(DSLType type, SkSpan argArray); - -private: - const SkSL::Type& skslType() const { - SkASSERT(fSkSLType); - return *fSkSLType; - } - - const SkSL::Type* fSkSLType = nullptr; - - friend DSLType Array(const DSLType& base, int count, Position pos); - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); - friend DSLType UnsizedArray(const DSLType& base, Position pos); - friend class DSLCore; - friend class DSLFunction; - friend class DSLVarBase; - friend class DSLWriter; - friend class SkSL::Compiler; -}; - -#define TYPE(T) \ - template \ - DSLExpression T(Args&&... args) { \ - return DSLType::Construct(k ## T ## _Type, std::forward(args)...); \ - } - -#define VECTOR_TYPE(T) \ - TYPE(T) \ - TYPE(T ## 2) \ - TYPE(T ## 3) \ - TYPE(T ## 4) - -#define MATRIX_TYPE(T) \ - TYPE(T ## 2x2) \ - TYPE(T ## 3x2) \ - TYPE(T ## 4x2) \ - TYPE(T ## 2x3) \ - TYPE(T ## 3x3) \ - TYPE(T ## 4x3) \ - TYPE(T ## 2x4) \ - TYPE(T ## 3x4) \ - TYPE(T ## 4x4) - -VECTOR_TYPE(Bool) -VECTOR_TYPE(Float) -VECTOR_TYPE(Half) -VECTOR_TYPE(Int) -VECTOR_TYPE(UInt) -VECTOR_TYPE(Short) -VECTOR_TYPE(UShort) - -MATRIX_TYPE(Float) -MATRIX_TYPE(Half) - -#undef TYPE -#undef VECTOR_TYPE -#undef MATRIX_TYPE - -DSLType Array(const DSLType& base, int count, Position pos = {}); - -DSLType UnsizedArray(const DSLType& base, Position pos = {}); - -class DSLField { -public: - DSLField(const DSLType type, std::string_view name, - Position pos = {}) - : DSLField(DSLModifiers(), type, name, pos) {} - - DSLField(const DSLModifiers& modifiers, const DSLType type, std::string_view name, - Position pos = {}) - : fModifiers(modifiers) - , fType(type) - , fName(name) - , fPosition(pos) {} - -private: - DSLModifiers fModifiers; - const DSLType fType; - std::string_view fName; - Position fPosition; - - friend class DSLCore; - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); -}; - -DSLType Struct(std::string_view name, SkSpan fields, - Position pos = {}); - -template -DSLType Struct(std::string_view name, Field... fields) { - DSLField fieldTypes[] = {std::move(fields)...}; - return Struct(name, SkSpan(fieldTypes), Position()); -} - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h deleted file mode 100644 index f052a525e355d..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_VAR -#define SKSL_DSL_VAR - -#include "include/private/SkSLStatement.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/DSLType.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Expression; -class ExpressionArray; -class Variable; -enum class VariableStorage : int8_t; - -namespace dsl { - -class DSLVarBase { -public: - /** - * Constructs a new variable with the specified type and name. - */ - DSLVarBase(VariableStorage storage, DSLType type, std::string_view name, - DSLExpression initialValue, Position pos, Position namePos); - - DSLVarBase(VariableStorage storage, const DSLModifiers& modifiers, DSLType type, - std::string_view name, DSLExpression initialValue, Position pos, Position namePos); - - DSLVarBase(DSLVarBase&&) = default; - - std::string_view name() const { - return fName; - } - - const DSLModifiers& modifiers() const { - return fModifiers; - } - - VariableStorage storage() const { - return fStorage; - } - - DSLExpression x() { - return DSLExpression(*this).x(); - } - - DSLExpression y() { - return DSLExpression(*this).y(); - } - - DSLExpression z() { - return DSLExpression(*this).z(); - } - - DSLExpression w() { - return DSLExpression(*this).w(); - } - - DSLExpression r() { - return DSLExpression(*this).r(); - } - - DSLExpression g() { - return DSLExpression(*this).g(); - } - - DSLExpression b() { - return DSLExpression(*this).b(); - } - - DSLExpression a() { - return DSLExpression(*this).a(); - } - - DSLExpression field(std::string_view name) { - return DSLExpression(*this).field(name); - } - - DSLExpression operator[](DSLExpression&& index); - - DSLExpression operator++() { - return ++DSLExpression(*this); - } - - DSLExpression operator++(int) { - return DSLExpression(*this)++; - } - - DSLExpression operator--() { - return --DSLExpression(*this); - } - - DSLExpression operator--(int) { - return DSLExpression(*this)--; - } - - template DSLExpression assign(T&& param) { - return this->assignExpression(DSLExpression(std::forward(param))); - } - -protected: - /** - * Creates an empty, unpopulated var. Can be replaced with a real var later via `swap`. - */ - DSLVarBase(VariableStorage storage) : fType(kVoid_Type), fStorage(storage) {} - - DSLExpression assignExpression(DSLExpression other); - - void swap(DSLVarBase& other); - - DSLModifiers fModifiers; - // We only need to keep track of the type here so that we can create the SkSL::Variable. For - // predefined variables this field is unnecessary, so we don't bother tracking it and just set - // it to kVoid; in other words, you shouldn't generally be relying on this field to be correct. - // If you need to determine the variable's type, look at DSLWriter::Var(...)->type() instead. - DSLType fType; - std::unique_ptr fDeclaration; - SkSL::Variable* fVar = nullptr; - Position fNamePosition; - std::string_view fName; - DSLExpression fInitialValue; - Position fPosition; - VariableStorage fStorage; - bool fInitialized = false; - - friend class DSLCore; - friend class DSLFunction; - friend class DSLWriter; -}; - -/** - * A local variable. - */ -class DSLVar : public DSLVarBase { -public: - DSLVar(); - - DSLVar(DSLType type, std::string_view name, DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLVar(const DSLModifiers& modifiers, DSLType type, std::string_view name, - DSLExpression initialValue = DSLExpression(), Position pos = {}, Position namePos = {}); - - DSLVar(DSLVar&&) = default; - - void swap(DSLVar& other); - -private: - using INHERITED = DSLVarBase; -}; - -/** - * A global variable. - */ -class DSLGlobalVar : public DSLVarBase { -public: - DSLGlobalVar(); - - DSLGlobalVar(DSLType type, std::string_view name, DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLGlobalVar(const DSLModifiers& modifiers, DSLType type, std::string_view name, - DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLGlobalVar(const char* name); - - DSLGlobalVar(DSLGlobalVar&&) = default; - - void swap(DSLGlobalVar& other); - - /** - * Implements the following method calls: - * half4 shader::eval(float2 coords); - * half4 colorFilter::eval(half4 input); - */ - DSLExpression eval(DSLExpression x, Position pos = {}); - - /** - * Implements the following method call: - * half4 blender::eval(half4 src, half4 dst); - */ - DSLExpression eval(DSLExpression x, DSLExpression y, Position pos = {}); - -private: - DSLExpression eval(ExpressionArray args, Position pos); - - std::unique_ptr methodCall(std::string_view methodName, Position pos); - - using INHERITED = DSLVarBase; -}; - -/** - * A function parameter. - */ -class DSLParameter : public DSLVarBase { -public: - DSLParameter(); - - DSLParameter(DSLType type, std::string_view name, Position pos = {}, Position namePos = {}); - - DSLParameter(const DSLModifiers& modifiers, DSLType type, std::string_view name, - Position pos = {}, Position namePos = {}); - - DSLParameter(DSLParameter&&) = default; - - void swap(DSLParameter& other); - -private: - using INHERITED = DSLVarBase; -}; - -} // namespace dsl - -} // namespace SkSL - - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h deleted file mode 100644 index 4abf4631b8b17..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_ERROR_REPORTER -#define SKSL_ERROR_REPORTER - -#include "include/core/SkTypes.h" - -#include - -namespace SkSL { - -class Position; - -/** - * Class which is notified in the event of an error. - */ -class ErrorReporter { -public: - ErrorReporter() {} - - virtual ~ErrorReporter() {} - - void error(Position position, std::string_view msg); - - std::string_view source() const { return fSource; } - - void setSource(std::string_view source) { fSource = source; } - - int errorCount() const { - return fErrorCount; - } - - void resetErrorCount() { - fErrorCount = 0; - } - -protected: - /** - * Called when an error is reported. - */ - virtual void handleError(std::string_view msg, Position position) = 0; - -private: - Position position(int offset) const; - - std::string_view fSource; - int fErrorCount = 0; -}; - -/** - * Error reporter for tests that need an SkSL context; aborts immediately if an error is reported. - */ -class TestingOnly_AbortErrorReporter : public ErrorReporter { -public: - void handleError(std::string_view msg, Position pos) override; -}; - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h deleted file mode 100644 index 1e47dce618856..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_OPERATOR -#define SKSL_OPERATOR - -#include -#include - -namespace SkSL { - -class Context; -class Type; - -enum class OperatorKind : uint8_t { - PLUS, - MINUS, - STAR, - SLASH, - PERCENT, - SHL, - SHR, - LOGICALNOT, - LOGICALAND, - LOGICALOR, - LOGICALXOR, - BITWISENOT, - BITWISEAND, - BITWISEOR, - BITWISEXOR, - EQ, - EQEQ, - NEQ, - LT, - GT, - LTEQ, - GTEQ, - PLUSEQ, - MINUSEQ, - STAREQ, - SLASHEQ, - PERCENTEQ, - SHLEQ, - SHREQ, - BITWISEANDEQ, - BITWISEOREQ, - BITWISEXOREQ, - PLUSPLUS, - MINUSMINUS, - COMMA -}; - -enum class OperatorPrecedence : uint8_t { - kParentheses = 1, - kPostfix = 2, - kPrefix = 3, - kMultiplicative = 4, - kAdditive = 5, - kShift = 6, - kRelational = 7, - kEquality = 8, - kBitwiseAnd = 9, - kBitwiseXor = 10, - kBitwiseOr = 11, - kLogicalAnd = 12, - kLogicalXor = 13, - kLogicalOr = 14, - kTernary = 15, - kAssignment = 16, - kSequence = 17, - kTopLevel = kSequence -}; - -class Operator { -public: - using Kind = OperatorKind; - - Operator(Kind op) : fKind(op) {} - - Kind kind() const { return fKind; } - - bool isEquality() const { - return fKind == Kind::EQEQ || fKind == Kind::NEQ; - } - - OperatorPrecedence getBinaryPrecedence() const; - - // Returns the operator name surrounded by the expected whitespace for a tidy binary expression. - const char* operatorName() const; - - // Returns the operator name without any surrounding whitespace. - std::string_view tightOperatorName() const; - - // Returns true if op is '=' or any compound assignment operator ('+=', '-=', etc.) - bool isAssignment() const; - - // Given a compound assignment operator, returns the non-assignment version of the operator - // (e.g. '+=' becomes '+') - Operator removeAssignment() const; - - /** - * Defines the set of relational (comparison) operators: - * < <= > >= - */ - bool isRelational() const; - - /** - * Defines the set of operators which are only valid on integral types: - * << <<= >> >>= & &= | |= ^ ^= % %= - */ - bool isOnlyValidForIntegralTypes() const; - - /** - * Defines the set of operators which perform vector/matrix math. - * + += - -= * *= / /= % %= << <<= >> >>= & &= | |= ^ ^= - */ - bool isValidForMatrixOrVector() const; - - /* - * Defines the set of operators allowed by The OpenGL ES Shading Language 1.00, Section 5.1. - * The set of illegal (reserved) operators are the ones that only make sense with integral - * types. This is not a coincidence: It's because ES2 doesn't require 'int' to be anything but - * syntactic sugar for floats with truncation after each operation. - */ - bool isAllowedInStrictES2Mode() const { - return !this->isOnlyValidForIntegralTypes(); - } - - /** - * Determines the operand and result types of a binary expression. Returns true if the - * expression is legal, false otherwise. If false, the values of the out parameters are - * undefined. - */ - bool determineBinaryType(const Context& context, - const Type& left, - const Type& right, - const Type** outLeftType, - const Type** outRightType, - const Type** outResultType) const; - -private: - bool isOperator() const; - bool isMatrixMultiply(const Type& left, const Type& right) const; - - Kind fKind; -}; - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h deleted file mode 100644 index 5f8e80a607b8f..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_POSITION -#define SKSL_POSITION - -#include "include/core/SkTypes.h" - -#include -#include - -namespace SkSL { - -class Position { -public: - Position() - : fStartOffset(-1) - , fLength(0) {} - - static Position Range(int startOffset, int endOffset) { - SkASSERT(startOffset <= endOffset); - SkASSERT(startOffset <= 0xFFFFFF); - int length = endOffset - startOffset; - Position result; - result.fStartOffset = startOffset; - result.fLength = length <= 0xFF ? length : 0xFF; - return result; - } - - bool valid() const { - return fStartOffset != -1; - } - - int line(std::string_view source) const; - - int startOffset() const { - SkASSERT(this->valid()); - return fStartOffset; - } - - int endOffset() const { - SkASSERT(this->valid()); - return fStartOffset + fLength; - } - - // Returns the position from this through, and including the entirety of, end. - Position rangeThrough(Position end) const { - if (fStartOffset == -1 || end.fStartOffset == -1) { - return *this; - } - SkASSERTF(this->startOffset() <= end.startOffset() && this->endOffset() <= end.endOffset(), - "Invalid range: (%d-%d) - (%d-%d)\n", this->startOffset(), this->endOffset(), - end.startOffset(), end.endOffset()); - return Range(this->startOffset(), end.endOffset()); - } - - // Returns a position representing the character immediately after this position - Position after() const { - int endOffset = this->endOffset(); - return Range(endOffset, endOffset + 1); - } - - bool operator==(const Position& other) const { - return fStartOffset == other.fStartOffset && fLength == other.fLength; - } - - bool operator!=(const Position& other) const { - return !(*this == other); - } - - bool operator>(const Position& other) const { - return fStartOffset > other.fStartOffset; - } - - bool operator>=(const Position& other) const { - return fStartOffset >= other.fStartOffset; - } - - bool operator<(const Position& other) const { - return fStartOffset < other.fStartOffset; - } - - bool operator<=(const Position& other) const { - return fStartOffset <= other.fStartOffset; - } - -private: - int32_t fStartOffset : 24; - uint32_t fLength : 8; -}; - -struct ForLoopPositions { - Position initPosition = Position(); - Position conditionPosition = Position(); - Position nextPosition = Position(); -}; - -} // namespace SkSL - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h index d2c8b8b23b964..536691875e4f4 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h @@ -14,7 +14,7 @@ #include "include/core/SkMatrix.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" // NOTE -- This entire header / impl is deprecated, and will be removed from Skia soon. // diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h index afdf91e5ebcb8..d387fb24ca6bc 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h @@ -14,12 +14,15 @@ #include "include/core/SkPath.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" +#include #include class SkStream; -class SkTypeface; +class SkStreamAsset; +struct SkFontArguments; class SK_API SkCustomTypefaceBuilder { public: @@ -33,6 +36,9 @@ class SK_API SkCustomTypefaceBuilder { sk_sp detach(); + static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('u','s','e','r'); + static sk_sp MakeFromStream(std::unique_ptr, const SkFontArguments&); + private: struct GlyphRec { // logical union diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h index 5ef7a103a98af..87c6916b39f09 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h @@ -9,17 +9,14 @@ #ifndef SkNWayCanvas_DEFINED #define SkNWayCanvas_DEFINED -#include "include/core/SkBlendMode.h" -#include "include/core/SkCanvas.h" #include "include/core/SkCanvasVirtualEnforcer.h" -#include "include/core/SkClipOp.h" #include "include/core/SkColor.h" #include "include/core/SkM44.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSamplingOptions.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" #include "include/utils/SkNoDrawCanvas.h" #include @@ -28,6 +25,7 @@ namespace sktext { class GlyphRunList; } +class SkCanvas; class SkData; class SkDrawable; class SkImage; @@ -40,12 +38,14 @@ class SkRegion; class SkShader; class SkTextBlob; class SkVertices; +enum class SkBlendMode; +enum class SkClipOp; struct SkDrawShadowRec; struct SkPoint; struct SkRSXform; struct SkRect; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) namespace sktext::gpu { class Slug; } @@ -77,7 +77,7 @@ class SK_API SkNWayCanvas : public SkCanvasVirtualEnforcer { void onDrawGlyphRunList(const sktext::GlyphRunList&, const SkPaint&) override; void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) override; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) void onDrawSlug(const sktext::gpu::Slug* slug) override; #endif void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h index a03bfdb54108a..0b686e5edc5af 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h @@ -39,14 +39,15 @@ class SK_API SkOrderedFontMgr : public SkFontMgr { protected: int onCountFamilies() const override; void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onCreateStyleSet(int index)const override; + sk_sp onCreateStyleSet(int index)const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkTypeface* onMatchFamilyStyle(const char familyName[], const SkFontStyle&) const override; - SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const override; + sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle&) const override; + sk_sp onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const override; // Note: all of these always return null sk_sp onMakeFromData(sk_sp, int ttcIndex) const override; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h index 5ce3c26f1dc74..9a836bc7c2551 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h @@ -8,7 +8,6 @@ #ifndef SkPaintFilterCanvas_DEFINED #define SkPaintFilterCanvas_DEFINED -#include "include/core/SkBlendMode.h" #include "include/core/SkCanvas.h" #include "include/core/SkCanvasVirtualEnforcer.h" #include "include/core/SkColor.h" @@ -18,7 +17,7 @@ #include "include/core/SkScalar.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" #include "include/utils/SkNWayCanvas.h" #include @@ -42,6 +41,7 @@ class SkSurface; class SkSurfaceProps; class SkTextBlob; class SkVertices; +enum class SkBlendMode; struct SkDrawShadowRec; struct SkPoint; struct SkRSXform; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h index f1c81b2f28d3c..acd0ef2305c03 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h @@ -19,7 +19,7 @@ class SK_API SkParsePath { static bool FromSVGString(const char str[], SkPath*); enum class PathEncoding { Absolute, Relative }; - static void ToSVGString(const SkPath&, SkString*, PathEncoding = PathEncoding::Absolute); + static SkString ToSVGString(const SkPath&, PathEncoding = PathEncoding::Absolute); }; #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h deleted file mode 100644 index ba40732b9cf7a..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2006 The Android Open Source Project - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkRandom_DEFINED -#define SkRandom_DEFINED - -#include "include/core/SkScalar.h" -#include "include/private/SkFixed.h" -#include "include/private/SkFloatBits.h" - -/** \class SkRandom - - Utility class that implements pseudo random 32bit numbers using Marsaglia's - multiply-with-carry "mother of all" algorithm. Unlike rand(), this class holds - its own state, so that multiple instances can be used with no side-effects. - - Has a large period and all bits are well-randomized. - */ -class SkRandom { -public: - SkRandom() { init(0); } - SkRandom(uint32_t seed) { init(seed); } - SkRandom(const SkRandom& rand) : fK(rand.fK), fJ(rand.fJ) {} - - SkRandom& operator=(const SkRandom& rand) { - fK = rand.fK; - fJ = rand.fJ; - - return *this; - } - - /** Return the next pseudo random number as an unsigned 32bit value. - */ - uint32_t nextU() { - fK = kKMul*(fK & 0xffff) + (fK >> 16); - fJ = kJMul*(fJ & 0xffff) + (fJ >> 16); - return (((fK << 16) | (fK >> 16)) + fJ); - } - - /** Return the next pseudo random number as a signed 32bit value. - */ - int32_t nextS() { return (int32_t)this->nextU(); } - - /** - * Returns value [0...1) as an IEEE float - */ - float nextF() { - int floatint = 0x3f800000 | (int)(this->nextU() >> 9); - float f = SkBits2Float(floatint) - 1.0f; - return f; - } - - /** - * Returns value [min...max) as a float - */ - float nextRangeF(float min, float max) { - return min + this->nextF() * (max - min); - } - - /** Return the next pseudo random number, as an unsigned value of - at most bitCount bits. - @param bitCount The maximum number of bits to be returned - */ - uint32_t nextBits(unsigned bitCount) { - SkASSERT(bitCount > 0 && bitCount <= 32); - return this->nextU() >> (32 - bitCount); - } - - /** Return the next pseudo random unsigned number, mapped to lie within - [min, max] inclusive. - */ - uint32_t nextRangeU(uint32_t min, uint32_t max) { - SkASSERT(min <= max); - uint32_t range = max - min + 1; - if (0 == range) { - return this->nextU(); - } else { - return min + this->nextU() % range; - } - } - - /** Return the next pseudo random unsigned number, mapped to lie within - [0, count). - */ - uint32_t nextULessThan(uint32_t count) { - SkASSERT(count > 0); - return this->nextRangeU(0, count - 1); - } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [0..SK_Scalar1). - */ - SkScalar nextUScalar1() { return SkFixedToScalar(this->nextUFixed1()); } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [min..max). - */ - SkScalar nextRangeScalar(SkScalar min, SkScalar max) { - return this->nextUScalar1() * (max - min) + min; - } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [-SK_Scalar1..SK_Scalar1). - */ - SkScalar nextSScalar1() { return SkFixedToScalar(this->nextSFixed1()); } - - /** Return the next pseudo random number as a bool. - */ - bool nextBool() { return this->nextU() >= 0x80000000; } - - /** A biased version of nextBool(). - */ - bool nextBiasedBool(SkScalar fractionTrue) { - SkASSERT(fractionTrue >= 0 && fractionTrue <= SK_Scalar1); - return this->nextUScalar1() <= fractionTrue; - } - - /** Reset the random object. - */ - void setSeed(uint32_t seed) { init(seed); } - -private: - // Initialize state variables with LCG. - // We must ensure that both J and K are non-zero, otherwise the - // multiply-with-carry step will forevermore return zero. - void init(uint32_t seed) { - fK = NextLCG(seed); - if (0 == fK) { - fK = NextLCG(fK); - } - fJ = NextLCG(fK); - if (0 == fJ) { - fJ = NextLCG(fJ); - } - SkASSERT(0 != fK && 0 != fJ); - } - static uint32_t NextLCG(uint32_t seed) { return kMul*seed + kAdd; } - - /** Return the next pseudo random number expressed as an unsigned SkFixed - in the range [0..SK_Fixed1). - */ - SkFixed nextUFixed1() { return this->nextU() >> 16; } - - /** Return the next pseudo random number expressed as a signed SkFixed - in the range [-SK_Fixed1..SK_Fixed1). - */ - SkFixed nextSFixed1() { return this->nextS() >> 15; } - - // See "Numerical Recipes in C", 1992 page 284 for these constants - // For the LCG that sets the initial state from a seed - enum { - kMul = 1664525, - kAdd = 1013904223 - }; - // Constants for the multiply-with-carry steps - enum { - kKMul = 30345, - kJMul = 18000, - }; - - uint32_t fK; - uint32_t fJ; -}; - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h index 2ee56934ade6d..322549b38f7ed 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h @@ -51,6 +51,17 @@ SKCMS_API float skcms_TransferFunction_eval (const skcms_TransferFunction*, flo SKCMS_API bool skcms_TransferFunction_invert(const skcms_TransferFunction*, skcms_TransferFunction*); +typedef enum skcms_TFType { + skcms_TFType_Invalid, + skcms_TFType_sRGBish, + skcms_TFType_PQish, + skcms_TFType_HLGish, + skcms_TFType_HLGinvish, +} skcms_TFType; + +// Identify which kind of transfer function is encoded in an skcms_TransferFunction +SKCMS_API skcms_TFType skcms_TransferFunction_getType(const skcms_TransferFunction*); + // We can jam a couple alternate transfer function forms into skcms_TransferFunction, // including those matching the general forms of the SMPTE ST 2084 PQ function or HLG. // @@ -307,6 +318,9 @@ typedef enum skcms_PixelFormat { skcms_PixelFormat_BGR_fff, // Pointers must be 32-bit aligned. skcms_PixelFormat_RGBA_ffff, skcms_PixelFormat_BGRA_ffff, + + skcms_PixelFormat_RGB_101010x_XR, // Note: This is located here to signal no clamping. + skcms_PixelFormat_BGR_101010x_XR, // Compatible with MTLPixelFormatBGR10_XR. } skcms_PixelFormat; // We always store any alpha channel linearly. In the chart below, tf-1() is the inverse diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h index 7b8aa8ac1c50f..350f6a20a6c6b 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h @@ -903,6 +903,16 @@ static void exec_ops(const Op* ops, const void** args, a = cast((rgba >> 30) & 0x3 ) * (1/ 3.0f); } break; + case Op_load_101010x_XR:{ + static constexpr float min = -0.752941f; + static constexpr float max = 1.25098f; + static constexpr float range = max - min; + U32 rgba = load(src + 4*i); + r = cast((rgba >> 0) & 0x3ff) * (1/1023.0f) * range + min; + g = cast((rgba >> 10) & 0x3ff) * (1/1023.0f) * range + min; + b = cast((rgba >> 20) & 0x3ff) * (1/1023.0f) * range + min; + } break; + case Op_load_161616LE:{ uintptr_t ptr = (uintptr_t)(src + 6*i); assert( (ptr & 1) == 0 ); // src must be 2-byte aligned for this @@ -1313,6 +1323,15 @@ static void exec_ops(const Op* ops, const void** args, | cast(to_fixed(a * 255)) << 24); } return; + case Op_store_101010x_XR: { + static constexpr float min = -0.752941f; + static constexpr float max = 1.25098f; + static constexpr float range = max - min; + store(dst + 4*i, cast(to_fixed(((r - min) / range) * 1023)) << 0 + | cast(to_fixed(((g - min) / range) * 1023)) << 10 + | cast(to_fixed(((b - min) / range) * 1023)) << 20); + return; + } case Op_store_1010102: { store(dst + 4*i, cast(to_fixed(r * 1023)) << 0 | cast(to_fixed(g * 1023)) << 10 diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h index a119e4b28d2c7..bc895f99c6e81 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h @@ -7,10 +7,10 @@ #include #include "include/core/SkFontMgr.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTHash.h" #include "modules/skparagraph/include/FontArguments.h" #include "modules/skparagraph/include/ParagraphCache.h" #include "modules/skparagraph/include/TextStyle.h" +#include "src/core/SkTHash.h" namespace skia { namespace textlayout { @@ -69,7 +69,7 @@ class FontCollection : public SkRefCnt { }; bool fEnableFontFallback; - SkTHashMap>, FamilyKey::Hasher> fTypefaces; + skia_private::THashMap>, FamilyKey::Hasher> fTypefaces; sk_sp fDefaultFontManager; sk_sp fAssetFontManager; sk_sp fDynamicFontManager; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h index 5c5503876bec8..c78b0798412a1 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h @@ -12,6 +12,8 @@ class SkCanvas; namespace skia { namespace textlayout { +class ParagraphPainter; + class Paragraph { public: @@ -39,6 +41,8 @@ class Paragraph { virtual void paint(SkCanvas* canvas, SkScalar x, SkScalar y) = 0; + virtual void paint(ParagraphPainter* painter, SkScalar x, SkScalar y) = 0; + // Returns a vector of bounding boxes that enclose all text between // start and end glyph indexes, including start and excluding end virtual std::vector getRectsForRange(unsigned start, @@ -66,9 +70,9 @@ class Paragraph { // -1 if not applicable (has not been shaped yet - valid case) virtual int32_t unresolvedGlyphs() = 0; - // Experimental API that allows fast way to update "immutable" paragraph + // Experimental API that allows fast way to update some of "immutable" paragraph attributes + // but not the text itself virtual void updateTextAlign(TextAlign textAlign) = 0; - virtual void updateText(size_t from, SkString text) = 0; virtual void updateFontSize(size_t from, size_t to, SkScalar fontSize) = 0; virtual void updateForegroundPaint(size_t from, size_t to, SkPaint paint) = 0; virtual void updateBackgroundPaint(size_t from, size_t to, SkPaint paint) = 0; @@ -91,6 +95,72 @@ class Paragraph { using Visitor = std::function; virtual void visit(const Visitor&) = 0; + // Editing API + virtual int getLineNumberAt(TextIndex codeUnitIndex) const = 0; + + /* Returns line metrics info for the line + * + * @param lineNumber a line number + * @param lineMetrics an address to return the info (in case of null just skipped) + * @return true if the line is found; false if not + */ + virtual bool getLineMetricsAt(int lineNumber, LineMetrics* lineMetrics) const = 0; + + /* Returns the visible text on the line (excluding a possible ellipsis) + * + * @param lineNumber a line number + * @param includeSpaces indicates if the whitespaces should be included + * @return the range of the text that is shown in the line + */ + virtual TextRange getActualTextRange(int lineNumber, bool includeSpaces) const = 0; + + struct GlyphClusterInfo { + SkRect fBounds; + TextRange fClusterTextRange; + TextDirection fGlyphClusterPosition; + }; + + /** Finds a glyph cluster for text index + * + * @param codeUnitIndex a text index + * @param glyphInfo a glyph cluster info filled if not null + * @return true if glyph cluster was found; false if not + */ + virtual bool getGlyphClusterAt(TextIndex codeUnitIndex, GlyphClusterInfo* glyphInfo) = 0; + + /** Finds the closest glyph cluster for a visual text position + * + * @param dx x coordinate + * @param dy y coordinate + * @param glyphInfo a glyph cluster info filled if not null + * @return + */ + virtual bool getClosestGlyphClusterAt(SkScalar dx, + SkScalar dy, + GlyphClusterInfo* glyphInfo) = 0; + + struct FontInfo { + FontInfo(const SkFont font, const TextRange textRange) + : fFont(font), fTextRange(textRange) { } + virtual ~FontInfo() = default; + FontInfo(const FontInfo& ) = default; + SkFont fFont; + TextRange fTextRange; + }; + + /** Returns the font that is used to shape the text at the position + * + * @param codeUnitIndex text index + * @return font info or an empty font info if the text is not found + */ + virtual SkFont getFontAt(TextIndex codeUnitIndex) const = 0; + + /** Returns the information about all the fonts used to shape the paragraph text + * + * @return a list of fonts and text ranges + */ + virtual std::vector getFonts() const = 0; + protected: sk_sp fFontCollection; ParagraphStyle fParagraphStyle; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h index 90ffb7019d8e8..45652ae79912c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h @@ -2,7 +2,7 @@ #ifndef ParagraphCache_DEFINED #define ParagraphCache_DEFINED -#include "include/private/SkMutex.h" +#include "include/private/base/SkMutex.h" #include "src/core/SkLRUCache.h" #include // std::function @@ -11,16 +11,6 @@ namespace skia { namespace textlayout { -enum InternalState { - kUnknown = 0, - kShaped = 2, - kClusterized = 3, - kMarked = 4, - kLineBroken = 5, - kFormatted = 6, - kDrawn = 7 -}; - class ParagraphImpl; class ParagraphCacheKey; class ParagraphCacheValue; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h new file mode 100644 index 0000000000000..56388e64f17bd --- /dev/null +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h @@ -0,0 +1,63 @@ +// Copyright 2019 Google LLC. +#ifndef ParagraphPainter_DEFINED +#define ParagraphPainter_DEFINED + +#include "include/core/SkPaint.h" +#include "include/core/SkTextBlob.h" + +#include +#include + +namespace skia { +namespace textlayout { + +class ParagraphPainter { +public: + typedef int PaintID; + typedef std::variant SkPaintOrID; + + struct DashPathEffect { + DashPathEffect(SkScalar onLength, SkScalar offLength); + + SkScalar fOnLength; + SkScalar fOffLength; + }; + + class DecorationStyle { + public: + DecorationStyle(); + DecorationStyle(SkColor color, SkScalar strokeWidth, + std::optional dashPathEffect); + + SkColor getColor() const { return fColor; } + SkScalar getStrokeWidth() const { return fStrokeWidth; } + std::optional getDashPathEffect() const { return fDashPathEffect; } + const SkPaint& skPaint() const { return fPaint; } + + private: + SkColor fColor; + SkScalar fStrokeWidth; + std::optional fDashPathEffect; + SkPaint fPaint; + }; + + virtual ~ParagraphPainter() = default; + + virtual void drawTextBlob(const sk_sp& blob, SkScalar x, SkScalar y, const SkPaintOrID& paint) = 0; + virtual void drawTextShadow(const sk_sp& blob, SkScalar x, SkScalar y, SkColor color, SkScalar blurSigma) = 0; + virtual void drawRect(const SkRect& rect, const SkPaintOrID& paint) = 0; + virtual void drawFilledRect(const SkRect& rect, const DecorationStyle& decorStyle) = 0; + virtual void drawPath(const SkPath& path, const DecorationStyle& decorStyle) = 0; + virtual void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const DecorationStyle& decorStyle) = 0; + + virtual void clipRect(const SkRect& rect) = 0; + virtual void translate(SkScalar dx, SkScalar dy) = 0; + + virtual void save() = 0; + virtual void restore() = 0; +}; + +} // namespace textlayout +} // namespace skia + +#endif // ParagraphPainter_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h index 82b4a7cb13cb4..e6f0ae46302d9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h @@ -12,6 +12,7 @@ #include "include/core/SkScalar.h" #include "modules/skparagraph/include/DartTypes.h" #include "modules/skparagraph/include/FontArguments.h" +#include "modules/skparagraph/include/ParagraphPainter.h" #include "modules/skparagraph/include/TextShadow.h" // TODO: Make it external so the other platforms (Android) could use it @@ -165,19 +166,41 @@ class TextStyle { void setColor(SkColor color) { fColor = color; } bool hasForeground() const { return fHasForeground; } - SkPaint getForeground() const { return fForeground; } + SkPaint getForeground() const { + const SkPaint* paint = std::get_if(&fForeground); + return paint ? *paint : SkPaint(); + } + ParagraphPainter::SkPaintOrID getForegroundPaintOrID() const { + return fForeground; + } void setForegroundColor(SkPaint paint) { fHasForeground = true; fForeground = std::move(paint); } + // Set the foreground to a paint ID. This is intended for use by clients + // that implement a custom ParagraphPainter that can not accept an SkPaint. + void setForegroundPaintID(ParagraphPainter::PaintID paintID) { + fHasForeground = true; + fForeground = paintID; + } void clearForegroundColor() { fHasForeground = false; } bool hasBackground() const { return fHasBackground; } - SkPaint getBackground() const { return fBackground; } + SkPaint getBackground() const { + const SkPaint* paint = std::get_if(&fBackground); + return paint ? *paint : SkPaint(); + } + ParagraphPainter::SkPaintOrID getBackgroundPaintOrID() const { + return fBackground; + } void setBackgroundColor(SkPaint paint) { fHasBackground = true; fBackground = std::move(paint); } + void setBackgroundPaintID(ParagraphPainter::PaintID paintID) { + fHasBackground = true; + fBackground = paintID; + } void clearBackgroundColor() { fHasBackground = false; } // Decorations @@ -291,9 +314,9 @@ class TextStyle { SkColor fColor = SK_ColorWHITE; bool fHasBackground = false; - SkPaint fBackground; + ParagraphPainter::SkPaintOrID fBackground; bool fHasForeground = false; - SkPaint fForeground; + ParagraphPainter::SkPaintOrID fForeground; std::vector fTextShadows; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h index df759b125ad24..c51110cd4fea9 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h @@ -2,8 +2,8 @@ #ifndef TypefaceFontProvider_DEFINED #define TypefaceFontProvider_DEFINED -#include "include/private/SkTArray.h" -#include "include/private/SkTHash.h" +#include "include/private/base/SkTArray.h" +#include "src/core/SkTHash.h" #include #include #include @@ -20,15 +20,15 @@ class TypefaceFontStyleSet : public SkFontStyleSet { int count() override; void getStyle(int index, SkFontStyle*, SkString* name) override; - SkTypeface* createTypeface(int index) override; - SkTypeface* matchStyle(const SkFontStyle& pattern) override; + sk_sp createTypeface(int index) override; + sk_sp matchStyle(const SkFontStyle& pattern) override; SkString getFamilyName() const { return fFamilyName; } SkString getAlias() const { return fAlias; } void appendTypeface(sk_sp typeface); private: - SkTArray> fStyles; + skia_private::TArray> fStyles; SkString fFamilyName; SkString fAlias; }; @@ -42,15 +42,15 @@ class TypefaceFontProvider : public SkFontMgr { void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkFontStyleSet* onCreateStyleSet(int) const override { return nullptr; } - SkTypeface* onMatchFamilyStyle(const char[], const SkFontStyle&) const override { + sk_sp onCreateStyleSet(int) const override { return nullptr; } + sk_sp onMatchFamilyStyle(const char[], const SkFontStyle&) const override { return nullptr; } - SkTypeface* onMatchFamilyStyleCharacter(const char[], const SkFontStyle&, - const char*[], int, - SkUnichar) const override { + sk_sp onMatchFamilyStyleCharacter(const char[], const SkFontStyle&, + const char*[], int, + SkUnichar) const override { return nullptr; } @@ -71,8 +71,8 @@ class TypefaceFontProvider : public SkFontMgr { } private: - SkTHashMap> fRegisteredFamilies; - SkTArray fFamilyNames; + skia_private::THashMap> fRegisteredFamilies; + skia_private::TArray fFamilyNames; }; } // namespace textlayout diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h index f59471198b066..a0f44a83be116 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h @@ -15,8 +15,8 @@ #include "include/core/SkString.h" #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTHash.h" +#include "include/private/base/SkMutex.h" +#include "src/core/SkTHash.h" #include @@ -50,6 +50,18 @@ class SK_API ImageAsset : public SkRefCnt { */ virtual sk_sp getFrame(float t); + // Describes how the frame image is to be scaled to the animation-declared asset size. + enum class SizeFit { + // See SkMatrix::ScaleToFit + kFill = SkMatrix::kFill_ScaleToFit, + kStart = SkMatrix::kStart_ScaleToFit, + kCenter = SkMatrix::kCenter_ScaleToFit, + kEnd = SkMatrix::kEnd_ScaleToFit, + + // No scaling. + kNone, + }; + struct FrameData { // SkImage payload. sk_sp image; @@ -57,6 +69,8 @@ class SK_API ImageAsset : public SkRefCnt { SkSamplingOptions sampling; // Additional image transform to be applied before AE scaling rules. SkMatrix matrix = SkMatrix::I(); + // Strategy for image size -> AE asset size scaling. + SizeFit scaling = SizeFit::kCenter; }; /** @@ -227,8 +241,8 @@ class SK_API CachingResourceProvider final : public ResourceProviderProxyBase { sk_sp loadImageAsset(const char[], const char[], const char[]) const override; - mutable SkMutex fMutex; - mutable SkTHashMap> fImageCache; + mutable SkMutex fMutex; + mutable skia_private::THashMap> fImageCache; using INHERITED = ResourceProviderProxyBase; }; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h index d6996638ccdcf..8e4d56caee221 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h @@ -9,7 +9,7 @@ #define SkSVGAttribute_DEFINED #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGRenderContext; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h index e4ac579f7966d..9513232218668 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h @@ -10,9 +10,9 @@ #include -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGAttributeParser : public SkNoncopyable { public: diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h index 560271854f5b6..e5e9516c32e68 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h @@ -8,7 +8,7 @@ #ifndef SkSVGContainer_DEFINED #define SkSVGContainer_DEFINED -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include "modules/svg/include/SkSVGTransformableNode.h" class SkSVGContainer : public SkSVGTransformableNode { @@ -27,7 +27,7 @@ class SkSVGContainer : public SkSVGTransformableNode { bool hasChildren() const final; // TODO: add some sort of child iterator, and hide the container. - SkSTArray<1, sk_sp, true> fChildren; + skia_private::STArray<1, sk_sp, true> fChildren; private: using INHERITED = SkSVGTransformableNode; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h index a035179b70e7b..f0bd467d28aee 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h @@ -11,7 +11,7 @@ #include "include/core/SkFontMgr.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include "modules/skresources/include/SkResources.h" #include "modules/svg/include/SkSVGIDMapper.h" diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h index edd503403c130..dcd938d1e1838 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h @@ -11,8 +11,8 @@ #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" #include "include/core/SkString.h" -#include "include/private/SkTHash.h" #include "modules/svg/include/SkSVGTypes.h" +#include "src/core/SkTHash.h" class SkImageFilter; class SkSVGFeInputType; @@ -61,7 +61,7 @@ class SkSVGFilterContext { SkSVGObjectBoundingBoxUnits fPrimitiveUnits; - SkTHashMap fResults; + skia_private::THashMap fResults; Result fPreviousResult; }; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h index 2c1e45afcf5d8..16053e83c85fd 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h @@ -37,8 +37,8 @@ class SkSVGGradient : public SkSVGHiddenContainer { SkTileMode, const SkMatrix& localMatrix) const = 0; private: - using StopPositionArray = SkSTArray<2, SkScalar , true>; - using StopColorArray = SkSTArray<2, SkColor4f, true>; + using StopPositionArray = skia_private::STArray<2, SkScalar , true>; + using StopColorArray = skia_private::STArray<2, SkColor4f, true>; void collectColorStops(const SkSVGRenderContext&, StopPositionArray*, StopColorArray*) const; SkColor4f resolveStopColor(const SkSVGRenderContext&, const SkSVGStop&) const; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h index ea0d9165fcbae..e78f28de37368 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h @@ -9,11 +9,11 @@ #define SkSVGIDMapper_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkTHash.h" +#include "src/core/SkTHash.h" class SkString; class SkSVGNode; -using SkSVGIDMapper = SkTHashMap>; +using SkSVGIDMapper = skia_private::THashMap>; #endif // SkSVGIDMapper_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h index 27a86395cb4b4..32ee8a08e415f 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h @@ -15,11 +15,11 @@ #include "include/core/SkRect.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" -#include "include/private/SkTHash.h" #include "modules/skresources/include/SkResources.h" #include "modules/svg/include/SkSVGAttribute.h" #include "modules/svg/include/SkSVGIDMapper.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" +#include "src/core/SkTHash.h" class SkCanvas; class SkSVGLength; @@ -52,7 +52,7 @@ struct SkSVGPresentationContext { SkSVGPresentationContext(const SkSVGPresentationContext&) = default; SkSVGPresentationContext& operator=(const SkSVGPresentationContext&) = default; - const SkTHashMap* fNamedColors = nullptr; + const skia_private::THashMap* fNamedColors = nullptr; // Inherited presentation attributes, computed for the current node. SkSVGPresentationAttributes fInherited; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h index 91f33dea9a3c2..41e041de3f76c 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h @@ -10,7 +10,7 @@ #include "modules/svg/include/SkSVGContainer.h" #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGLengthContext; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h index db103bef59179..77c5fbef40562 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h @@ -18,8 +18,9 @@ #include "include/core/SkSpan.h" #include "include/core/SkString.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" -#include "src/core/SkTLazy.h" + +#include +#include using SkSVGColorType = SkColor; using SkSVGIntegerType = int; @@ -27,7 +28,7 @@ using SkSVGNumberType = SkScalar; using SkSVGStringType = SkString; using SkSVGViewBoxType = SkRect; using SkSVGTransformType = SkMatrix; -using SkSVGPointsType = SkTDArray; +using SkSVGPointsType = std::vector; enum class SkSVGPropertyState { kUnspecified, @@ -45,17 +46,17 @@ template class SkSVGProperty { explicit SkSVGProperty(SkSVGPropertyState state) : fState(state) {} explicit SkSVGProperty(const T& value) : fState(SkSVGPropertyState::kValue) { - fValue.set(value); + fValue = value; } explicit SkSVGProperty(T&& value) : fState(SkSVGPropertyState::kValue) { - fValue.set(std::move(value)); + fValue = std::move(value); } template void init(Args&&... args) { fState = SkSVGPropertyState::kValue; - fValue.init(std::forward(args)...); + fValue.emplace(std::forward(args)...); } constexpr bool isInheritable() const { return kInheritable; } @@ -63,7 +64,7 @@ template class SkSVGProperty { bool isValue() const { return fState == SkSVGPropertyState::kValue; } T* getMaybeNull() const { - return fValue.getMaybeNull(); + return fValue.has_value() ? &fValue.value() : nullptr; } void set(SkSVGPropertyState state) { @@ -75,41 +76,41 @@ template class SkSVGProperty { void set(const T& value) { fState = SkSVGPropertyState::kValue; - fValue.set(value); + fValue = value; } void set(T&& value) { fState = SkSVGPropertyState::kValue; - fValue.set(std::move(value)); + fValue = std::move(value); } T* operator->() { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); - return fValue.get(); + SkASSERT(fValue.has_value()); + return &fValue.value(); } const T* operator->() const { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); - return fValue.get(); + SkASSERT(fValue.has_value()); + return &fValue.value(); } T& operator*() { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); + SkASSERT(fValue.has_value()); return *fValue; } const T& operator*() const { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); + SkASSERT(fValue.has_value()); return *fValue; } private: SkSVGPropertyState fState; - SkTLazy fValue; + std::optional fValue; }; class SkSVGLength { @@ -180,7 +181,7 @@ class SkSVGColor { kColor, kICCColor, }; - using Vars = SkSTArray<1, SkString>; + using Vars = std::vector; SkSVGColor() : SkSVGColor(SK_ColorBLACK) {} explicit SkSVGColor(const SkSVGColorType& c) : fType(Type::kColor), fColor(c), fVars(nullptr) {} @@ -400,7 +401,7 @@ class SkSVGDashArray { SkSVGDashArray() : fType(Type::kNone) {} explicit SkSVGDashArray(Type t) : fType(t) {} - explicit SkSVGDashArray(SkTDArray&& dashArray) + explicit SkSVGDashArray(std::vector&& dashArray) : fType(Type::kDashArray) , fDashArray(std::move(dashArray)) {} @@ -414,11 +415,11 @@ class SkSVGDashArray { Type type() const { return fType; } - const SkTDArray& dashArray() const { return fDashArray; } + const std::vector& dashArray() const { return fDashArray; } private: Type fType; - SkTDArray fDashArray; + std::vector fDashArray; }; class SkSVGStopColor { @@ -673,7 +674,7 @@ enum class SkSVGFeColorMatrixType { kLuminanceToAlpha, }; -using SkSVGFeColorMatrixValues = SkTDArray; +using SkSVGFeColorMatrixValues = std::vector; enum class SkSVGFeCompositeOperator { kOver, diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h index eb1977feb356e..d03afa6d9fa98 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h @@ -12,7 +12,7 @@ #include "include/core/SkMatrix.h" #include "include/core/SkPath.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/svg/include/SkSVGTypes.h" class SkSVGValue : public SkNoncopyable { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h deleted file mode 100644 index 50429d500f25c..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkLRUCache_DEFINED -#define SkLRUCache_DEFINED - -#include "include/private/SkChecksum.h" -#include "include/private/SkTHash.h" -#include "src/core/SkTInternalLList.h" - -/** - * A generic LRU cache. - */ -template -class SkLRUCache : public SkNoncopyable { -private: - struct Entry { - Entry(const K& key, V&& value) - : fKey(key) - , fValue(std::move(value)) {} - - K fKey; - V fValue; - - SK_DECLARE_INTERNAL_LLIST_INTERFACE(Entry); - }; - -public: - explicit SkLRUCache(int maxCount) - : fMaxCount(maxCount) {} - - ~SkLRUCache() { - Entry* node = fLRU.head(); - while (node) { - fLRU.remove(node); - delete node; - node = fLRU.head(); - } - } - - V* find(const K& key) { - Entry** value = fMap.find(key); - if (!value) { - return nullptr; - } - Entry* entry = *value; - if (entry != fLRU.head()) { - fLRU.remove(entry); - fLRU.addToHead(entry); - } // else it's already at head position, don't need to do anything - return &entry->fValue; - } - - V* insert(const K& key, V value) { - SkASSERT(!this->find(key)); - - Entry* entry = new Entry(key, std::move(value)); - fMap.set(entry); - fLRU.addToHead(entry); - while (fMap.count() > fMaxCount) { - this->remove(fLRU.tail()->fKey); - } - return &entry->fValue; - } - - V* insert_or_update(const K& key, V value) { - if (V* found = this->find(key)) { - *found = std::move(value); - return found; - } else { - return this->insert(key, std::move(value)); - } - } - - int count() { - return fMap.count(); - } - - template // f(K*, V*) - void foreach(Fn&& fn) { - typename SkTInternalLList::Iter iter; - for (Entry* e = iter.init(fLRU, SkTInternalLList::Iter::kHead_IterStart); e; - e = iter.next()) { - fn(&e->fKey, &e->fValue); - } - } - - void reset() { - fMap.reset(); - for (Entry* e = fLRU.head(); e; e = fLRU.head()) { - fLRU.remove(e); - delete e; - } - } - -private: - struct Traits { - static const K& GetKey(Entry* e) { - return e->fKey; - } - - static uint32_t Hash(const K& k) { - return HashK()(k); - } - }; - - void remove(const K& key) { - Entry** value = fMap.find(key); - SkASSERT(value); - Entry* entry = *value; - SkASSERT(key == entry->fKey); - fMap.remove(key); - fLRU.remove(entry); - delete entry; - } - - int fMaxCount; - SkTHashTable fMap; - SkTInternalLList fLRU; -}; - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h similarity index 89% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h rename to android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h index 7fe6d33c70c84..e72483b501df1 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h @@ -10,13 +10,15 @@ #include "include/core/SkTypes.h" #include "include/private/SkChecksum.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include #include #include -// Before trying to use SkTHashTable, look below to see if SkTHashMap or SkTHashSet works for you. +namespace skia_private { + +// Before trying to use THashTable, look below to see if THashMap or THashSet works for you. // They're easier to use, usually perform the same, and have fewer sharp edges. // T and K are treated as ordinary copyable C++ types. @@ -26,15 +28,15 @@ // If the key is large and stored inside T, you may want to make K a const&. // Similarly, if T is large you might want it to be a pointer. template -class SkTHashTable { +class THashTable { public: - SkTHashTable() = default; - ~SkTHashTable() = default; + THashTable() = default; + ~THashTable() = default; - SkTHashTable(const SkTHashTable& that) { *this = that; } - SkTHashTable( SkTHashTable&& that) { *this = std::move(that); } + THashTable(const THashTable& that) { *this = that; } + THashTable( THashTable&& that) { *this = std::move(that); } - SkTHashTable& operator=(const SkTHashTable& that) { + THashTable& operator=(const THashTable& that) { if (this != &that) { fCount = that.fCount; fCapacity = that.fCapacity; @@ -46,7 +48,7 @@ class SkTHashTable { return *this; } - SkTHashTable& operator=(SkTHashTable&& that) { + THashTable& operator=(THashTable&& that) { if (this != &that) { fCount = that.fCount; fCapacity = that.fCapacity; @@ -58,7 +60,7 @@ class SkTHashTable { } // Clear the table. - void reset() { *this = SkTHashTable(); } + void reset() { *this = THashTable(); } // How many entries are in the table? int count() const { return fCount; } @@ -75,7 +77,7 @@ class SkTHashTable { // If you change an entry so that it no longer has the same key, all hell // will break loose. Do not do that! // - // Please prefer to use SkTHashMap or SkTHashSet, which do not have this danger. + // Please prefer to use THashMap or THashSet, which do not have this danger. // The pointers returned by set() and find() are valid only until the next call to set(). // The pointers you receive in foreach() are only valid for its duration. @@ -103,7 +105,7 @@ class SkTHashTable { } index = this->next(index); } - SkASSERT(fCapacity == 0); + SkASSERT(fCapacity == fCount); return nullptr; } @@ -145,8 +147,8 @@ class SkTHashTable { fCount = 0; fCapacity = capacity; - SkAutoTArray oldSlots = std::move(fSlots); - fSlots = SkAutoTArray(capacity); + AutoTArray oldSlots = std::move(fSlots); + fSlots = AutoTArray(capacity); for (int i = 0; i < oldCapacity; i++) { Slot& s = oldSlots[i]; @@ -178,12 +180,12 @@ class SkTHashTable { } // A basic iterator-like class which disallows mutation; sufficient for range-based for loops. - // Intended for use by SkTHashMap and SkTHashSet via begin() and end(). + // Intended for use by THashMap and THashSet via begin() and end(). // Adding or removing elements may invalidate all iterators. template class Iter { public: - using TTable = SkTHashTable; + using TTable = THashTable; Iter(const TTable* table, int slot) : fTable(table), fSlot(slot) {} @@ -411,22 +413,22 @@ class SkTHashTable { int fCount = 0, fCapacity = 0; - SkAutoTArray fSlots; + AutoTArray fSlots; }; -// Maps K->V. A more user-friendly wrapper around SkTHashTable, suitable for most use cases. +// Maps K->V. A more user-friendly wrapper around THashTable, suitable for most use cases. // K and V are treated as ordinary copyable C++ types, with no assumed relationship between the two. template -class SkTHashMap { +class THashMap { public: // Allow default construction and assignment. - SkTHashMap() = default; + THashMap() = default; - SkTHashMap(SkTHashMap&& that) = default; - SkTHashMap(const SkTHashMap& that) = default; + THashMap(THashMap&& that) = default; + THashMap(const THashMap& that) = default; - SkTHashMap& operator=(SkTHashMap&& that) = default; - SkTHashMap& operator=(const SkTHashMap& that) = default; + THashMap& operator=(THashMap&& that) = default; + THashMap& operator=(const THashMap& that) = default; // Construct with an initializer list of key-value pairs. struct Pair : public std::pair { @@ -435,7 +437,7 @@ class SkTHashMap { static auto Hash(const K& key) { return HashK()(key); } }; - SkTHashMap(std::initializer_list pairs) { + THashMap(std::initializer_list pairs) { fTable.resize(pairs.size() * 5 / 3); for (const Pair& p : pairs) { fTable.set(p); @@ -498,7 +500,7 @@ class SkTHashMap { } // Dereferencing an iterator gives back a key-value pair, suitable for structured binding. - using Iter = typename SkTHashTable::template Iter>; + using Iter = typename THashTable::template Iter>; Iter begin() const { return Iter::MakeBegin(&fTable); @@ -509,24 +511,24 @@ class SkTHashMap { } private: - SkTHashTable fTable; + THashTable fTable; }; // A set of T. T is treated as an ordinary copyable C++ type. template -class SkTHashSet { +class THashSet { public: // Allow default construction and assignment. - SkTHashSet() = default; + THashSet() = default; - SkTHashSet(SkTHashSet&& that) = default; - SkTHashSet(const SkTHashSet& that) = default; + THashSet(THashSet&& that) = default; + THashSet(const THashSet& that) = default; - SkTHashSet& operator=(SkTHashSet&& that) = default; - SkTHashSet& operator=(const SkTHashSet& that) = default; + THashSet& operator=(THashSet&& that) = default; + THashSet& operator=(const THashSet& that) = default; // Construct with an initializer list of Ts. - SkTHashSet(std::initializer_list vals) { + THashSet(std::initializer_list vals) { fTable.resize(vals.size() * 5 / 3); for (const T& val : vals) { fTable.set(val); @@ -574,7 +576,7 @@ class SkTHashSet { }; public: - using Iter = typename SkTHashTable::template Iter; + using Iter = typename THashTable::template Iter; Iter begin() const { return Iter::MakeBegin(&fTable); @@ -585,7 +587,9 @@ class SkTHashSet { } private: - SkTHashTable fTable; + THashTable fTable; }; -#endif//SkTHash_DEFINED +} // namespace skia_private + +#endif // SkTHash_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h deleted file mode 100644 index a5cb615556e56..0000000000000 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkTInternalLList_DEFINED -#define SkTInternalLList_DEFINED - -#include "include/core/SkTypes.h" - -/** - * This macro creates the member variables required by the SkTInternalLList class. It should be - * placed in the private section of any class that will be stored in a double linked list. - */ -#define SK_DECLARE_INTERNAL_LLIST_INTERFACE(ClassName) \ - friend class SkTInternalLList; \ - /* back pointer to the owning list - for debugging */ \ - SkDEBUGCODE(SkTInternalLList* fList = nullptr;) \ - ClassName* fPrev = nullptr; \ - ClassName* fNext = nullptr - -/** - * This class implements a templated internal doubly linked list data structure. - */ -template class SkTInternalLList { -public: - SkTInternalLList() {} - - void reset() { - fHead = nullptr; - fTail = nullptr; - } - - void remove(T* entry) { - SkASSERT(fHead && fTail); - SkASSERT(this->isInList(entry)); - - T* prev = entry->fPrev; - T* next = entry->fNext; - - if (prev) { - prev->fNext = next; - } else { - fHead = next; - } - if (next) { - next->fPrev = prev; - } else { - fTail = prev; - } - - entry->fPrev = nullptr; - entry->fNext = nullptr; - -#ifdef SK_DEBUG - entry->fList = nullptr; -#endif - } - - void addToHead(T* entry) { - SkASSERT(nullptr == entry->fPrev && nullptr == entry->fNext); - SkASSERT(nullptr == entry->fList); - - entry->fPrev = nullptr; - entry->fNext = fHead; - if (fHead) { - fHead->fPrev = entry; - } - fHead = entry; - if (nullptr == fTail) { - fTail = entry; - } - -#ifdef SK_DEBUG - entry->fList = this; -#endif - } - - void addToTail(T* entry) { - SkASSERT(nullptr == entry->fPrev && nullptr == entry->fNext); - SkASSERT(nullptr == entry->fList); - - entry->fPrev = fTail; - entry->fNext = nullptr; - if (fTail) { - fTail->fNext = entry; - } - fTail = entry; - if (nullptr == fHead) { - fHead = entry; - } - -#ifdef SK_DEBUG - entry->fList = this; -#endif - } - - /** - * Inserts a new list entry before an existing list entry. The new entry must not already be - * a member of this or any other list. If existingEntry is NULL then the new entry is added - * at the tail. - */ - void addBefore(T* newEntry, T* existingEntry) { - SkASSERT(newEntry); - - if (nullptr == existingEntry) { - this->addToTail(newEntry); - return; - } - - SkASSERT(this->isInList(existingEntry)); - newEntry->fNext = existingEntry; - T* prev = existingEntry->fPrev; - existingEntry->fPrev = newEntry; - newEntry->fPrev = prev; - if (nullptr == prev) { - SkASSERT(fHead == existingEntry); - fHead = newEntry; - } else { - prev->fNext = newEntry; - } -#ifdef SK_DEBUG - newEntry->fList = this; -#endif - } - - /** - * Inserts a new list entry after an existing list entry. The new entry must not already be - * a member of this or any other list. If existingEntry is NULL then the new entry is added - * at the head. - */ - void addAfter(T* newEntry, T* existingEntry) { - SkASSERT(newEntry); - - if (nullptr == existingEntry) { - this->addToHead(newEntry); - return; - } - - SkASSERT(this->isInList(existingEntry)); - newEntry->fPrev = existingEntry; - T* next = existingEntry->fNext; - existingEntry->fNext = newEntry; - newEntry->fNext = next; - if (nullptr == next) { - SkASSERT(fTail == existingEntry); - fTail = newEntry; - } else { - next->fPrev = newEntry; - } -#ifdef SK_DEBUG - newEntry->fList = this; -#endif - } - - void concat(SkTInternalLList&& list) { - if (list.isEmpty()) { - return; - } - - list.fHead->fPrev = fTail; - if (!fHead) { - SkASSERT(!list.fHead->fPrev); - fHead = list.fHead; - } else { - SkASSERT(fTail); - fTail->fNext = list.fHead; - } - fTail = list.fTail; - -#ifdef SK_DEBUG - for (T* node = list.fHead; node; node = node->fNext) { - SkASSERT(node->fList == &list); - node->fList = this; - } -#endif - - list.fHead = list.fTail = nullptr; - } - - bool isEmpty() const { - SkASSERT(SkToBool(fHead) == SkToBool(fTail)); - return !fHead; - } - - T* head() const { return fHead; } - T* tail() const { return fTail; } - - class Iter { - public: - enum IterStart { - kHead_IterStart, - kTail_IterStart - }; - - Iter() : fCurr(nullptr) {} - Iter(const Iter& iter) : fCurr(iter.fCurr) {} - Iter& operator= (const Iter& iter) { fCurr = iter.fCurr; return *this; } - - T* init(const SkTInternalLList& list, IterStart startLoc) { - if (kHead_IterStart == startLoc) { - fCurr = list.fHead; - } else { - SkASSERT(kTail_IterStart == startLoc); - fCurr = list.fTail; - } - - return fCurr; - } - - T* get() { return fCurr; } - - /** - * Return the next/previous element in the list or NULL if at the end. - */ - T* next() { - if (nullptr == fCurr) { - return nullptr; - } - - fCurr = fCurr->fNext; - return fCurr; - } - - T* prev() { - if (nullptr == fCurr) { - return nullptr; - } - - fCurr = fCurr->fPrev; - return fCurr; - } - - /** - * C++11 range-for interface. - */ - bool operator!=(const Iter& that) { return fCurr != that.fCurr; } - T* operator*() { return this->get(); } - void operator++() { this->next(); } - - private: - T* fCurr; - }; - - Iter begin() const { - Iter iter; - iter.init(*this, Iter::kHead_IterStart); - return iter; - } - - Iter end() const { return Iter(); } - -#ifdef SK_DEBUG - void validate() const { - SkASSERT(!fHead == !fTail); - Iter iter; - for (T* item = iter.init(*this, Iter::kHead_IterStart); item; item = iter.next()) { - SkASSERT(this->isInList(item)); - if (nullptr == item->fPrev) { - SkASSERT(fHead == item); - } else { - SkASSERT(item->fPrev->fNext == item); - } - if (nullptr == item->fNext) { - SkASSERT(fTail == item); - } else { - SkASSERT(item->fNext->fPrev == item); - } - } - } - - /** - * Debugging-only method that uses the list back pointer to check if 'entry' is indeed in 'this' - * list. - */ - bool isInList(const T* entry) const { - return entry->fList == this; - } - - /** - * Debugging-only method that laboriously counts the list entries. - */ - int countEntries() const { - int count = 0; - for (T* entry = fHead; entry; entry = entry->fNext) { - ++count; - } - return count; - } -#endif // SK_DEBUG - -private: - T* fHead = nullptr; - T* fTail = nullptr; - - SkTInternalLList(const SkTInternalLList&) = delete; - SkTInternalLList& operator=(const SkTInternalLList&) = delete; -}; - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkMeasureTime.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkMeasureTime.h index 0edebdcc7a553..de3e6acde53d3 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkMeasureTime.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkMeasureTime.h @@ -7,7 +7,7 @@ #include #include -#include +#include "RNSkLog.h" namespace RNSkia { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkTimingInfo.h b/android/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkTimingInfo.h index 69172fe0fe6df..10d86ec2a7e19 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkTimingInfo.h +++ b/android/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkTimingInfo.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "RNSkLog.h" #include #include #include diff --git a/apps/native-component-list/package.json b/apps/native-component-list/package.json index 3c839684c5167..11aec0570d33e 100644 --- a/apps/native-component-list/package.json +++ b/apps/native-component-list/package.json @@ -56,7 +56,7 @@ "@react-navigation/stack": "~6.3.2", "@react-navigation/elements": "~1.3.6", "@shopify/flash-list": "1.4.3", - "@shopify/react-native-skia": "0.1.172", + "@shopify/react-native-skia": "0.1.193", "date-format": "^2.0.0", "deep-object-diff": "^1.1.9", "expo": "~49.0.0-alpha.1", diff --git a/ios/Podfile.lock b/ios/Podfile.lock index b80e8b3a0d954..75bf28e2b24b2 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -2089,32 +2089,7 @@ PODS: - ReactCommon/turbomodule/core - react-native-segmented-control (2.4.0): - React-Core - - react-native-skia (0.1.172): - - React - - React-callinvoker - - React-Core - - react-native-skia/Api (= 0.1.172) - - react-native-skia/Jsi (= 0.1.172) - - react-native-skia/RNSkia (= 0.1.172) - - react-native-skia/SkiaHeaders (= 0.1.172) - - react-native-skia/Utils (= 0.1.172) - - react-native-skia/Api (0.1.172): - - React - - React-callinvoker - - React-Core - - react-native-skia/Jsi (0.1.172): - - React - - React-callinvoker - - React-Core - - react-native-skia/RNSkia (0.1.172): - - React - - React-callinvoker - - React-Core - - react-native-skia/SkiaHeaders (0.1.172): - - React - - React-callinvoker - - React-Core - - react-native-skia/Utils (0.1.172): + - react-native-skia (0.1.193): - React - React-callinvoker - React-Core @@ -3516,7 +3491,7 @@ SPEC CHECKSUMS: ABI47_0_0react-native-pager-view: 73b777af817cb59e405b524d64ed799eaf7c1e0d ABI47_0_0react-native-safe-area-context: fd7fe4aa020f08c12ac41fb223e73d73a51ddda6 ABI47_0_0react-native-segmented-control: 70d475eb39ae1b142e147ec2f930c7e04ba648c6 - ABI47_0_0react-native-skia: e2b3f4b651f6ec723d2200ea1fef9a54385971de + ABI47_0_0react-native-skia: 551a7e60fc52f2a44c1b382385b407857f54b00a ABI47_0_0react-native-slider: 03426a2c02e189942bd9d1ebe3660a7ce865abaa ABI47_0_0react-native-webview: fd74c03ab6c178600a7d92525d2e04cd918ab010 ABI47_0_0React-perflogger: 9a52299ec70eb15e293db99da2286f6b5ba1981f @@ -3624,7 +3599,7 @@ SPEC CHECKSUMS: ABI48_0_0react-native-pager-view: d305600a3bfed406e34eced45440aa49db7443ee ABI48_0_0react-native-safe-area-context: 20f8ba0ac5f1e77db9004646322ea28940571596 ABI48_0_0react-native-segmented-control: 94be546da127ec3ba7700218365155097b71c691 - ABI48_0_0react-native-skia: f798aadeab90f76f65e880f7f6ce226cfdb08168 + ABI48_0_0react-native-skia: ccc0ed1f1546d760f4fdae670e9fb7e7aaa48b4f ABI48_0_0react-native-slider: 945bf10759c027ee55ab625ebc963f0d71c79a3e ABI48_0_0react-native-webview: 5865178c5798f4d992d530583f83a211c1f20024 ABI48_0_0React-perflogger: 0d4574f2725620588415f8e407efa81f7623d4e0 @@ -3778,7 +3753,7 @@ SPEC CHECKSUMS: react-native-pager-view: 0ccb8bf60e2ebd38b1f3669fa3650ecce81db2df react-native-safe-area-context: b8979f5eda6ed5903d4dbc885be3846ea3daa753 react-native-segmented-control: 06607462630512ff8eef652ec560e6235a30cc3e - react-native-skia: ff2265fb802b2a3e1bf4a3c5a86d46936dd20354 + react-native-skia: d770660c767ab137636bd30bf18a1b70a18055c8 react-native-slider: 33b8d190b59d4f67a541061bb91775d53d617d9d react-native-webview: b8ec89966713985111a14d6e4bf98d8b54bced0d React-NativeModulesApple: ae27f95a2a84a877785a20ce4c689995dd5f4a64 diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/ABI47_0_0react-native-skia.podspec.json b/ios/vendored/sdk47/@shopify/react-native-skia/ABI47_0_0react-native-skia.podspec.json index ce741397abcf7..25448d6b3ad68 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/ABI47_0_0react-native-skia.podspec.json +++ b/ios/vendored/sdk47/@shopify/react-native-skia/ABI47_0_0react-native-skia.podspec.json @@ -17,9 +17,9 @@ }, "requires_arc": true, "pod_target_xcconfig": { - "GCC_PREPROCESSOR_DEFINITIONS": "$(inherited) SK_GL=1 SK_METAL=1", + "GCC_PREPROCESSOR_DEFINITIONS": "$(inherited) SK_METAL=1 SK_GANESH=1", "CLANG_CXX_LANGUAGE_STANDARD": "c++17", - "HEADER_SEARCH_PATHS": "\"$(PODS_ROOT)/Headers/Private/ABI47_0_0React-bridging/react/bridging\" \"$(PODS_CONFIGURATION_BUILD_DIR)/ABI47_0_0React-bridging/react_bridging.framework/Headers\"" + "HEADER_SEARCH_PATHS": "\"$(PODS_TARGET_SRCROOT)/cpp/\"/** \"$(PODS_ROOT)/Headers/Private/ABI47_0_0React-bridging/react/bridging\" \"$(PODS_CONFIGURATION_BUILD_DIR)/ABI47_0_0React-bridging/react_bridging.framework/Headers\"" }, "frameworks": [ "GLKit", diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImage.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImage.h index b94e3b6ba4476..ee3ad1738994e 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImage.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImage.h @@ -13,7 +13,10 @@ #include #include #include -#include +#include +#include +#include + #pragma clang diagnostic pop @@ -69,7 +72,15 @@ namespace ABI47_0_0RNSkia auto quality = count == 2 ? arguments[1].asNumber() : 100.0; // Get data - auto data = getObject()->encodeToData(format, quality); + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, getObject().get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, getObject().get(), options); + } auto arrayCtor = runtime.global().getPropertyAsFunction(runtime, "Uint8Array"); size_t size = data->size(); @@ -90,8 +101,19 @@ namespace ABI47_0_0RNSkia auto format = count >= 1 ? static_cast(arguments[0].asNumber()) : SkEncodedImageFormat::kPNG; auto quality = count == 2 ? arguments[1].asNumber() : 100.0; - - auto data = getObject()->encodeToData(format, quality); + auto image = getObject(); + if (image->isTextureBacked()) { + image = image->makeNonTextureImage(); + } + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, image.get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, image.get(), options); + } auto len = SkBase64::Encode(data->bytes(), data->size(), nullptr); auto buffer = std::string(len, 0); SkBase64::Encode(data->bytes(), data->size(), (void *)&buffer[0]); diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h index 9b55f01850816..a64391ab3d79d 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h @@ -18,7 +18,7 @@ namespace ABI47_0_0RNSkia { public: JSI_HOST_FUNCTION(MakeImageFromEncoded) { auto data = JsiSkData::fromValue(runtime, arguments[0]); - auto image = SkImage::MakeFromEncoded(data); + auto image = SkImages::DeferredFromEncodedData(data); if(image == nullptr) { return jsi::Value::null(); } @@ -30,7 +30,7 @@ namespace ABI47_0_0RNSkia { auto imageInfo = JsiSkImageInfo::fromValue(runtime, arguments[0]); auto pixelData = JsiSkData::fromValue(runtime, arguments[1]); auto bytesPerRow = arguments[2].asNumber(); - auto image = SkImage::MakeRasterData(*imageInfo, pixelData, bytesPerRow); + auto image = SkImages::RasterFromData(*imageInfo, pixelData, bytesPerRow); if(image == nullptr) { return jsi::Value::null(); } diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkPath.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkPath.h index a421727291b47..eae41538b95a1 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkPath.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/api/JsiSkPath.h @@ -7,6 +7,7 @@ #include #include "JsiSkHostObjects.h" +#include "JsiSkMatrix.h" #include "JsiSkPoint.h" #include "JsiSkRRect.h" #include "JsiSkRect.h" @@ -19,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -269,8 +271,11 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { auto jsiPrecision = opts.getProperty(runtime, "precision"); auto precision = jsiPrecision.isUndefined() ? 1 : jsiPrecision.asNumber(); - auto result = p.getFillPath(path, &path, nullptr, precision); - getObject()->swap(path); + auto result = + skpathutils::FillPathWithPaint(path, p, &path, nullptr, precision); + if (result) { + getObject()->swap(path); + } return result ? thisValue.getObject(runtime) : jsi::Value::null(); } @@ -305,8 +310,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { JSI_HOST_FUNCTION(toSVGString) { SkPath path = *getObject(); - SkString s; - SkParsePath::ToSVGString(path, &s); + auto s = SkParsePath::ToSVGString(path); return jsi::String::createFromUtf8(runtime, s.c_str()); } diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h index 5c8059cd91ee7..3407cfd02c00d 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h @@ -27,7 +27,7 @@ class SkShader; class SkAndroidFrameworkUtils { public: -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** * clipWithStencil draws the current clip into a stencil buffer with reference value and mask * set to 0x1. This function works only on a GPU canvas. @@ -37,7 +37,7 @@ class SkAndroidFrameworkUtils { * @return true on success or false if clip is empty or not a GPU canvas. */ static bool clipWithStencil(SkCanvas* canvas); -#endif //SK_SUPPORT_GPU +#endif //defined(SK_GANESH) static void SafetyNetLog(const char*); @@ -58,12 +58,6 @@ class SkAndroidFrameworkUtils { */ static SkCanvas* getBaseWrappedCanvas(SkCanvas* canvas); - /** - * Skia will change the order in which local matrices concatenate. In order to not break Android - * apps targeting older API levels we offer this function to use the legacy concatenation order. - */ - static void UseLegacyLocalMatrixConcatenation(); - /** * If the shader represents a linear gradient ShaderAsALinearGradient * returns true and if info is not null, ShaderAsALinearGradient populates diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h new file mode 100644 index 0000000000000..14ed009f8c400 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h @@ -0,0 +1,101 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkImageAndroid_DEFINED +#define SkImageAndroid_DEFINED + +#include "include/core/SkImage.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GrTypes.h" + +class SkColorSpace; +class GrDirectContext; +class SkPixmap; +struct AHardwareBuffer; + +namespace SkImages { + +/** (See Skia bug 7447) + Creates SkImage from Android hardware buffer. + Returned SkImage takes a reference on the buffer. + Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + @param hardwareBuffer AHardwareBuffer Android hardware buffer + @param colorSpace range of colors; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer, + SkAlphaType alphaType = kPremul_SkAlphaType); +SK_API sk_sp DeferredFromAHardwareBuffer( + AHardwareBuffer* hardwareBuffer, + SkAlphaType alphaType, + sk_sp colorSpace, + GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); + +/** Creates SkImage from Android hardware buffer and uploads the data from the SkPixmap to it. + Returned SkImage takes a reference on the buffer. + Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + @param context GPU context + @param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer + @param hardwareBuffer AHardwareBuffer Android hardware buffer + @param surfaceOrigin surface origin for resulting image + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromAHardwareBufferWithData( + GrDirectContext* context, + const SkPixmap& pixmap, + AHardwareBuffer* hardwareBuffer, + GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); + +/** + * Like SkImagePriv::SkMakeImageFromRasterBitmap, except this can be pinned using + * skgpu::ganesh::PinAsTexture and CopyPixelMode is never. + */ +SK_API sk_sp PinnableRasterFromBitmap(const SkBitmap&); + +} // namespace SkImages + +// TODO(kjlubick) remove this after Android has been ported. +namespace sk_image_factory { +inline sk_sp MakePinnableFromRasterBitmap(const SkBitmap& b) { + return SkImages::PinnableRasterFromBitmap(b); +} +} // namespace sk_image_factory + +namespace skgpu::ganesh { +/** + * Will attempt to upload and lock the contents of the image as a texture, so that subsequent + * draws to a gpu-target will come from that texture (and not by looking at the original image + * src). In particular this is intended to use the texture even if the image's original content + * changes subsequent to this call (i.e. the src is mutable!). + * + * Only compatible with SkImages created from SkImages::PinnableRasterFromBitmap. + * + * All successful calls must be balanced by an equal number of calls to UnpinTexture(). + * + * Once in this "pinned" state, the image has all of the same thread restrictions that exist + * for a natively created gpu image (e.g. SkImage::MakeFromTexture) + * - all drawing, pinning, unpinning must happen in the same thread as the GrContext. + * + * @return true if the image was successfully uploaded and locked into a texture + */ +bool PinAsTexture(GrRecordingContext*, SkImage*); + +/** + * The balancing call to a successful invocation of PinAsTexture. When a balanced + * number of calls have been made, then the "pinned" texture is free to be purged, etc. This + * also means that a subsequent "pin" call will look at the original content again, and if + * its uniqueID/generationID has changed, then a newer texture will be uploaded/pinned. + * + * Only compatible with SkImages created from SkImages::PinnableRasterFromBitmap. + * + * The context passed to unpin must match the one passed to pin. + */ +void UnpinTexture(GrRecordingContext*, SkImage*); + +} // namespace skgpu::ganesh + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h index 02625838308bd..2b8a79751cfd9 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h @@ -9,24 +9,27 @@ #define SkAndroidCodec_DEFINED #include "include/codec/SkCodec.h" -#include "include/core/SkAlphaType.h" #include "include/core/SkColorSpace.h" -#include "include/core/SkColorType.h" -#include "include/core/SkEncodedImageFormat.h" #include "include/core/SkImageInfo.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" #include "include/private/SkEncodedInfo.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/skcms/skcms.h" +// TODO(kjlubick, bungeman) Replace these includes with forward declares +#include "include/codec/SkEncodedImageFormat.h" // IWYU pragma: keep +#include "include/core/SkAlphaType.h" // IWYU pragma: keep +#include "include/core/SkColorType.h" // IWYU pragma: keep + #include #include class SkData; class SkPngChunkReader; class SkStream; +struct SkGainmapInfo; struct SkIRect; /** @@ -118,10 +121,8 @@ class SK_API SkAndroidCodec : SkNoncopyable { /** * @param outputColorType Color type that the client will decode to. * @param prefColorSpace Preferred color space to decode to. - * This may not return |prefColorSpace| for a couple reasons. - * (1) Android Principles: 565 must be sRGB, F16 must be - * linear sRGB, transfer function must be parametric. - * (2) Codec Limitations: F16 requires a linear color space. + * This may not return |prefColorSpace| for + * specific color types. * * Returns the appropriate color space to decode to. */ @@ -262,6 +263,23 @@ class SK_API SkAndroidCodec : SkNoncopyable { SkCodec* codec() const { return fCodec.get(); } + /** + * Retrieve the gainmap for an image. + * + * @param outInfo On success, this is populated with the parameters for + * rendering this gainmap. This parameter must be non-nullptr. + * + * @param outGainmapImageStream On success, this is populated with a stream from which the + * gainmap image may be decoded. This parameter is optional, and + * may be set to nullptr. + * + * @return If this has a gainmap image and that gainmap image was + * successfully extracted then return true. Otherwise return + * false. + */ + bool getAndroidGainmap(SkGainmapInfo* outInfo, + std::unique_ptr* outGainmapImageStream); + protected: SkAndroidCodec(SkCodec*); diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h index 5af847afcfe30..3ed1a95a800c9 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h @@ -8,10 +8,7 @@ #ifndef SkCodec_DEFINED #define SkCodec_DEFINED -#include "include/codec/SkCodecAnimation.h" #include "include/codec/SkEncodedOrigin.h" -#include "include/core/SkAlphaType.h" -#include "include/core/SkEncodedImageFormat.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" #include "include/core/SkRect.h" @@ -20,21 +17,30 @@ #include "include/core/SkTypes.h" #include "include/core/SkYUVAPixmaps.h" #include "include/private/SkEncodedInfo.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/skcms/skcms.h" #include +#include #include #include #include -class SkAndroidCodec; class SkData; class SkFrameHolder; class SkImage; class SkPngChunkReader; class SkSampler; class SkStream; +struct SkGainmapInfo; +enum SkAlphaType : int; +enum class SkEncodedImageFormat; + +namespace SkCodecAnimation { +enum class Blend; +enum class DisposalMethod; +} + namespace DM { class CodecSrc; @@ -767,6 +773,8 @@ class SK_API SkCodec : SkNoncopyable { return fSrcXformFormat; } + virtual bool onGetGainmapInfo(SkGainmapInfo*, std::unique_ptr*) { return false; } + virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const { // By default, scaling is not supported. return this->dimensions(); @@ -887,8 +895,8 @@ class SK_API SkCodec : SkNoncopyable { const SkEncodedInfo fEncodedInfo; XformFormat fSrcXformFormat; std::unique_ptr fStream; - bool fNeedsRewind; - const SkEncodedOrigin fOrigin; + bool fNeedsRewind = false; + const SkEncodedOrigin fOrigin; SkImageInfo fDstInfo; Options fOptions; @@ -904,13 +912,13 @@ class SK_API SkCodec : SkNoncopyable { skcms_AlphaFormat fDstXformAlphaFormat; // Only meaningful during scanline decodes. - int fCurrScanline; + int fCurrScanline = -1; - bool fStartedIncrementalDecode; + bool fStartedIncrementalDecode = false; // Allows SkAndroidCodec to call handleFrameIndex (potentially decoding a prior frame and - // clearing to transparent) without SkCodec calling it, too. - bool fAndroidCodecHandlesFrameIndex; + // clearing to transparent) without SkCodec itself calling it, too. + bool fUsingCallbackForHandleFrameIndex = false; bool initializeColorXform(const SkImageInfo& dstInfo, SkEncodedInfo::Alpha, bool srcIsOpaque); @@ -934,17 +942,23 @@ class SK_API SkCodec : SkNoncopyable { return nullptr; } + // Callback for decoding a prior frame. The `Options::fFrameIndex` is ignored, + // being replaced by frameIndex. This allows opts to actually be a subclass of + // SkCodec::Options which SkCodec itself does not know how to copy or modify, + // but just passes through to the caller (where it can be reinterpret_cast'd). + using GetPixelsCallback = std::function; + /** * Check for a valid Options.fFrameIndex, and decode prior frames if necessary. * - * If androidCodec is not null, that means this SkCodec is owned by an SkAndroidCodec. In that - * case, the Options will be treated as an AndroidOptions, and SkAndroidCodec will be used to - * decode a prior frame, if a prior frame is needed. When such an owned SkCodec calls - * handleFrameIndex, it will immediately return kSuccess, since SkAndroidCodec already handled - * it. + * If GetPixelsCallback is not null, it will be used to decode a prior frame instead + * of using this SkCodec directly. It may also be used recursively, if that in turn + * depends on a prior frame. This is used by SkAndroidCodec. */ Result handleFrameIndex(const SkImageInfo&, void* pixels, size_t rowBytes, const Options&, - SkAndroidCodec* androidCodec = nullptr); + GetPixelsCallback = nullptr); // Methods for scanline decoding. virtual Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/, diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h new file mode 100644 index 0000000000000..99ca44e765c53 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h @@ -0,0 +1,36 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkEncodedImageFormat_DEFINED +#define SkEncodedImageFormat_DEFINED + +#include + +/** + * Enum describing format of encoded data. + */ +enum class SkEncodedImageFormat { +#ifdef SK_BUILD_FOR_GOOGLE3 + kUnknown, +#endif + kBMP, + kGIF, + kICO, + kJPEG, + kPNG, + kWBMP, + kWEBP, + kPKM, + kKTX, + kASTC, + kDNG, + kHEIF, + kAVIF, + kJPEGXL, +}; + +#endif // SkEncodedImageFormat_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h new file mode 100644 index 0000000000000..0df4a36f0c247 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h @@ -0,0 +1,31 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkPixmapUtils_DEFINED +#define SkPixmapUtils_DEFINED + +#include "include/codec/SkEncodedOrigin.h" +#include "include/core/SkImageInfo.h" +#include "include/private/base/SkAPI.h" + +class SkPixmap; + +namespace SkPixmapUtils { +/** + * Copy the pixels in src into dst, applying the orientation transformations specified + * by origin. If the inputs are invalid, this returns false and no copy is made. + */ +SK_API bool Orient(const SkPixmap& dst, const SkPixmap& src, SkEncodedOrigin origin); + +/** + * Return a copy of the provided ImageInfo with the width and height swapped. + */ +SK_API SkImageInfo SwapWidthHeight(const SkImageInfo& info); + +} // namespace SkPixmapUtils + +#endif // SkPixmapUtils_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPngChunkReader.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkPngChunkReader.h similarity index 100% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPngChunkReader.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/codec/SkPngChunkReader.h diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h index 313d324e405b8..74c21f9438b9e 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h @@ -1,4 +1,3 @@ - /* * Copyright 2006 The Android Open Source Project * @@ -6,7 +5,6 @@ * found in the LICENSE file. */ - #ifndef SkUserConfig_DEFINED #define SkUserConfig_DEFINED @@ -16,9 +14,9 @@ Below are optional defines that add, subtract, or change default behavior in Skia. Your port can locally edit this file to enable/disable flags as - you choose, or these can be delared on your command line (i.e. -Dfoo). + you choose, or these can be declared on your command line (i.e. -Dfoo). - By default, this include file will always default to having all of the flags + By default, this #include file will always default to having all the flags commented out, so including it will have no effect. */ @@ -32,58 +30,92 @@ By default, these mutually exclusive flags are defined in SkTypes.h, based on the presence or absence of NDEBUG, but that decision can be changed here. - */ +*/ //#define SK_DEBUG //#define SK_RELEASE /* To write debug messages to a console, skia will call SkDebugf(...) following printf conventions (e.g. const char* format, ...). If you want to redirect this to something other than printf, define yours here - */ +*/ //#define SkDebugf(...) MyFunction(__VA_ARGS__) -/* - * To specify a different default font cache limit, define this. If this is - * undefined, skia will use a built-in value. - */ +/* Skia has both debug and release asserts. When an assert fails SK_ABORT will + be used to report an abort message. SK_ABORT is expected not to return. Skia + provides a default implementation which will print the message with SkDebugf + and then call sk_abort_no_print. +*/ +//#define SK_ABORT(message, ...) + +/* To specify a different default font strike cache memory limit, define this. If this is + undefined, skia will use a built-in value. +*/ //#define SK_DEFAULT_FONT_CACHE_LIMIT (1024 * 1024) -/* - * To specify the default size of the image cache, undefine this and set it to - * the desired value (in bytes). SkGraphics.h as a runtime API to set this - * value as well. If this is undefined, a built-in value will be used. - */ +/* To specify a different default font strike cache count limit, define this. If this is + undefined, skia will use a built-in value. +*/ +// #define SK_DEFAULT_FONT_CACHE_COUNT_LIMIT 2048 + +/* To specify the default size of the image cache, undefine this and set it to + the desired value (in bytes). SkGraphics.h as a runtime API to set this + value as well. If this is undefined, a built-in value will be used. +*/ //#define SK_DEFAULT_IMAGE_CACHE_LIMIT (1024 * 1024) /* Define this to set the upper limit for text to support LCD. Values that are very large increase the cost in the font cache and draw slower, without improving readability. If this is undefined, Skia will use its default value (e.g. 48) - */ +*/ //#define SK_MAX_SIZE_FOR_LCDTEXT 48 /* Change the kN32_SkColorType ordering to BGRA to work in X windows. - */ +*/ //#define SK_R32_SHIFT 16 - -/* Determines whether to build code that supports the GPU backend. Some classes +/* Determines whether to build code that supports the Ganesh GPU backend. Some classes that are not GPU-specific, such as SkShader subclasses, have optional code - that is used allows them to interact with the GPU backend. If you'd like to - omit this code set SK_SUPPORT_GPU to 0. This also allows you to omit the gpu - directories from your include search path when you're not building the GPU - backend. Defaults to 1 (build the GPU code). - */ -//#define SK_SUPPORT_GPU 1 + that is used allows them to interact with this GPU backend. If you'd like to + include this code, include -DSK_GANESH in your cflags or uncomment below. + Defaults to not set (No Ganesh GPU backend). + This define affects the ABI of Skia, so make sure it matches the client which uses + the compiled version of Skia. +*/ +//#define SK_GANESH /* Skia makes use of histogram logging macros to trace the frequency of - * events. By default, Skia provides no-op versions of these macros. - * Skia consumers can provide their own definitions of these macros to - * integrate with their histogram collection backend. - */ + events. By default, Skia provides no-op versions of these macros. + Skia consumers can provide their own definitions of these macros to + integrate with their histogram collection backend. +*/ //#define SK_HISTOGRAM_BOOLEAN(name, sample) //#define SK_HISTOGRAM_ENUMERATION(name, sample, enum_size) //#define SK_HISTOGRAM_EXACT_LINEAR(name, sample, value_max) //#define SK_HISTOGRAM_MEMORY_KB(name, sample) +/* Skia tries to make use of some non-standard C++ language extensions. + By default, Skia provides msvc and clang/gcc versions of these macros. + Skia consumers can provide their own definitions of these macros to + integrate with their own compilers and build system. +*/ +//#define SK_UNUSED [[maybe_unused]] +//#define SK_WARN_UNUSED_RESULT [[nodiscard]] +//#define SK_ALWAYS_INLINE inline __attribute__((always_inline)) +//#define SK_NEVER_INLINE __attribute__((noinline)) +//#define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) +//#define SK_NO_SANITIZE(A) __attribute__((no_sanitize(A))) +//#define SK_TRIVIAL_ABI [[clang::trivial_abi]] + +/* + * If compiling Skia as a DLL, public APIs should be exported. Skia will set + * SK_API to something sensible for Clang and MSVC, but if clients need to + * customize it for their build system or compiler, they may. + * If a client needs to use SK_API (e.g. overriding SK_ABORT), then they + * *must* define their own, the default will not be defined prior to loading + * this file. + */ +//#define SK_API __declspec(dllexport) + + #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h index 658f20716e7e5..d4ed7a6000b7a 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h @@ -8,24 +8,32 @@ #ifndef SkBitmap_DEFINED #define SkBitmap_DEFINED +#include "include/core/SkAlphaType.h" #include "include/core/SkColor.h" #include "include/core/SkImageInfo.h" -#include "include/core/SkMatrix.h" #include "include/core/SkPixmap.h" #include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/core/SkShader.h" -#include "include/core/SkTileMode.h" +#include "include/core/SkSamplingOptions.h" +#include "include/core/SkSize.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkDebug.h" + +#include +#include -class SkBitmap; class SkColorSpace; -struct SkMask; +class SkImage; +class SkMatrix; class SkMipmap; -struct SkIRect; -struct SkRect; class SkPaint; class SkPixelRef; class SkShader; +enum SkColorType : int; +enum class SkTileMode; +struct SkMask; /** \class SkBitmap SkBitmap describes a two-dimensional raster pixel array. SkBitmap is built on @@ -766,11 +774,10 @@ class SK_API SkBitmap { treated as opaque. If colorType() is kAlpha_8_SkColorType, then RGB is ignored. @param c unpremultiplied color - @param colorSpace SkColorSpace of c example: https://fiddle.skia.org/c/@Bitmap_eraseColor */ - void eraseColor(SkColor4f c, SkColorSpace* colorSpace = nullptr) const; + void eraseColor(SkColor4f) const; /** Replaces pixel values with c, interpreted as being in the sRGB SkColorSpace. All pixels contained by bounds() are affected. If the colorType() is @@ -810,11 +817,9 @@ class SK_API SkBitmap { @param c unpremultiplied color @param area rectangle to fill - @param colorSpace SkColorSpace of c example: https://fiddle.skia.org/c/@Bitmap_erase */ - void erase(SkColor4f c, SkColorSpace* colorSpace, const SkIRect& area) const; void erase(SkColor4f c, const SkIRect& area) const; /** Replaces pixel values inside area with c. interpreted as being in the sRGB @@ -1168,23 +1173,18 @@ class SK_API SkBitmap { example: https://fiddle.skia.org/c/@Bitmap_peekPixels */ bool peekPixels(SkPixmap* pixmap) const; - sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, - const SkMatrix* = nullptr) const; + /** + * Make a shader with the specified tiling, matrix and sampling. + */ + sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, + const SkMatrix* localMatrix = nullptr) const; sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& localMatrix) const { - return this->makeShader(tmx, tmy, sampling, &localMatrix); - } - - sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix* localMatrix = nullptr) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, localMatrix); - } - + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix& localMatrix) const { - return this->makeShader(sampling, &localMatrix); - } + const SkMatrix* lm = nullptr) const; /** * Returns a new image from the bitmap. If the bitmap is marked immutable, this will diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h index aec37b6e686de..f0dde10f25c6b 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h @@ -8,8 +8,6 @@ #ifndef SkBlurTypes_DEFINED #define SkBlurTypes_DEFINED -#include "include/core/SkTypes.h" - enum SkBlurStyle : int { kNormal_SkBlurStyle, //!< fuzzy inside and outside kSolid_SkBlurStyle, //!< solid inside, fuzzy outside diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h index b16872809e322..225b733a6b717 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h @@ -12,6 +12,7 @@ #include "include/core/SkClipOp.h" #include "include/core/SkColor.h" #include "include/core/SkFontTypes.h" +#include "include/core/SkImageFilter.h" #include "include/core/SkImageInfo.h" #include "include/core/SkM44.h" #include "include/core/SkMatrix.h" @@ -26,13 +27,13 @@ #include "include/core/SkString.h" #include "include/core/SkSurfaceProps.h" #include "include/core/SkTypes.h" -#include "include/private/SkDeque.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkDeque.h" +#include #include #include #include -#include #ifndef SK_SUPPORT_LEGACY_GETTOTALMATRIX #define SK_SUPPORT_LEGACY_GETTOTALMATRIX @@ -44,34 +45,39 @@ class GlyphRunList; } class AutoLayerForImageFilter; -class GrBackendRenderTarget; class GrRecordingContext; + class SkBaseDevice; class SkBitmap; +class SkBlender; class SkData; class SkDrawable; -struct SkDrawShadowRec; class SkFont; class SkImage; -class SkImageFilter; +class SkMesh; class SkPaintFilterCanvas; class SkPath; class SkPicture; class SkPixmap; -class SkRegion; class SkRRect; -struct SkRSXform; -class SkMesh; +class SkRegion; +class SkShader; class SkSpecialImage; class SkSurface; class SkSurface_Base; class SkTextBlob; class SkVertices; +struct SkDrawShadowRec; +struct SkRSXform; namespace skgpu::graphite { class Recorder; } namespace sktext::gpu { class Slug; } namespace SkRecords { class Draw; } +#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_GANESH) +class GrBackendRenderTarget; +#endif + // TODO: // This is not ideal but Chrome is depending on a forward decl of GrSlug here. // It should be removed once Chrome has migrated to sktext::gpu::Slug. @@ -650,7 +656,7 @@ class SK_API SkCanvas { SkRect bounds suggests but does not define layer size. To clip drawing to a specific rectangle, use clipRect(). - alpha of zero is fully transparent, 255 is fully opaque. + alpha of zero is fully transparent, 1.0f is fully opaque. Call restoreToCount() with returned value to restore this and subsequent saves. @@ -660,7 +666,11 @@ class SK_API SkCanvas { example: https://fiddle.skia.org/c/@Canvas_saveLayerAlpha */ - int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); + int saveLayerAlphaf(const SkRect* bounds, float alpha); + // Helper that accepts an int between 0 and 255, and divides it by 255.0 + int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { + return this->saveLayerAlphaf(bounds, alpha * (1.0f / 255)); + } /** \enum SkCanvas::SaveLayerFlagsSet SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, @@ -2173,7 +2183,7 @@ class SK_API SkCanvas { /////////////////////////////////////////////////////////////////////////// -#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && SK_SUPPORT_GPU +#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_GANESH) // These methods exist to support WebView in Android Framework. SkIRect topLayerBounds() const; GrBackendRenderTarget topLayerBackendRenderTarget() const; @@ -2290,7 +2300,7 @@ class SK_API SkCanvas { virtual void onDiscard(); -#if (SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED)) +#if (defined(SK_GANESH) || defined(SK_GRAPHITE)) /** Experimental */ virtual sk_sp onConvertGlyphRunListToSlug( @@ -2352,6 +2362,13 @@ class SK_API SkCanvas { // Encapsulate state needed to restore from saveBehind() struct BackImage { + // Out of line to avoid including SkSpecialImage.h + BackImage(sk_sp, SkIPoint); + BackImage(const BackImage&); + BackImage(BackImage&&); + BackImage& operator=(const BackImage&); + ~BackImage(); + sk_sp fImage; SkIPoint fLoc; }; @@ -2406,7 +2423,7 @@ class SK_API SkCanvas { fSurfaceBase = sb; } friend class SkSurface_Base; - friend class SkSurface_Gpu; + friend class SkSurface_Ganesh; SkIRect fClipRestrictionRect = SkIRect::MakeEmpty(); int fClipRestrictionSaveCount = -1; @@ -2440,7 +2457,7 @@ class SK_API SkCanvas { SkCanvas& operator=(SkCanvas&&) = delete; SkCanvas& operator=(const SkCanvas&) = delete; -#if (SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED)) +#if (defined(SK_GANESH) || defined(SK_GRAPHITE)) friend class sktext::gpu::Slug; /** Experimental * Convert a SkTextBlob to a sktext::gpu::Slug using the current canvas state. diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h index ef15c1670823d..214b5138f0b71 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h @@ -15,7 +15,7 @@ namespace SkSL { struct ShaderCaps; } #endif -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) namespace skgpu::graphite { class Caps; } #endif @@ -28,7 +28,7 @@ class SK_API SkCapabilities : public SkRefCnt { #endif protected: -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) friend class skgpu::graphite::Caps; // for ctor #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h index 6a920e93fddb4..3b46be030f224 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h @@ -11,8 +11,10 @@ #include "include/core/SkAlphaType.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" #include +#include /** \file SkColor.h diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h index 29f64339baaac..f89de9db72fcb 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h @@ -9,9 +9,11 @@ #define SkColorPriv_DEFINED #include "include/core/SkColor.h" -#include "include/core/SkMath.h" -#include "include/private/SkTPin.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkTPin.h" +#include "include/private/base/SkTo.h" + +#include /** Turn 0..255 into 0..256 by adding 1 at the half-way point. Used to turn a byte into a scale value, so that we can say scale * value >> 8 instead of @@ -146,7 +148,20 @@ static SK_ALWAYS_INLINE uint32_t SkAlphaMulQ(uint32_t c, unsigned scale) { } static inline SkPMColor SkPMSrcOver(SkPMColor src, SkPMColor dst) { - return src + SkAlphaMulQ(dst, SkAlpha255To256(255 - SkGetPackedA32(src))); + uint32_t scale = SkAlpha255To256(255 - SkGetPackedA32(src)); + + uint32_t mask = 0xFF00FF; + uint32_t rb = (((dst & mask) * scale) >> 8) & mask; + uint32_t ag = (((dst >> 8) & mask) * scale) & ~mask; + + rb += (src & mask); + ag += (src & ~mask); + + // Color channels (but not alpha) can overflow, so we have to saturate to 0xFF in each lane. + return std::min(rb & 0x000001FF, 0x000000FFU) | + std::min(ag & 0x0001FF00, 0x0000FF00U) | + std::min(rb & 0x01FF0000, 0x00FF0000U) | + (ag & 0xFF000000); } #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h index a09758645b161..57c29e222a43b 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h @@ -9,10 +9,13 @@ #define SkColorSpace_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkFixed.h" -#include "include/private/SkOnce.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkFixed.h" +#include "include/private/base/SkOnce.h" #include "modules/skcms/skcms.h" -#include + +#include +#include class SkData; @@ -147,8 +150,7 @@ class SK_API SkColorSpace : public SkNVRefCnt { bool isNumericalTransferFn(skcms_TransferFunction* fn) const; /** - * Returns true and sets |toXYZD50| if the color gamut can be described as a matrix. - * Returns false otherwise. + * Returns true and sets |toXYZD50|. */ bool toXYZD50(skcms_Matrix3x3* toXYZD50) const; @@ -160,23 +162,19 @@ class SK_API SkColorSpace : public SkNVRefCnt { /** * Returns a color space with the same gamut as this one, but with a linear gamma. - * For color spaces whose gamut can not be described in terms of XYZ D50, returns - * linear sRGB. */ sk_sp makeLinearGamma() const; /** - * Returns a color space with the same gamut as this one, with with the sRGB transfer - * function. For color spaces whose gamut can not be described in terms of XYZ D50, returns - * sRGB. + * Returns a color space with the same gamut as this one, but with the sRGB transfer + * function. */ sk_sp makeSRGBGamma() const; /** * Returns a color space with the same transfer function as this one, but with the primary - * colors rotated. For any XYZ space, this produces a new color space that maps RGB to GBR - * (when applied to a source), and maps RGB to BRG (when applied to a destination). For other - * types of color spaces, returns nullptr. + * colors rotated. In other words, this produces a new color space that maps RGB to GBR + * (when applied to a source), and maps RGB to BRG (when applied to a destination). * * This is used for testing, to construct color spaces that have severe and testable behavior. */ @@ -190,15 +188,14 @@ class SK_API SkColorSpace : public SkNVRefCnt { * in some cases: converting ICC fixed point to float, converting white point to D50, * rounding decisions on transfer function and matrix. * - * This does not consider a 2.2f exponential transfer function to be sRGB. While these + * This does not consider a 2.2f exponential transfer function to be sRGB. While these * functions are similar (and it is sometimes useful to consider them together), this * function checks for logical equality. */ bool isSRGB() const; /** - * Returns nullptr on failure. Fails when we fallback to serializing ICC data and - * the data is too large to serialize. + * Returns a serialized representation of this color space. */ sk_sp serialize() const; @@ -211,7 +208,7 @@ class SK_API SkColorSpace : public SkNVRefCnt { static sk_sp Deserialize(const void* data, size_t length); /** - * If both are null, we return true. If one is null and the other is not, we return false. + * If both are null, we return true. If one is null and the other is not, we return false. * If both are non-null, we do a deeper compare. */ static bool Equals(const SkColorSpace*, const SkColorSpace*); diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h index b51aa7b96f96b..a68dc833b49b5 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h @@ -28,6 +28,7 @@ enum SkColorType : int { kBGRA_1010102_SkColorType, //!< 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word kRGB_101010x_SkColorType, //!< pixel with 10 bits each for red, green, blue; in 32-bit word kBGR_101010x_SkColorType, //!< pixel with 10 bits each for blue, green, red; in 32-bit word + kBGR_101010x_XR_SkColorType, //!< pixel with 10 bits each for blue, green, red; in 32-bit word, extended range kGray_8_SkColorType, //!< pixel with grayscale level in 8-bit byte kRGBA_F16Norm_SkColorType, //!< pixel with half floats in [0,1] for red, green, blue, alpha; // in 64-bit word diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h index 08a50b11054c8..7090deaaed22a 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h @@ -10,7 +10,7 @@ #include "include/core/SkPath.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" struct SkConic; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h index ea5b73d1a4776..aaae60c41920d 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h @@ -8,8 +8,6 @@ #ifndef SkCoverageMode_DEFINED #define SkCoverageMode_DEFINED -#include "include/core/SkTypes.h" - /** * Describes geometric operations (ala SkRegion::Op) that can be applied to coverage bytes. * These can be thought of as variants of porter-duff (SkBlendMode) modes, but only applied diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h index 7389b92afd099..863c9333f6e1e 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h @@ -9,6 +9,8 @@ #define SkCubicMap_DEFINED #include "include/core/SkPoint.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" /** * Fast evaluation of a cubic ease-in / ease-out curve. This is defined as a parametric cubic diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkData.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkData.h index 2a4b40d5f614a..2b50cebc81b6a 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkData.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkData.h @@ -8,9 +8,12 @@ #ifndef SkData_DEFINED #define SkData_DEFINED -#include - #include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" + +#include +#include class SkStream; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h index a6a510b7b221e..3aa48d5f33ea0 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h @@ -8,8 +8,12 @@ #ifndef SkDataTable_DEFINED #define SkDataTable_DEFINED -#include "include/core/SkData.h" -#include "include/private/SkTDArray.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" + +#include +#include /** * Like SkData, SkDataTable holds an immutable data buffer. The data buffer is diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h index 28e460fa8b050..e5511beea3aea 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h @@ -13,10 +13,11 @@ #include "include/core/SkTypes.h" class SkDeferredDisplayListPriv; +class SkPromiseImageTexture; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrRecordingContext.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include class GrRenderTask; class GrRenderTargetProxy; @@ -36,7 +37,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { return fCharacterization; } -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** * Iterate through the programs required by the DDL. */ @@ -52,7 +53,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { private: GrDirectContext* fDContext; - const SkTArray& fProgramData; + const skia_private::TArray& fProgramData; int fIndex; }; #endif @@ -70,7 +71,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { // texture when the DDL is replayed. It has to be separately ref counted bc the lazy proxy // can outlive the DDL. class LazyProxyData : public SkRefCnt { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) public: // Upon being replayed - this field will be filled in (by the DrawingManager) with the // proxy backing the destination SkSurface. Note that, since there is no good place to @@ -87,21 +88,21 @@ class SkDeferredDisplayList : public SkNVRefCnt { sk_sp fTargetProxy, sk_sp); -#if SK_SUPPORT_GPU - const SkTArray& programData() const { +#if defined(SK_GANESH) + const skia_private::TArray& programData() const { return fProgramData; } #endif const SkSurfaceCharacterization fCharacterization; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) // These are ordered such that the destructor cleans op tasks up first (which may refer back // to the arena and memory pool in their destructors). GrRecordingContext::OwnedArenas fArenas; - SkTArray> fRenderTasks; + skia_private::TArray> fRenderTasks; - SkTArray fProgramData; + skia_private::TArray fProgramData; sk_sp fTargetProxy; sk_sp fLazyProxyData; #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h index 8103485597fcf..cd91798513bdf 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h @@ -50,13 +50,14 @@ class SK_API SkDeferredDisplayListRecorder { sk_sp detach(); -#if SK_SUPPORT_GPU - using PromiseImageTextureContext = SkImage::PromiseImageTextureContext; - using PromiseImageTextureFulfillProc = SkImage::PromiseImageTextureFulfillProc; - using PromiseImageTextureReleaseProc = SkImage::PromiseImageTextureReleaseProc; +#if defined(SK_GANESH) + using PromiseImageTextureContext = void*; + using PromiseImageTextureFulfillProc = + sk_sp (*)(PromiseImageTextureContext); + using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); #ifndef SK_MAKE_PROMISE_TEXTURE_DISABLE_LEGACY_API - /** Deprecated: Use SkImage::MakePromiseTexture instead. */ + /** Deprecated: Use SkImages::PromiseTextureFrom instead. */ sk_sp makePromiseTexture(const GrBackendFormat& backendFormat, int width, int height, @@ -69,14 +70,14 @@ class SK_API SkDeferredDisplayListRecorder { PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContext); - /** Deprecated: Use SkImage::MakePromiseYUVATexture instead. */ + /** Deprecated: Use SkImages::PromiseTextureFromYUVA instead. */ sk_sp makeYUVAPromiseTexture(const GrYUVABackendTextureInfo& yuvaBackendTextureInfo, sk_sp imageColorSpace, PromiseImageTextureFulfillProc textureFulfillProc, PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContexts[]); #endif // SK_MAKE_PROMISE_TEXTURE_DISABLE_LEGACY_API -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) private: SkDeferredDisplayListRecorder(const SkDeferredDisplayListRecorder&) = delete; @@ -86,7 +87,7 @@ class SK_API SkDeferredDisplayListRecorder { const SkSurfaceCharacterization fCharacterization; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) sk_sp fContext; sk_sp fTargetProxy; sk_sp fLazyProxyData; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h index c86543dc6b367..316bf058bcf5a 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h @@ -9,14 +9,22 @@ #define SkDrawable_DEFINED #include "include/core/SkFlattenable.h" -#include "include/core/SkImageInfo.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" +#include "include/private/base/SkAPI.h" + +#include +#include +#include class GrBackendDrawableInfo; class SkCanvas; class SkMatrix; class SkPicture; -enum class GrBackendApi : unsigned; +enum class GrBackendApi : unsigned int; +struct SkDeserialProcs; +struct SkIRect; +struct SkImageInfo; struct SkRect; /** diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h index 99ca44e765c53..0db3830b9ac71 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h @@ -1,36 +1,9 @@ /* - * Copyright 2015 Google Inc. + * Copyright 2023 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#ifndef SkEncodedImageFormat_DEFINED -#define SkEncodedImageFormat_DEFINED - -#include - -/** - * Enum describing format of encoded data. - */ -enum class SkEncodedImageFormat { -#ifdef SK_BUILD_FOR_GOOGLE3 - kUnknown, -#endif - kBMP, - kGIF, - kICO, - kJPEG, - kPNG, - kWBMP, - kWEBP, - kPKM, - kKTX, - kASTC, - kDNG, - kHEIF, - kAVIF, - kJPEGXL, -}; - -#endif // SkEncodedImageFormat_DEFINED +// TODO(kjlubick) remove this shim after clients have been moved to the new location +#include "include/codec/SkEncodedImageFormat.h" // IWYU pragma: export diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h index 916ee174f4828..3585e845b5489 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h @@ -9,13 +9,15 @@ #define SkFlattenable_DEFINED #include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +#include class SkData; class SkReadBuffer; class SkWriteBuffer; - -struct SkSerialProcs; struct SkDeserialProcs; +struct SkSerialProcs; /** \class SkFlattenable diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h index 05fb7db414887..88e92694bd455 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h @@ -11,6 +11,7 @@ #include "include/core/SkFontTypes.h" #include "include/core/SkScalar.h" #include "include/core/SkTypeface.h" +#include "include/private/base/SkTemplates.h" #include diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h index 717a87f056f38..f4960393113cb 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h @@ -9,6 +9,7 @@ #define SkFontMetrics_DEFINED #include "include/core/SkScalar.h" +#include "include/private/base/SkTo.h" /** \class SkFontMetrics The metrics of an SkFont. diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h index 125262b466753..eccb0a729cba0 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h @@ -13,6 +13,8 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkTypes.h" +#include + class SkData; class SkFontData; class SkStreamAsset; @@ -23,23 +25,20 @@ class SK_API SkFontStyleSet : public SkRefCnt { public: virtual int count() = 0; virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0; - virtual SkTypeface* createTypeface(int index) = 0; - virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0; + virtual sk_sp createTypeface(int index) = 0; + virtual sk_sp matchStyle(const SkFontStyle& pattern) = 0; - static SkFontStyleSet* CreateEmpty(); + static sk_sp CreateEmpty(); protected: - SkTypeface* matchStyleCSS3(const SkFontStyle& pattern); - -private: - using INHERITED = SkRefCnt; + sk_sp matchStyleCSS3(const SkFontStyle& pattern); }; class SK_API SkFontMgr : public SkRefCnt { public: int countFamilies() const; void getFamilyName(int index, SkString* familyName) const; - SkFontStyleSet* createStyleSet(int index) const; + sk_sp createStyleSet(int index) const; /** * The caller must call unref() on the returned object. @@ -52,7 +51,7 @@ class SK_API SkFontMgr : public SkRefCnt { * It is possible that this will return a style set not accessible from * createStyleSet(int) due to hidden or auto-activated fonts. */ - SkFontStyleSet* matchFamily(const char familyName[]) const; + sk_sp matchFamily(const char familyName[]) const; /** * Find the closest matching typeface to the specified familyName and style @@ -66,7 +65,7 @@ class SK_API SkFontMgr : public SkRefCnt { * createStyleSet(int) or matchFamily(const char[]) due to hidden or * auto-activated fonts. */ - SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&) const; + sk_sp matchFamilyStyle(const char familyName[], const SkFontStyle&) const; /** * Use the system fallback to find a typeface for the given character. @@ -83,9 +82,9 @@ class SK_API SkFontMgr : public SkRefCnt { * most significant. If no specified bcp47 codes match, any font with the * requested character will be matched. */ - SkTypeface* matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const; + sk_sp matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const; /** * Create a typeface for the specified data and TTC index (pass 0 for none) @@ -123,16 +122,17 @@ class SK_API SkFontMgr : public SkRefCnt { protected: virtual int onCountFamilies() const = 0; virtual void onGetFamilyName(int index, SkString* familyName) const = 0; - virtual SkFontStyleSet* onCreateStyleSet(int index)const = 0; + virtual sk_sp onCreateStyleSet(int index)const = 0; /** May return NULL if the name is not found. */ - virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const = 0; + virtual sk_sp onMatchFamily(const char familyName[]) const = 0; - virtual SkTypeface* onMatchFamilyStyle(const char familyName[], - const SkFontStyle&) const = 0; - virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const = 0; + virtual sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle&) const = 0; + virtual sk_sp onMatchFamilyStyleCharacter(const char familyName[], + const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const = 0; virtual sk_sp onMakeFromData(sk_sp, int ttcIndex) const = 0; virtual sk_sp onMakeFromStreamIndex(std::unique_ptr, @@ -143,18 +143,9 @@ class SK_API SkFontMgr : public SkRefCnt { virtual sk_sp onLegacyMakeTypeface(const char familyName[], SkFontStyle) const = 0; - // this method is never called -- will be removed - virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, - const SkFontStyle&) const { - return nullptr; - } - private: - /** Implemented by porting layer to return the default factory. */ static sk_sp Factory(); - - using INHERITED = SkRefCnt; }; #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h index 04893ef2fdc59..be46b53bb2852 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h @@ -9,7 +9,9 @@ #define SkFontStyle_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkTPin.h" +#include "include/private/base/SkTPin.h" + +#include class SK_API SkFontStyle { public: @@ -75,6 +77,7 @@ class SK_API SkFontStyle { } private: + friend class SkTypefaceProxyPrototype; // To serialize fValue int32_t fValue; }; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h index c24bb742e71df..6ce9175d1e091 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h @@ -10,9 +10,12 @@ #include "include/core/SkRefCnt.h" +#include + class SkData; class SkImageGenerator; class SkOpenTypeSVGDecoder; +class SkPath; class SkTraceMemoryDump; class SK_API SkGraphics { @@ -115,16 +118,6 @@ class SK_API SkGraphics { */ static void PurgeAllCaches(); - /** - * Applications with command line options may pass optional state, such - * as cache sizes, here, for instance: - * font-cache-limit=12345678 - * - * The flags format is name=value[;name=value...] with no spaces. - * This format is subject to change. - */ - static void SetFlags(const char* flags); - typedef std::unique_ptr (*ImageGeneratorFromEncodedDataFactory)(sk_sp); @@ -151,18 +144,28 @@ class SK_API SkGraphics { static OpenTypeSVGDecoderFactory GetOpenTypeSVGDecoderFactory(); /** - * Temporarily (until variable COLRv1 is released) pass a feature switch function for whether - * variable COLRv1 is enabled. Needed for initializing FreeType with a property setting so that - * variable COLRv1 can be enabled in Chrome Canaries during development. + * Call early in main() to allow Skia to use a JIT to accelerate CPU-bound operations. */ - using VariableColrV1EnabledFunc = bool (*)(); - static VariableColrV1EnabledFunc SetVariableColrV1EnabledFunc(VariableColrV1EnabledFunc); - static bool GetVariableColrV1Enabled(); + static void AllowJIT(); /** - * Call early in main() to allow Skia to use a JIT to accelerate CPU-bound operations. + * To override the default AA algorithm choice in the CPU backend, provide a function that + * returns whether to use analytic (true) or supersampled (false) for a given path. + * + * NOTE: This is a temporary API, intended for migration of all clients to one algorithm, + * and should not be used. */ - static void AllowJIT(); + typedef bool (*PathAnalyticAADeciderProc)(const SkPath&); + static void SetPathAnalyticAADecider(PathAnalyticAADeciderProc); + + /* + * Similar to above, but simply forces the CPU backend to always use analytic AA. + * + * NOTE: This is a temporary API, intended for migration of all clients to one algorithm. + * If the PathAnalyticAADeciderProc is *also* set, this setting has no effect. + * Unlike that API, this function is thread-safe. + */ + static void SetForceAnalyticAA(bool); }; class SkAutoGraphics { diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h index cb84c1ffbc76d..c0b458100cf88 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h @@ -1,19 +1,9 @@ /* - * Copyright 2016 Google Inc. + * Copyright 2023 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#ifndef SkICC_DEFINED -#define SkICC_DEFINED - -#include "include/core/SkData.h" - -struct skcms_Matrix3x3; -struct skcms_TransferFunction; - -SK_API sk_sp SkWriteICCProfile(const skcms_TransferFunction&, - const skcms_Matrix3x3& toXYZD50); - -#endif//SkICC_DEFINED +// TODO(kjlubick) remove this shim after clients have been moved to the new location +#include "include/encode/SkICC.h" // IWYU pragma: export diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h index 4157eafa0b509..8f7d4a46bd9d9 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h @@ -8,581 +8,252 @@ #ifndef SkImage_DEFINED #define SkImage_DEFINED +#include "include/core/SkAlphaType.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/core/SkSamplingOptions.h" -#include "include/core/SkScalar.h" -#include "include/core/SkShader.h" -#include "include/core/SkSurfaceProps.h" -#include "include/core/SkTileMode.h" -#if SK_SUPPORT_GPU -#include "include/gpu/GrTypes.h" -#endif -#if defined(SK_GRAPHITE_ENABLED) +#include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" + +#if defined(SK_GRAPHITE) #include "include/gpu/graphite/GraphiteTypes.h" +class SkYUVAPixmaps; #endif -#include // std::function -#include -#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 -#include -#endif +#include +#include +#include +#include -class GrBackendFormat; -class GrBackendTexture; -class GrContextThreadSafeProxy; class GrDirectContext; class GrRecordingContext; -class GrYUVABackendTextureInfo; -class GrYUVABackendTextures; -class SkCanvas; +class SkBitmap; +class SkColorSpace; class SkData; class SkImage; class SkImageFilter; class SkImageGenerator; +class SkMatrix; class SkMipmap; class SkPaint; class SkPicture; class SkPixmap; -class SkPromiseImageTexture; -class SkSurface; -class SkYUVAPixmaps; +class SkShader; +class SkSurfaceProps; +enum SkColorType : int; +enum class SkTextureCompressionType; +enum class SkTileMode; -enum class SkEncodedImageFormat; +struct SkIPoint; +struct SkSamplingOptions; -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) namespace skgpu::graphite { class BackendTexture; class Recorder; -}; +class TextureInfo; +enum class Volatile : bool; +class YUVABackendTextures; +} #endif -/** \class SkImage - SkImage describes a two dimensional array of pixels to draw. The pixels may be - decoded in a raster bitmap, encoded in a SkPicture or compressed data stream, - or located in GPU memory as a GPU texture. - - SkImage cannot be modified after it is created. SkImage may allocate additional - storage as needed; for instance, an encoded SkImage may decode when drawn. +namespace SkImages { - SkImage width and height are greater than zero. Creating an SkImage with zero width - or height returns SkImage equal to nullptr. - - SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams, - GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported - include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details - vary with platform. +/** Caller data passed to RasterReleaseProc; may be nullptr. */ +using ReleaseContext = void*; +/** Function called when SkImage no longer shares pixels. ReleaseContext is + provided by caller when SkImage is created, and may be nullptr. */ -class SK_API SkImage : public SkRefCnt { -public: - - /** Caller data passed to RasterReleaseProc; may be nullptr. - */ - typedef void* ReleaseContext; - - /** Creates SkImage from SkPixmap and copy of pixels. Since pixels are copied, SkPixmap - pixels may be modified or deleted without affecting SkImage. - - SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param pixmap SkImageInfo, pixel address, and row bytes - @return copy of SkPixmap pixels, or nullptr +using RasterReleaseProc = void(const void* pixels, ReleaseContext); - example: https://fiddle.skia.org/c/@Image_MakeRasterCopy - */ - static sk_sp MakeRasterCopy(const SkPixmap& pixmap); - - /** Creates SkImage from SkImageInfo, sharing pixels. +/** Creates a CPU-backed SkImage from bitmap, sharing or copying bitmap pixels. If the bitmap + is marked immutable, and its pixel memory is shareable, it may be shared + instead of copied. - SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - rowBytes are large enough to hold one row of pixels; - pixels is not nullptr, and contains enough data for SkImage. - - @param info contains width, height, SkAlphaType, SkColorType, SkColorSpace - @param pixels address or pixel storage - @param rowBytes size of pixel row or larger - @return SkImage sharing pixels, or nullptr - */ - static sk_sp MakeRasterData(const SkImageInfo& info, sk_sp pixels, - size_t rowBytes); + SkImage is returned if bitmap is valid. Valid SkBitmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. - /** Function called when SkImage no longer shares pixels. ReleaseContext is - provided by caller when SkImage is created, and may be nullptr. - */ - typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext); - - /** Creates SkImage from pixmap, sharing SkPixmap pixels. Pixels must remain valid and - unchanged until rasterReleaseProc is called. rasterReleaseProc is passed - releaseContext when SkImage is deleted or no longer refers to pixmap pixels. - - Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback - when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc - does not require state. - - SkImage is returned if pixmap is valid. Valid SkPixmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param pixmap SkImageInfo, pixel address, and row bytes - @param rasterReleaseProc function called when pixels can be released; or nullptr - @param releaseContext state passed to rasterReleaseProc; or nullptr - @return SkImage sharing pixmap - */ - static sk_sp MakeFromRaster(const SkPixmap& pixmap, - RasterReleaseProc rasterReleaseProc, - ReleaseContext releaseContext); - - /** Creates SkImage from bitmap, sharing or copying bitmap pixels. If the bitmap - is marked immutable, and its pixel memory is shareable, it may be shared - instead of copied. - - SkImage is returned if bitmap is valid. Valid SkBitmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param bitmap SkImageInfo, row bytes, and pixels - @return created SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_MakeFromBitmap - */ - static sk_sp MakeFromBitmap(const SkBitmap& bitmap); - - /** Creates SkImage from data returned by imageGenerator. Generated data is owned by SkImage and - may not be shared or accessed. - - SkImage is returned if generator data is valid. Valid data parameters vary by type of data - and platform. - - imageGenerator may wrap SkPicture data, codec data, or custom data. - - @param imageGenerator stock or custom routines to retrieve SkImage - @return created SkImage, or nullptr - */ - static sk_sp MakeFromGenerator(std::unique_ptr imageGenerator); - - /** - * Return an image backed by the encoded data, but attempt to defer decoding until the image - * is actually used/drawn. This deferral allows the system to cache the result, either on the - * CPU or on the GPU, depending on where the image is drawn. If memory is low, the cache may - * be purged, causing the next draw of the image to have to re-decode. - * - * If alphaType is nullopt, the image's alpha type will be chosen automatically based on the - * image format. Transparent images will default to kPremul_SkAlphaType. If alphaType contains - * kPremul_SkAlphaType or kUnpremul_SkAlphaType, that alpha type will be used. Forcing opaque - * (passing kOpaque_SkAlphaType) is not allowed, and will return nullptr. - * - * This is similar to DecodeTo[Raster,Texture], but this method will attempt to defer the - * actual decode, while the DecodeTo... method explicitly decode and allocate the backend - * when the call is made. - * - * If the encoded format is not supported, nullptr is returned. - * - * @param encoded the encoded data - * @return created SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_MakeFromEncoded - */ - static sk_sp MakeFromEncoded(sk_sp encoded, - std::optional alphaType = std::nullopt); - - /* - * Experimental: - * Skia | GL_COMPRESSED_* | MTLPixelFormat* | VK_FORMAT_*_BLOCK - * -------------------------------------------------------------------------------------- - * kETC2_RGB8_UNORM | ETC1_RGB8 | ETC2_RGB8 (iOS-only) | ETC2_R8G8B8_UNORM - * | RGB8_ETC2 | | - * -------------------------------------------------------------------------------------- - * kBC1_RGB8_UNORM | RGB_S3TC_DXT1_EXT | N/A | BC1_RGB_UNORM - * -------------------------------------------------------------------------------------- - * kBC1_RGBA8_UNORM | RGBA_S3TC_DXT1_EXT | BC1_RGBA (macOS-only)| BC1_RGBA_UNORM - */ - enum class CompressionType { - kNone, - kETC2_RGB8_UNORM, // the same as ETC1 - - kBC1_RGB8_UNORM, - kBC1_RGBA8_UNORM, - kLast = kBC1_RGBA8_UNORM, - }; + @param bitmap SkImageInfo, row bytes, and pixels + @return created SkImage, or nullptr +*/ +SK_API sk_sp RasterFromBitmap(const SkBitmap& bitmap); - static constexpr int kCompressionTypeCount = static_cast(CompressionType::kLast) + 1; +/** Creates a CPU-backed SkImage from compressed data. - static const CompressionType kETC1_CompressionType = CompressionType::kETC2_RGB8_UNORM; + This method will decompress the compressed data and create an image wrapping + it. Any mipmap levels present in the compressed data are discarded. - /** Creates a CPU-backed SkImage from compressed data. + @param data compressed data to store in SkImage + @param width width of full SkImage + @param height height of full SkImage + @param type type of compression used + @return created SkImage, or nullptr +*/ +SK_API sk_sp RasterFromCompressedTextureData(sk_sp data, + int width, + int height, + SkTextureCompressionType type); + +/** + * Return a SkImage using the encoded data, but attempts to defer decoding until the + * image is actually used/drawn. This deferral allows the system to cache the result, either on the + * CPU or on the GPU, depending on where the image is drawn. If memory is low, the cache may + * be purged, causing the next draw of the image to have to re-decode. + * + * If alphaType is nullopt, the image's alpha type will be chosen automatically based on the + * image format. Transparent images will default to kPremul_SkAlphaType. If alphaType contains + * kPremul_SkAlphaType or kUnpremul_SkAlphaType, that alpha type will be used. Forcing opaque + * (passing kOpaque_SkAlphaType) is not allowed, and will return nullptr. + * + * If the encoded format is not supported, nullptr is returned. + * + * @param encoded the encoded data + * @return created SkImage, or nullptr - This method will decompress the compressed data and create an image wrapping - it. Any mipmap levels present in the compressed data are discarded. + example: https://fiddle.skia.org/c/@Image_DeferredFromEncodedData +*/ +SK_API sk_sp DeferredFromEncodedData(sk_sp encoded, + std::optional alphaType = std::nullopt); - @param data compressed data to store in SkImage - @param width width of full SkImage - @param height height of full SkImage - @param type type of compression used - @return created SkImage, or nullptr - */ - static sk_sp MakeRasterFromCompressed(sk_sp data, - int width, int height, - CompressionType type); +/** Creates SkImage from data returned by imageGenerator. The image data will not be created + (on either the CPU or GPU) until the image is actually drawn. + Generated data is owned by SkImage and may not be shared or accessed. - enum class BitDepth { - kU8, //!< uses 8-bit unsigned int per color component - kF16, //!< uses 16-bit float per color component - }; + SkImage is returned if generator data is valid. Valid data parameters vary by type of data + and platform. - /** Creates SkImage from picture. Returned SkImage width and height are set by dimensions. - SkImage draws picture with matrix and paint, set to bitDepth and colorSpace. + imageGenerator may wrap SkPicture data, codec data, or custom data. - If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws - with default SkPaint. colorSpace may be nullptr. + @param imageGenerator stock or custom routines to retrieve SkImage + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromGenerator(std::unique_ptr imageGenerator); - @param picture stream of drawing commands - @param dimensions width and height - @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr - @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr - @param bitDepth 8-bit integer or 16-bit float: per component - @param colorSpace range of colors; may be nullptr - @param props props to use when rasterizing the picture - @return created SkImage, or nullptr - */ - static sk_sp MakeFromPicture(sk_sp picture, const SkISize& dimensions, - const SkMatrix* matrix, const SkPaint* paint, - BitDepth bitDepth, sk_sp colorSpace, - SkSurfaceProps props = {}); - -#if SK_SUPPORT_GPU - /** Creates a GPU-backed SkImage from compressed data. - - This method will return an SkImage representing the compressed data. - If the GPU doesn't support the specified compression method, the data - will be decompressed and then wrapped in a GPU-backed image. - - Note: one can query the supported compression formats via - GrRecordingContext::compressedBackendFormat. - - @param context GPU context - @param data compressed data to store in SkImage - @param width width of full SkImage - @param height height of full SkImage - @param type type of compression used - @param mipmapped does 'data' contain data for all the mipmap levels? - @param isProtected do the contents of 'data' require DRM protection (on Vulkan)? - @return created SkImage, or nullptr - */ - static sk_sp MakeTextureFromCompressed(GrDirectContext* direct, - sk_sp data, - int width, int height, - CompressionType type, - GrMipmapped mipmapped = GrMipmapped::kNo, - GrProtected isProtected = GrProtected::kNo); - - /** User function called when supplied texture may be deleted. - */ - typedef void (*TextureReleaseProc)(ReleaseContext releaseContext); +enum class BitDepth { + kU8, //!< uses 8-bit unsigned int per color component + kF16, //!< uses 16-bit float per color component +}; - /** Creates SkImage from GPU texture associated with context. GPU texture must stay - valid and unchanged until textureReleaseProc is called. textureReleaseProc is - passed releaseContext when SkImage is deleted or no longer refers to texture. +/** Creates SkImage from picture. Returned SkImage width and height are set by dimensions. + SkImage draws picture with matrix and paint, set to bitDepth and colorSpace. - SkImage is returned if format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. + The Picture data is not turned into an image (CPU or GPU) until it is drawn. - @note When using a DDL recording context, textureReleaseProc will be called on the - GPU thread after the DDL is played back on the direct context. + If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws + with default SkPaint. colorSpace may be nullptr. - @param context GPU context - @param backendTexture texture residing on GPU - @param colorSpace This describes the color space of this image's contents, as - seen after sampling. In general, if the format of the backend - texture is SRGB, some linear colorSpace should be supplied - (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the - backend texture is linear, then the colorSpace should include - a description of the transfer function as - well (e.g., SkColorSpace::MakeSRGB()). - @param textureReleaseProc function called when texture can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin origin, - SkColorType colorType, - SkAlphaType alphaType, + @param picture stream of drawing commands + @param dimensions width and height + @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr + @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr + @param bitDepth 8-bit integer or 16-bit float: per component + @param colorSpace range of colors; may be nullptr + @param props props to use when rasterizing the picture + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromPicture(sk_sp picture, + const SkISize& dimensions, + const SkMatrix* matrix, + const SkPaint* paint, + BitDepth bitDepth, sk_sp colorSpace, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates an SkImage from a GPU backend texture. The backend texture must stay - valid and unchanged until textureReleaseProc is called. The textureReleaseProc is - called when the SkImage is deleted or no longer refers to the texture and will be - passed the releaseContext. - - An SkImage is returned if the format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. - - @note When using a DDL recording context, textureReleaseProc will be called on the - GPU thread after the DDL is played back on the direct context. - - @param context the GPU context - @param backendTexture a texture already allocated by the GPU - @param alphaType This characterizes the nature of the alpha values in the - backend texture. For opaque compressed formats (e.g., ETC1) - this should usually be set to kOpaque_SkAlphaType. - @param colorSpace This describes the color space of this image's contents, as - seen after sampling. In general, if the format of the backend - texture is SRGB, some linear colorSpace should be supplied - (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the - backend texture is linear, then the colorSpace should include - a description of the transfer function as - well (e.g., SkColorSpace::MakeSRGB()). - @param textureReleaseProc function called when the backend texture can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromCompressedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin origin, - SkAlphaType alphaType, - sk_sp colorSpace, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates SkImage from pixmap. SkImage is uploaded to GPU back-end using context. - - Created SkImage is available to other GPU contexts, and is available across thread - boundaries. All contexts must be in the same GPU share group, or otherwise - share resources. - - When SkImage is no longer referenced, context releases texture memory - asynchronously. - - GrBackendTexture created from pixmap is uploaded to match SkSurface created with - dstColorSpace. SkColorSpace of SkImage is determined by pixmap.colorSpace(). - - SkImage is returned referring to GPU back-end if context is not nullptr, - format of data is recognized and supported, and if context supports moving - resources between contexts. Otherwise, pixmap pixel data is copied and SkImage - as returned in raster format if possible; nullptr may be returned. - Recognized GPU formats vary by platform and GPU back-end. - - @param context GPU context - @param pixmap SkImageInfo, pixel address, and row bytes - @param buildMips create SkImage as mip map if true - @param dstColorSpace range of colors of matching SkSurface on GPU - @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary - @return created SkImage, or nullptr - */ - static sk_sp MakeCrossContextFromPixmap(GrDirectContext* context, - const SkPixmap& pixmap, - bool buildMips, - bool limitToMaxTextureSize = false); - - /** Creates SkImage from backendTexture associated with context. backendTexture and - returned SkImage are managed internally, and are released when no longer needed. - - SkImage is returned if format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. - - @param context GPU context - @param backendTexture texture residing on GPU - @param textureOrigin origin of backendTexture - @param colorType color type of the resulting image - @param alphaType alpha type of the resulting image - @param colorSpace range of colors; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType); - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType, - SkAlphaType alphaType); - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace); - - /** Creates an SkImage from YUV[A] planar textures. This requires that the textures stay valid - for the lifetime of the image. The ReleaseContext can be used to know when it is safe to - either delete or overwrite the textures. If ReleaseProc is provided it is also called before - return on failure. - - @param context GPU context - @param yuvaTextures A set of textures containing YUVA data and a description of the - data and transformation to RGBA. - @param imageColorSpace range of colors of the resulting image after conversion to RGB; - may be nullptr - @param textureReleaseProc called when the backend textures can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromYUVATextures(GrRecordingContext* context, - const GrYUVABackendTextures& yuvaTextures, - sk_sp imageColorSpace = nullptr, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates SkImage from SkYUVAPixmaps. - - The image will remain planar with each plane converted to a texture using the passed - GrRecordingContext. - - SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. - The SkColorSpace of the resulting RGB values is specified by imageColorSpace. This will - be the SkColorSpace reported by the image and when drawn the RGB values will be converted - from this space into the destination space (if the destination is tagged). - - Currently, this is only supported using the GPU backend and will fail if context is nullptr. + SkSurfaceProps props); +SK_API sk_sp DeferredFromPicture(sk_sp picture, + const SkISize& dimensions, + const SkMatrix* matrix, + const SkPaint* paint, + BitDepth bitDepth, + sk_sp colorSpace); + +/** Creates a CPU-backed SkImage from pixmap, copying the pixel data. + As a result, pixmap pixels may be modified or deleted without affecting SkImage. + + SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. + + @param pixmap SkImageInfo, pixel address, and row bytes + @return copy of SkPixmap pixels, or nullptr + + example: https://fiddle.skia.org/c/@Image_RasterFromPixmapCopy +*/ +SK_API sk_sp RasterFromPixmapCopy(const SkPixmap& pixmap); + +/** Creates CPU-backed SkImage from pixmap, sharing SkPixmap pixels. Pixels must remain valid and + unchanged until rasterReleaseProc is called. rasterReleaseProc is passed + releaseContext when SkImage is deleted or no longer refers to pixmap pixels. + + Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback + when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc + does not require state. + + SkImage is returned if pixmap is valid. Valid SkPixmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. + + @param pixmap SkImageInfo, pixel address, and row bytes + @param rasterReleaseProc function called when pixels can be released; or nullptr + @param releaseContext state passed to rasterReleaseProc; or nullptr + @return SkImage sharing pixmap +*/ +SK_API sk_sp RasterFromPixmap(const SkPixmap& pixmap, + RasterReleaseProc rasterReleaseProc, + ReleaseContext releaseContext); + +/** Creates CPU-backed SkImage from pixel data described by info. + The pixels data will *not* be copied. + + SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + rowBytes are large enough to hold one row of pixels; + pixels is not nullptr, and contains enough data for SkImage. + + @param info contains width, height, SkAlphaType, SkColorType, SkColorSpace + @param pixels address or pixel storage + @param rowBytes size of pixel row or larger + @return SkImage sharing pixels, or nullptr +*/ +SK_API sk_sp RasterFromData(const SkImageInfo& info, + sk_sp pixels, + size_t rowBytes); - SkYUVAPixmaps does not need to remain valid after this returns. +} // namespace SkImages - @param context GPU context - @param pixmaps The planes as pixmaps with supported SkYUVAInfo that - specifies conversion to RGB. - @param buildMips create internal YUVA textures as mip map if kYes. This is - silently ignored if the context does not support mip maps. - @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary - @param imageColorSpace range of colors of the resulting image; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromYUVAPixmaps(GrRecordingContext* context, - const SkYUVAPixmaps& pixmaps, - GrMipmapped buildMips = GrMipmapped::kNo, - bool limitToMaxTextureSize = false, - sk_sp imageColorSpace = nullptr); - - using PromiseImageTextureContext = void*; - using PromiseImageTextureFulfillProc = - sk_sp (*)(PromiseImageTextureContext); - using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); - - /** Create a new SkImage that is very similar to an SkImage created by MakeFromTexture. The - difference is that the caller need not have created the texture nor populated it with the - image pixel data. Moreover, the SkImage may be created on a thread as the creation of the - image does not require access to the backend API or GrDirectContext. Instead of passing a - GrBackendTexture the client supplies a description of the texture consisting of - GrBackendFormat, width, height, and GrMipmapped state. The resulting SkImage can be drawn - to a SkDeferredDisplayListRecorder or directly to a GPU-backed SkSurface. - - When the actual texture is required to perform a backend API draw, textureFulfillProc will - be called to receive a GrBackendTexture. The properties of the GrBackendTexture must match - those set during the SkImage creation, and it must refer to a valid existing texture in the - backend API context/device, and be populated with the image pixel data. The texture cannot - be deleted until textureReleaseProc is called. - - There is at most one call to each of textureFulfillProc and textureReleaseProc. - textureReleaseProc is always called even if image creation fails or if the - image is never fulfilled (e.g. it is never drawn or all draws are clipped out) - - @param gpuContextProxy the thread-safe proxy of the gpu context. required. - @param backendFormat format of promised gpu texture - @param dimensions width & height of promised gpu texture - @param mipmapped mip mapped state of promised gpu texture - @param origin surface origin of promised gpu texture - @param colorType color type of promised gpu texture - @param alphaType alpha type of promised gpu texture - @param colorSpace range of colors; may be nullptr - @param textureFulfillProc function called to get actual gpu texture - @param textureReleaseProc function called when texture can be deleted - @param textureContext state passed to textureFulfillProc and textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakePromiseTexture(sk_sp gpuContextProxy, - const GrBackendFormat& backendFormat, - SkISize dimensions, - GrMipmapped mipmapped, - GrSurfaceOrigin origin, - SkColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace, - PromiseImageTextureFulfillProc textureFulfillProc, - PromiseImageTextureReleaseProc textureReleaseProc, - PromiseImageTextureContext textureContext); - - /** This entry point operates like 'MakePromiseTexture' but it is used to construct a SkImage - from YUV[A] data. The source data may be planar (i.e. spread across multiple textures). In - the extreme Y, U, V, and A are all in different planes and thus the image is specified by - four textures. 'backendTextureInfo' describes the planar arrangement, texture formats, - conversion to RGB, and origin of the textures. Separate 'textureFulfillProc' and - 'textureReleaseProc' calls are made for each texture. Each texture has its own - PromiseImageTextureContext. If 'backendTextureInfo' is not valid then no release proc - calls are made. Otherwise, the calls will be made even on failure. 'textureContexts' has one - entry for each of the up to four textures, as indicated by 'backendTextureInfo'. - - Currently the mip mapped property of 'backendTextureInfo' is ignored. However, in the - near future it will be required that if it is kYes then textureFulfillProc must return - a mip mapped texture for each plane in order to successfully draw the image. - - @param gpuContextProxy the thread-safe proxy of the gpu context. required. - @param backendTextureInfo info about the promised yuva gpu texture - @param imageColorSpace range of colors; may be nullptr - @param textureFulfillProc function called to get actual gpu texture - @param textureReleaseProc function called when texture can be deleted - @param textureContexts state passed to textureFulfillProc and textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakePromiseYUVATexture(sk_sp gpuContextProxy, - const GrYUVABackendTextureInfo& backendTextureInfo, - sk_sp imageColorSpace, - PromiseImageTextureFulfillProc textureFulfillProc, - PromiseImageTextureReleaseProc textureReleaseProc, - PromiseImageTextureContext textureContexts[]); +/** \class SkImage + SkImage describes a two dimensional array of pixels to draw. The pixels may be + decoded in a raster bitmap, encoded in a SkPicture or compressed data stream, + or located in GPU memory as a GPU texture. -#endif // SK_SUPPORT_GPU + SkImage cannot be modified after it is created. SkImage may allocate additional + storage as needed; for instance, an encoded SkImage may decode when drawn. -#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 - /** (See Skia bug 7447) - Creates SkImage from Android hardware buffer. - Returned SkImage takes a reference on the buffer. + SkImage width and height are greater than zero. Creating an SkImage with zero width + or height returns SkImage equal to nullptr. - Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams, + GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported + include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details + vary with platform. - @param hardwareBuffer AHardwareBuffer Android hardware buffer - @param colorSpace range of colors; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAHardwareBuffer( - AHardwareBuffer* hardwareBuffer, - SkAlphaType alphaType = kPremul_SkAlphaType, - sk_sp colorSpace = nullptr, - GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); - - /** Creates SkImage from Android hardware buffer and uploads the data from the SkPixmap to it. - Returned SkImage takes a reference on the buffer. - - Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. - - @param context GPU context - @param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer - @param hardwareBuffer AHardwareBuffer Android hardware buffer - @param surfaceOrigin surface origin for resulting image - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAHardwareBufferWithData( - GrDirectContext* context, - const SkPixmap& pixmap, - AHardwareBuffer* hardwareBuffer, - GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); -#endif + See SkImages namespace for the static factory methods to make SkImages. + Clients should *not* subclass SkImage as there is a lot of internal machinery that is + not publicly accessible. +*/ +class SK_API SkImage : public SkRefCnt { +public: /** Returns a SkImageInfo describing the width, height, color type, alpha type, and color space of the SkImage. @@ -691,18 +362,12 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, const SkMatrix* localMatrix = nullptr) const; - sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& lm) const { - return this->makeShader(tmx, tmy, sampling, &lm); - } - sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm); - } + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix* lm = nullptr) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm); - } + const SkMatrix* lm = nullptr) const; /** * makeRawShader functions like makeShader, but for images that contain non-color data. @@ -719,20 +384,12 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, const SkMatrix* localMatrix = nullptr) const; - sk_sp makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& lm) const { - return this->makeRawShader(tmx, tmy, sampling, &lm); - } - sk_sp makeRawShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const { - return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm); - } + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeRawShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeRawShader(const SkSamplingOptions& sampling, - const SkMatrix* lm = nullptr) const { - return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm); - } - - using CubicResampler = SkCubicResampler; + const SkMatrix* lm = nullptr) const; /** Copies SkImage pixel address, row bytes, and SkImageInfo to pixmap, if address is available, and returns true. If pixel address is not available, return @@ -752,12 +409,12 @@ class SK_API SkImage : public SkRefCnt { example: https://fiddle.skia.org/c/@Image_isTextureBacked */ - bool isTextureBacked() const; + virtual bool isTextureBacked() const = 0; /** Returns an approximation of the amount of texture memory used by the image. Returns zero if the image is not texture backed or if the texture has an external format. */ - size_t textureSize() const; + virtual size_t textureSize() const = 0; /** Returns true if SkImage can be drawn on either raster surface or GPU surface. If context is nullptr, tests if SkImage draws on raster surface; @@ -772,43 +429,7 @@ class SK_API SkImage : public SkRefCnt { example: https://fiddle.skia.org/c/@Image_isValid */ - bool isValid(GrRecordingContext* context) const; - -#if SK_SUPPORT_GPU - /** Flushes any pending uses of texture-backed images in the GPU backend. If the image is not - texture-backed (including promise texture images) or if the GrDirectContext does not - have the same context ID as the context backing the image then this is a no-op. - - If the image was not used in any non-culled draws in the current queue of work for the - passed GrDirectContext then this is a no-op unless the GrFlushInfo contains semaphores or - a finish proc. Those are respected even when the image has not been used. - - @param context the context on which to flush pending usages of the image. - @param info flush options - */ - GrSemaphoresSubmitted flush(GrDirectContext* context, const GrFlushInfo& flushInfo) const; - - void flush(GrDirectContext* context) const { this->flush(context, {}); } - - /** Version of flush() that uses a default GrFlushInfo. Also submits the flushed work to the - GPU. - */ - void flushAndSubmit(GrDirectContext*) const; - - /** Retrieves the back-end texture. If SkImage has no back-end texture, an invalid - object is returned. Call GrBackendTexture::isValid to determine if the result - is valid. - - If flushPendingGrContextIO is true, completes deferred I/O operations. - - If origin in not nullptr, copies location of content drawn into SkImage. - - @param flushPendingGrContextIO flag to flush outstanding requests - @return back-end API texture handle; invalid on failure - */ - GrBackendTexture getBackendTexture(bool flushPendingGrContextIO, - GrSurfaceOrigin* origin = nullptr) const; -#endif // SK_SUPPORT_GPU + virtual bool isValid(GrRecordingContext* context) const = 0; /** \enum SkImage::CachingHint CachingHint selects whether Skia may internally cache SkBitmap generated by @@ -941,40 +562,11 @@ class SK_API SkImage : public SkRefCnt { enum class RescaleMode { kNearest, + kLinear, kRepeatedLinear, kRepeatedCubic, }; - /** Makes image pixel data available to caller, possibly asynchronously. - - Currently asynchronous reads are only supported on the GPU backend and only when the - underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all - other cases this operates synchronously. - - Data is read from the source sub-rectangle, then converted to the color space, color type, - and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the image - causes failure. - - When the pixel data is ready the caller's ReadPixelsCallback is called with a - AsyncReadResult containing pixel data in the requested color type, alpha type, and color - space. The AsyncReadResult will have count() == 1. Upon failure the callback is called with - nullptr for AsyncReadResult. For a GPU image this flushes work but a submit must occur to - guarantee a finite time before the callback is called. - - The data is valid for the lifetime of AsyncReadResult with the exception that if the SkImage - is GPU-backed the data is immediately invalidated if the context is abandoned or - destroyed. - - @param info info of the requested pixels - @param srcRect subrectangle of image to read - @param callback function to call with result of the read - @param context passed to callback - */ - void asyncReadPixels(const SkImageInfo& info, - const SkIRect& srcRect, - ReadPixelsCallback callback, - ReadPixelsContext context) const; - /** Makes image pixel data available to caller, possibly asynchronously. It can also rescale the image pixels. @@ -1071,44 +663,6 @@ class SK_API SkImage : public SkRefCnt { bool scalePixels(const SkPixmap& dst, const SkSamplingOptions&, CachingHint cachingHint = kAllow_CachingHint) const; - /** Encodes SkImage pixels, returning result as SkData. - - Returns nullptr if encoding fails, or if encodedImageFormat is not supported. - - SkImage encoding in a format requires both building with one or more of: - SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP; and platform support - for the encoded format. - - If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encodedImageFormat can - additionally be one of: SkEncodedImageFormat::kICO, SkEncodedImageFormat::kBMP, - SkEncodedImageFormat::kGIF. - - quality is a platform and format specific metric trading off size and encoding - error. When used, quality equaling 100 encodes with the least error. quality may - be ignored by the encoder. - - @param encodedImageFormat one of: SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kPNG, - SkEncodedImageFormat::kWEBP - @param quality encoder specific metric with 100 equaling best - @return encoded SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_encodeToData - */ - sk_sp encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const; - - /** Encodes SkImage pixels, returning result as SkData. Returns existing encoded data - if present; otherwise, SkImage is encoded with SkEncodedImageFormat::kPNG. Skia - must be built with SK_ENCODE_PNG to encode SkImage. - - Returns nullptr if existing encoded data is missing or invalid, and - encoding fails. - - @return encoded SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_encodeToData_2 - */ - sk_sp encodeToData() const; - /** Returns encoded SkImage pixels as SkData, if SkImage was created from supported encoded stream format. Platform support for formats vary and may require building with one or more of: SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP. @@ -1151,33 +705,79 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp withDefaultMipmaps() const; -#if SK_SUPPORT_GPU - /** Returns SkImage backed by GPU texture associated with context. Returned SkImage is - compatible with SkSurface created with dstColorSpace. The returned SkImage respects - mipmapped setting; if mipmapped equals GrMipmapped::kYes, the backing texture - allocates mip map levels. - - The mipmapped parameter is effectively treated as kNo if MIP maps are not supported by the - GPU. - - Returns original SkImage if the image is already texture-backed, the context matches, and - mipmapped is compatible with the backing GPU texture. SkBudgeted is ignored in this case. - - Returns nullptr if context is nullptr, or if SkImage was created with another - GrDirectContext. +#if defined(SK_GANESH) || defined(SK_GRAPHITE) + using ReleaseContext = SkImages::ReleaseContext; + using TextureReleaseProc = void (*)(ReleaseContext); +#endif - @param GrDirectContext the GrDirectContext in play, if it exists - @param GrMipmapped whether created SkImage texture must allocate mip map levels - @param SkBudgeted whether to count a newly created texture for the returned image - counts against the context's budget. - @return created SkImage, or nullptr +#if defined(SK_GRAPHITE) + // Passed to both fulfill and imageRelease + using GraphitePromiseImageContext = void*; + // Returned from fulfill and passed into textureRelease + using GraphitePromiseTextureReleaseContext = void*; + + using GraphitePromiseImageFulfillProc = + std::tuple + (*)(GraphitePromiseImageContext); + using GraphitePromiseImageReleaseProc = void (*)(GraphitePromiseImageContext); + using GraphitePromiseTextureReleaseProc = void (*)(GraphitePromiseTextureReleaseContext); + + /** Create a new SkImage that is very similar to an SkImage created by + MakeGraphiteFromBackendTexture. The difference is that the caller need not have created the + backend texture nor populated it with data when creating the image. Instead of passing a + BackendTexture to the factory the client supplies a description of the texture consisting + of dimensions, TextureInfo, SkColorInfo and Volatility. + + In general, 'fulfill' must return a BackendTexture that matches the properties + provided at SkImage creation time. The BackendTexture must refer to a valid existing + texture in the backend API context/device, and already be populated with data. + The texture cannot be deleted until 'textureRelease' is called. 'textureRelease' will + be called with the textureReleaseContext returned by 'fulfill'. + + Wrt when and how often the fulfill, imageRelease, and textureRelease callbacks will + be called: + + For non-volatile promise images, 'fulfill' will be called at Context::insertRecording + time. Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' will always be + called only once - when Skia will no longer try calling 'fulfill' to get a backend + texture. If 'fulfill' failed (i.e., it didn't return a valid backend texture) then + 'textureRelease' will never be called. If 'fulfill' was successful then + 'textureRelease' will be called only once when the GPU is done with the contents of the + promise image. This will usually occur during a Context::submit call but it could occur + earlier due to error conditions. 'fulfill' can be called multiple times if the promise + image is used in multiple recordings. If 'fulfill' fails, the insertRecording itself will + fail. Subsequent insertRecording calls (with Recordings that use the promise image) will + keep calling 'fulfill' until it succeeds. + + For volatile promise images, 'fulfill' will be called each time the Recording is inserted + into a Context. Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' + will always be called only once just like the non-volatile case. If 'fulfill' fails at + insertRecording-time, 'textureRelease' will never be called. If 'fulfill' was successful + then a 'textureRelease' matching that 'fulfill' will be called when the GPU is done with + the contents of the promise image. This will usually occur during a Context::submit call + but it could occur earlier due to error conditions. + + @param recorder the recorder that will capture the commands creating the image + @param dimensions width & height of promised gpu texture + @param textureInfo structural information for the promised gpu texture + @param colorInfo color type, alpha type and colorSpace information for the image + @param isVolatile volatility of the promise image + @param fulfill function called to get the actual backend texture + @param imageRelease function called when any image-centric data can be deleted + @param textureRelease function called when the backend texture can be deleted + @param imageContext state passed to fulfill and imageRelease + @return created SkImage, or nullptr */ - sk_sp makeTextureImage(GrDirectContext*, - GrMipmapped = GrMipmapped::kNo, - SkBudgeted = SkBudgeted::kYes) const; -#endif + static sk_sp MakeGraphitePromiseTexture(skgpu::graphite::Recorder*, + SkISize dimensions, + const skgpu::graphite::TextureInfo&, + const SkColorInfo&, + skgpu::graphite::Volatile, + GraphitePromiseImageFulfillProc, + GraphitePromiseImageReleaseProc, + GraphitePromiseTextureReleaseProc, + GraphitePromiseImageContext); -#ifdef SK_GRAPHITE_ENABLED /** Creates an SkImage from a GPU texture associated with the recorder. SkImage is returned if the format of backendTexture is recognized and supported. @@ -1198,12 +798,60 @@ class SK_API SkImage : public SkRefCnt { const skgpu::graphite::BackendTexture&, SkColorType colorType, SkAlphaType alphaType, - sk_sp colorSpace); + sk_sp colorSpace, + TextureReleaseProc = nullptr, + ReleaseContext = nullptr); + + /** Creates an SkImage from YUV[A] planar textures associated with the recorder. + @param recorder The recorder. + @param yuvaBackendTextures A set of textures containing YUVA data and a description of the + data and transformation to RGBA. + @param imageColorSpace range of colors of the resulting image after conversion to RGB; + may be nullptr + @param TextureReleaseProc called when the backend textures can be released + @param ReleaseContext state passed to TextureReleaseProc + @return created SkImage, or nullptr + */ + static sk_sp MakeGraphiteFromYUVABackendTextures( + skgpu::graphite::Recorder* recorder, + const skgpu::graphite::YUVABackendTextures& yuvaBackendTextures, + sk_sp imageColorSpace, + TextureReleaseProc = nullptr, + ReleaseContext = nullptr); struct RequiredImageProperties { - skgpu::graphite::Mipmapped fMipmapped; + skgpu::Mipmapped fMipmapped; }; + /** Creates SkImage from SkYUVAPixmaps. + + The image will remain planar with each plane converted to a texture using the passed + Recorder. + + SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. + The SkColorSpace of the resulting RGB values is specified by imgColorSpace. This will + be the SkColorSpace reported by the image and when drawn the RGB values will be converted + from this space into the destination space (if the destination is tagged). + + This is only supported using the GPU backend and will fail if recorder is nullptr. + + SkYUVAPixmaps does not need to remain valid after this returns. + + @param Recorder The Recorder to use for storing commands + @param pixmaps The planes as pixmaps with supported SkYUVAInfo that + specifies conversion to RGB. + @param RequiredImageProperties Properties the returned SkImage must possess (e.g., + mipmaps) + @param limitToMaxTextureSize Downscale image to GPU maximum texture size, if necessary + @param imgColorSpace Range of colors of the resulting image; may be nullptr + @return Created SkImage, or nullptr + */ + static sk_sp MakeGraphiteFromYUVAPixmaps(skgpu::graphite::Recorder*, + const SkYUVAPixmaps& pixmaps, + RequiredImageProperties = {}, + bool limitToMaxTextureSize = false, + sk_sp imgColorSpace = nullptr); + /** Graphite version of makeTextureImage. Returns an SkImage backed by a Graphite texture, using the provided Recorder for creation @@ -1225,9 +873,70 @@ class SK_API SkImage : public SkRefCnt { mipmaps) @return created SkImage, or nullptr */ - sk_sp makeTextureImage(skgpu::graphite::Recorder*, - RequiredImageProperties = {}) const; -#endif + virtual sk_sp makeTextureImage(skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const = 0; + + /** Returns subset of this image. + + Returns nullptr if any of the following are true: + - Subset is empty + - Subset is not contained inside the image's bounds + - Pixels in the image could not be read or copied + + If this image is texture-backed, the recorder parameter is required. + If the recorder parameter is provided, and the image is raster-backed, the subset will + be converted to texture-backed. + + @param subset bounds of returned SkImage + @param recorder the recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return the subsetted image, or nullptr + */ + sk_sp makeSubset(const SkIRect& subset, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + + /** Creates SkImage in target SkColorSpace. + Returns nullptr if SkImage could not be created. + + Returns original SkImage if it is in target SkColorSpace. + Otherwise, converts pixels from SkImage SkColorSpace to target SkColorSpace. + If SkImage colorSpace() returns nullptr, SkImage SkColorSpace is assumed to be sRGB. + + If this image is graphite-backed, the recorder parameter is required. + + @param targetColorSpace SkColorSpace describing color range of returned SkImage + @param recorder The Recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return created SkImage in target SkColorSpace + */ + sk_sp makeColorSpace(sk_sp targetColorSpace, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + + /** Experimental. + Creates SkImage in target SkColorType and SkColorSpace. + Returns nullptr if SkImage could not be created. + + Returns original SkImage if it is in target SkColorType and SkColorSpace. + + If this image is graphite-backed, the recorder parameter is required. + + @param targetColorType SkColorType of returned SkImage + @param targetColorSpace SkColorSpace of returned SkImage + @param recorder The Recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return created SkImage in target SkColorType and SkColorSpace + */ + sk_sp makeColorTypeAndColorSpace(SkColorType targetColorType, + sk_sp targetColorSpace, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + +#endif // SK_GRAPHITE /** Returns raster image or lazy image. Copies SkImage backed by GPU texture into CPU memory if needed. Returns original SkImage if decoded in raster bitmap, @@ -1285,38 +994,6 @@ class SK_API SkImage : public SkRefCnt { const SkIRect& clipBounds, SkIRect* outSubset, SkIPoint* offset) const; - /** Defines a callback function, taking one parameter of type GrBackendTexture with - no return value. Function is called when back-end texture is to be released. - */ - typedef std::function BackendTextureReleaseProc; - -#if SK_SUPPORT_GPU - /** Creates a GrBackendTexture from the provided SkImage. Returns true and - stores result in backendTexture and backendTextureReleaseProc if - texture is created; otherwise, returns false and leaves - backendTexture and backendTextureReleaseProc unmodified. - - Call backendTextureReleaseProc after deleting backendTexture. - backendTextureReleaseProc cleans up auxiliary data related to returned - backendTexture. The caller must delete returned backendTexture after use. - - If SkImage is both texture backed and singly referenced, image is returned in - backendTexture without conversion or making a copy. SkImage is singly referenced - if its was transferred solely using std::move(). - - If SkImage is not texture backed, returns texture with SkImage contents. - - @param context GPU context - @param image SkImage used for texture - @param backendTexture storage for back-end texture - @param backendTextureReleaseProc storage for clean up function - @return true if back-end texture was created - */ - static bool MakeBackendTextureFromSkImage(GrDirectContext* context, - sk_sp image, - GrBackendTexture* backendTexture, - BackendTextureReleaseProc* backendTextureReleaseProc); -#endif /** Deprecated. */ enum LegacyBitmapMode { @@ -1393,7 +1070,8 @@ class SK_API SkImage : public SkRefCnt { SkImage(const SkImageInfo& info, uint32_t uniqueID); friend class SkBitmap; - friend class SkImage_Base; + friend class SkImage_Base; // for private ctor + friend class SkImage_Raster; // for withMipmaps friend class SkMipmapBuilder; SkImageInfo fInfo; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h deleted file mode 100644 index be0183c094cba..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkImageEncoder_DEFINED -#define SkImageEncoder_DEFINED - -#include "include/core/SkEncodedImageFormat.h" -#include "include/core/SkRefCnt.h" -#include "include/core/SkTypes.h" - -class SkBitmap; -class SkData; -class SkPixmap; -class SkWStream; - -/** - * Encode SkPixmap in the given binary image format. - * - * @param dst results are written to this stream. - * @param src source pixels. - * @param format image format, not all formats are supported. - * @param quality range from 0-100, this is supported by jpeg and webp. - * higher values correspond to improved visual quality, but less compression. - * - * @return false iff input is bad or format is unsupported. - * - * Will always return false if Skia is compiled without image - * encoders. - * - * For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise - * it will use lossy. - * - * For examples of encoding an image to a file or to a block of memory, - * see tools/ToolUtils.h. - */ -SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src, - SkEncodedImageFormat format, int quality); - -/** - * The following helper function wraps SkEncodeImage(). - */ -SK_API bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q); - -/** - * Encode SkPixmap in the given binary image format. - * - * @param src source pixels. - * @param format image format, not all formats are supported. - * @param quality range from 0-100, this is supported by jpeg and webp. - * higher values correspond to improved visual quality, but less compression. - * - * @return encoded data or nullptr if input is bad or format is unsupported. - * - * Will always return nullptr if Skia is compiled without image - * encoders. - * - * For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise - * it will use lossy. - */ -SK_API sk_sp SkEncodePixmap(const SkPixmap& src, SkEncodedImageFormat format, int quality); - -/** - * Helper that extracts the pixmap from the bitmap, and then calls SkEncodePixmap() - */ -SK_API sk_sp SkEncodeBitmap(const SkBitmap& src, SkEncodedImageFormat format, int quality); - -#endif // SkImageEncoder_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h index 42125214e7167..ba9ae09833066 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h @@ -8,32 +8,25 @@ #ifndef SkImageGenerator_DEFINED #define SkImageGenerator_DEFINED -#include "include/core/SkBitmap.h" -#include "include/core/SkColor.h" -#include "include/core/SkImage.h" +#include "include/core/SkData.h" #include "include/core/SkImageInfo.h" -#include "include/core/SkSurfaceProps.h" +#include "include/core/SkPixmap.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkYUVAPixmaps.h" +#include "include/private/base/SkAPI.h" +#if defined(SK_GRAPHITE) +#include "include/core/SkImage.h" +#include "include/gpu/graphite/Recorder.h" +#endif + +#include +#include +#include #include class GrRecordingContext; -class GrSurfaceProxyView; -class GrSamplerState; -class SkBitmap; -class SkData; -class SkMatrix; -class SkPaint; -class SkPicture; - -enum class GrImageTexGenPolicy : int; - -#if SK_GRAPHITE_ENABLED -namespace skgpu::graphite { -enum class Mipmapped : bool; -class Recorder; -} -#endif +enum SkAlphaType : int; class SK_API SkImageGenerator { public: @@ -121,36 +114,12 @@ class SK_API SkImageGenerator { */ bool getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps); -#if SK_SUPPORT_GPU - /** - * If the generator can natively/efficiently return its pixels as a GPU image (backed by a - * texture) this will return that image. If not, this will return NULL. - * - * Regarding the GrRecordingContext parameter: - * - * It must be non-NULL. The generator should only succeed if: - * - its internal context is the same - * - it can somehow convert its texture into one that is valid for the provided context. - * - * If the mipmapped parameter is kYes, the generator should try to create a TextureProxy that - * at least has the mip levels allocated and the base layer filled in. If this is not possible, - * the generator is allowed to return a non mipped proxy, but this will have some additional - * overhead in later allocating mips and copying of the base layer. - * - * GrImageTexGenPolicy determines whether or not a new texture must be created (and its budget - * status) or whether this may (but is not required to) return a pre-existing texture that is - * retained by the generator (kDraw). - */ - GrSurfaceProxyView generateTexture(GrRecordingContext*, - const SkImageInfo& info, - GrMipmapped mipmapped, - GrImageTexGenPolicy); -#endif + virtual bool isTextureGenerator() const { return false; } -#if SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) sk_sp makeTextureImage(skgpu::graphite::Recorder*, const SkImageInfo&, - skgpu::graphite::Mipmapped); + skgpu::Mipmapped); #endif /** @@ -164,17 +133,6 @@ class SK_API SkImageGenerator { static std::unique_ptr MakeFromEncoded( sk_sp, std::optional = std::nullopt); - /** Return a new image generator backed by the specified picture. If the size is empty or - * the picture is NULL, this returns NULL. - * The optional matrix and paint arguments are passed to drawPicture() at rasterization - * time. - */ - static std::unique_ptr MakeFromPicture(const SkISize&, sk_sp, - const SkMatrix*, const SkPaint*, - SkImage::BitDepth, - sk_sp, - SkSurfaceProps props = {}); - protected: static constexpr int kNeedNewImageUniqueID = 0; @@ -187,30 +145,17 @@ class SK_API SkImageGenerator { virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes&, SkYUVAPixmapInfo*) const { return false; } virtual bool onGetYUVAPlanes(const SkYUVAPixmaps&) { return false; } -#if SK_SUPPORT_GPU - // returns nullptr - virtual GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&, - GrMipmapped, GrImageTexGenPolicy); - - // Most internal SkImageGenerators produce textures and views that use kTopLeft_GrSurfaceOrigin. - // If the generator may produce textures with different origins (e.g. - // GrAHardwareBufferImageGenerator) it should override this function to return the correct - // origin. - virtual GrSurfaceOrigin origin() const { return kTopLeft_GrSurfaceOrigin; } -#endif -#if SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) virtual sk_sp onMakeTextureImage(skgpu::graphite::Recorder*, const SkImageInfo&, - skgpu::graphite::Mipmapped); + skgpu::Mipmapped); #endif + const SkImageInfo fInfo; private: - const SkImageInfo fInfo; const uint32_t fUniqueID; - friend class SkImage_Lazy; - // This is our default impl, which may be different on different platforms. // It is called from NewFromEncoded() after it has checked for any runtime factory. // The SkData will never be NULL, as that will have been checked by NewFromEncoded. diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h index 9befe3071fb2b..b5661719006ef 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h @@ -10,16 +10,18 @@ #include "include/core/SkAlphaType.h" #include "include/core/SkColorType.h" -#include "include/core/SkMath.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkTFitsIn.h" -#include "include/private/SkTFitsIn.h" -#include "include/private/SkTo.h" +#include +#include +#include -class SkReadBuffer; -class SkWriteBuffer; class SkColorSpace; /** Returns the number of bytes required to store a pixel, including unused padding. diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h index 7fdbcb8e820d3..11a06a15b1a6d 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h @@ -99,6 +99,11 @@ struct SK_API SkV4 { } bool operator!=(const SkV4& v) const { return !(*this == v); } + static SkScalar Dot(const SkV4& a, const SkV4& b) { + return a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; + } + static SkV4 Normalize(const SkV4& v) { return v * (1.0f / v.length()); } + SkV4 operator-() const { return {-x, -y, -z, -w}; } SkV4 operator+(const SkV4& v) const { return { x + v.x, y + v.y, z + v.z, w + v.w }; } SkV4 operator-(const SkV4& v) const { return { x - v.x, y - v.y, z - v.z, w - v.w }; } @@ -111,6 +116,12 @@ struct SK_API SkV4 { } friend SkV4 operator*(SkScalar s, const SkV4& v) { return v*s; } + SkScalar lengthSquared() const { return Dot(*this, *this); } + SkScalar length() const { return SkScalarSqrt(Dot(*this, *this)); } + + SkScalar dot(const SkV4& v) const { return Dot(*this, v); } + SkV4 normalize() const { return Normalize(*this); } + const float* ptr() const { return &x; } float* ptr() { return &x; } diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h index 3fde51b717e53..9d03e98c0c5f8 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h @@ -8,12 +8,15 @@ #ifndef SkMaskFilter_DEFINED #define SkMaskFilter_DEFINED -#include "include/core/SkBlurTypes.h" -#include "include/core/SkCoverageMode.h" #include "include/core/SkFlattenable.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" -class SkMatrix; +#include + +enum SkBlurStyle : int; +struct SkDeserialProcs; struct SkRect; /** \class SkMaskFilter diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h index 03140760d6f2b..cf84d26228b60 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h @@ -8,12 +8,19 @@ #ifndef SkMatrix_DEFINED #define SkMatrix_DEFINED +#include "include/core/SkPoint.h" #include "include/core/SkRect.h" -#include "include/private/SkMacros.h" -#include "include/private/SkTo.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkMacros.h" +#include "include/private/base/SkTo.h" + +#include +#include -struct SkRSXform; struct SkPoint3; +struct SkRSXform; +struct SkSize; // Remove when clients are updated to live without this #define SK_SUPPORT_LEGACY_MATRIX_RECTTORECT @@ -1812,7 +1819,10 @@ class SK_API SkMatrix { if (tx != 0.0f || ty != 0.0f) { mask |= kTranslate_Mask; } - this->setTypeMask(mask | kRectStaysRect_Mask); + if (sx != 0 && sy != 0) { + mask |= kRectStaysRect_Mask; + } + this->setTypeMask(mask); } /** Returns true if all elements of the matrix are finite. Returns false if any diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h index f34672e3ab05e..360a039e7f531 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h @@ -19,6 +19,7 @@ #include "include/effects/SkRuntimeEffect.h" #include +#include #include class GrDirectContext; @@ -29,22 +30,31 @@ namespace SkSL { struct Program; } /** * A specification for custom meshes. Specifies the vertex buffer attributes and stride, the - * vertex program that produces a user-defined set of varyings, a fragment program that ingests - * the interpolated varyings and produces local coordinates and optionally a color. + * vertex program that produces a user-defined set of varyings, and a fragment program that ingests + * the interpolated varyings and produces local coordinates for shading and optionally a color. + * + * The varyings must include a float2 named "position". If the passed varyings does not + * contain such a varying then one is implicitly added to the final specification and the SkSL + * Varyings struct described below. It is an error to have a varying named "position" that has a + * type other than float2. + * + * The provided attributes and varyings are used to create Attributes and Varyings structs in SkSL + * that are used by the shaders. Each attribute from the Attribute span becomes a member of the + * SkSL Attributes struct and likewise for the varyings. * * The signature of the vertex program must be: - * float2 main(Attributes, out Varyings) - * where the return value is a local position that will be transformed by SkCanvas's matrix. + * Varyings main(const Attributes). * * The signature of the fragment program must be either: - * (float2|void) main(Varyings) + * float2 main(const Varyings) * or - * (float2|void) main(Varyings, out (half4|float4) color) + * float2 main(const Varyings, out (half4|float4) color) * * where the return value is the local coordinates that will be used to access SkShader. If the - * return type is void then the interpolated position from vertex shader return is used as the local - * coordinate. If the color variant is used it will be blended with SkShader (or SkPaint color in - * absence of a shader) using the SkBlender provided to the SkCanvas draw call. + * color variant is used, the returned color will be blended with SkPaint's SkShader (or SkPaint + * color in absence of a SkShader) using the SkBlender passed to SkCanvas drawMesh(). To use + * interpolated local space positions as the shader coordinates, equivalent to how SkPaths are + * shaded, return the position field from the Varying struct as the coordinates. * * The vertex and fragment programs may both contain uniforms. Uniforms with the same name are * assumed to be shared between stages. It is an error to specify uniforms in the vertex and @@ -187,11 +197,12 @@ class SkMeshSpecification : public SkNVRefCnt { SkMeshSpecification(SkSpan, size_t, SkSpan, + int passthroughLocalCoordsVaryingIndex, + uint32_t deadVaryingMask, std::vector uniforms, std::unique_ptr, std::unique_ptr, ColorType, - bool hasLocalCoords, sk_sp, SkAlphaType); @@ -208,8 +219,9 @@ class SkMeshSpecification : public SkNVRefCnt { const std::unique_ptr fFS; const size_t fStride; uint32_t fHash; + const int fPassthroughLocalCoordsVaryingIndex; + const uint32_t fDeadVaryingMask; const ColorType fColorType; - const bool fHasLocalCoords; const sk_sp fColorSpace; const SkAlphaType fAlphaType; }; @@ -295,8 +307,11 @@ class SkMesh { */ static sk_sp MakeIndexBuffer(GrDirectContext*, const void* data, size_t size); - /** Deprecated in favor of const void* and size_t version above. */ - static sk_sp MakeIndexBuffer(GrDirectContext*, sk_sp); + /** + * Makes a copy of an index buffer. The implementation currently only supports a CPU-backed + * source buffer. + */ + static sk_sp CopyIndexBuffer(GrDirectContext*, sk_sp); /** * Makes a vertex buffer to be used with SkMeshes. The buffer may be CPU- or GPU-backed @@ -313,12 +328,23 @@ class SkMesh { */ static sk_sp MakeVertexBuffer(GrDirectContext*, const void*, size_t size); - /** Deprecated in favor of const void* and size_t version above. */ - static sk_sp MakeVertexBuffer(GrDirectContext*, sk_sp); + /** + * Makes a copy of a vertex buffer. The implementation currently only supports a CPU-backed + * source buffer. + */ + static sk_sp CopyVertexBuffer(GrDirectContext*, sk_sp); enum class Mode { kTriangles, kTriangleStrip }; - static SkMesh Make(sk_sp, + struct Result; + + /** + * Creates a non-indexed SkMesh. The returned SkMesh can be tested for validity using + * SkMesh::isValid(). An invalid mesh simply fails to draws if passed to SkCanvas::drawMesh(). + * If the mesh is invalid the returned string give contain the reason for the failure (e.g. the + * vertex buffer was null or uniform data too small). + */ + static Result Make(sk_sp, Mode, sk_sp, size_t vertexCount, @@ -326,7 +352,13 @@ class SkMesh { sk_sp uniforms, const SkRect& bounds); - static SkMesh MakeIndexed(sk_sp, + /** + * Creates an indexed SkMesh. The returned SkMesh can be tested for validity using + * SkMesh::isValid(). A invalid mesh simply fails to draw if passed to SkCanvas::drawMesh(). + * If the mesh is invalid the returned string give contain the reason for the failure (e.g. the + * index buffer was null or uniform data too small). + */ + static Result MakeIndexed(sk_sp, Mode, sk_sp, size_t vertexCount, @@ -364,7 +396,7 @@ class SkMesh { private: friend struct SkMeshPriv; - bool validate() const; + std::tuple validate() const; sk_sp fSpec; @@ -384,6 +416,8 @@ class SkMesh { SkRect fBounds = SkRect::MakeEmpty(); }; +struct SkMesh::Result { SkMesh mesh; SkString error; }; + #endif // SK_ENABLE_SKSL #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h index a6c6bdf195e1f..398de57d0c59f 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h @@ -5,5 +5,5 @@ * found in the LICENSE file. */ #ifndef SK_MILESTONE -#define SK_MILESTONE 108 +#define SK_MILESTONE 114 #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h index d6c1d830c7ed3..157dbb59d8d6c 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h @@ -8,23 +8,28 @@ #ifndef SkPaint_DEFINED #define SkPaint_DEFINED -#include "include/core/SkBlendMode.h" #include "include/core/SkColor.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTo.h" - +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkFloatingPoint.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" + +#include #include +#include class SkBlender; class SkColorFilter; class SkColorSpace; -struct SkRect; class SkImageFilter; class SkMaskFilter; -class SkMatrix; -class SkPath; class SkPathEffect; class SkShader; +enum class SkBlendMode; +struct SkRect; /** \class SkPaint SkPaint controls options applied when drawing. SkPaint collects all @@ -383,34 +388,6 @@ class SK_API SkPaint { */ void setStrokeJoin(Join join); - /** Returns the filled equivalent of the stroked path. - - @param src SkPath read to create a filled version - @param dst resulting SkPath; may be the same as src, but may not be nullptr - @param cullRect optional limit passed to SkPathEffect - @param resScale if > 1, increase precision, else if (0 < resScale < 1) reduce precision - to favor speed and size - @return true if the path represents style fill, or false if it represents hairline - */ - bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect, - SkScalar resScale = 1) const; - - bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect, - const SkMatrix& ctm) const; - - /** Returns the filled equivalent of the stroked path. - - Replaces dst with the src path modified by SkPathEffect and style stroke. - SkPathEffect, if any, is not culled. stroke width is created with default precision. - - @param src SkPath read to create a filled version - @param dst resulting SkPath dst may be the same as src, but may not be nullptr - @return true if the path represents style fill, or false if it represents hairline - */ - bool getFillPath(const SkPath& src, SkPath* dst) const { - return this->getFillPath(src, dst, nullptr, 1); - } - /** Returns optional colors used when filling a path, such as a gradient. Does not alter SkShader SkRefCnt. diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h index fea6932e04035..0b69dd2b6fd95 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h @@ -10,20 +10,29 @@ #include "include/core/SkMatrix.h" #include "include/core/SkPathTypes.h" +#include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTo.h" - +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" + +#include +#include +#include #include #include +#include -class SkAutoPathBoundsUpdate; class SkData; class SkPathRef; class SkRRect; class SkWStream; - enum class SkPathConvexity; enum class SkPathFirstDirection; +struct SkPathVerbAnalysis; // WIP -- define this locally, and fix call-sites to use SkPathBuilder (skbug.com/9000) //#define SK_HIDE_PATH_EDIT_METHODS @@ -1866,6 +1875,16 @@ class SK_API SkPath { */ void shrinkToFit(); + // Creates a new Path after the supplied arguments have been validated by + // sk_path_analyze_verbs(). + static SkPath MakeInternal(const SkPathVerbAnalysis& analsis, + const SkPoint points[], + const uint8_t verbs[], + int verbCount, + const SkScalar conics[], + SkPathFillType fillType, + bool isVolatile); + friend class SkAutoPathBoundsUpdate; friend class SkAutoDisableOvalCheck; friend class SkAutoDisableDirectionCheck; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h index b52eaaaa96b0b..247c08624c554 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h @@ -8,11 +8,19 @@ #ifndef SkPathBuilder_DEFINED #define SkPathBuilder_DEFINED -#include "include/core/SkMatrix.h" #include "include/core/SkPath.h" #include "include/core/SkPathTypes.h" +#include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTDArray.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/SkPathRef.h" +#include "include/private/base/SkTo.h" + +#include + +class SkRRect; class SK_API SkPathBuilder { public: @@ -220,9 +228,9 @@ class SK_API SkPathBuilder { } private: - SkTDArray fPts; - SkTDArray fVerbs; - SkTDArray fConicWeights; + SkPathRef::PointsArray fPts; + SkPathRef::VerbsArray fVerbs; + SkPathRef::ConicWeightsArray fConicWeights; SkPathFillType fFillType; bool fIsVolatile; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h index 2335c7c23ce13..167b18278d923 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h @@ -10,7 +10,7 @@ #include "include/core/SkContourMeasure.h" #include "include/core/SkPath.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" class SK_API SkPathMeasure { public: diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h index f589ea46ce2e3..963a6bda00b00 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h @@ -8,8 +8,6 @@ #ifndef SkPathTypes_DEFINED #define SkPathTypes_DEFINED -#include "include/core/SkTypes.h" - enum class SkPathFillType { /** Specifies that "inside" is computed by a non-zero sum of signed edge crossings */ kWinding, diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h new file mode 100644 index 0000000000000..6285da7996033 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h @@ -0,0 +1,42 @@ +/* + * 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 SkPathUtils_DEFINED +#define SkPathUtils_DEFINED + +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" + +class SkMatrix; +class SkPaint; +class SkPath; +struct SkRect; + +namespace skpathutils { + +/** Returns the filled equivalent of the stroked path. + + @param src SkPath read to create a filled version + @param paint SkPaint, from which attributes such as stroke cap, width, miter, and join, + as well as pathEffect will be used. + @param dst resulting SkPath; may be the same as src, but may not be nullptr + @param cullRect optional limit passed to SkPathEffect + @param resScale if > 1, increase precision, else if (0 < resScale < 1) reduce precision + to favor speed and size + @return true if the dst path was updated, false if it was not (e.g. if the path + represents hairline and cannot be filled). +*/ +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, + const SkRect *cullRect, SkScalar resScale = 1); + +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, + const SkRect *cullRect, const SkMatrix &ctm); + +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst); + +} + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h index b6422dd56e3ee..bb384dfab1b8c 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h @@ -243,8 +243,9 @@ class SK_API SkPicture : public SkRefCnt { void serialize(SkWStream*, const SkSerialProcs*, class SkRefCntSet* typefaces, bool textBlobsOnly=false) const; - static sk_sp MakeFromStream(SkStream*, const SkDeserialProcs*, - class SkTypefacePlayback*); + static sk_sp MakeFromStreamPriv(SkStream*, const SkDeserialProcs*, + class SkTypefacePlayback*, + int recursionLimit); friend class SkPictureData; /** Return true if the SkStream/Buffer represents a serialized picture, and diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h index af3926dd25f0f..d91d105000ef0 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h @@ -12,6 +12,8 @@ #include "include/core/SkPicture.h" #include "include/core/SkRefCnt.h" +#include + #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK namespace android { class Picture; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h index ce25665b01a6a..12779890f8859 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h @@ -8,20 +8,16 @@ #ifndef SkPixelRef_DEFINED #define SkPixelRef_DEFINED -#include "include/core/SkBitmap.h" -#include "include/core/SkImageInfo.h" -#include "include/core/SkPixmap.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/private/SkIDChangeListener.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkTo.h" #include +#include +#include -struct SkIRect; - -class GrTexture; class SkDiscardableMemory; /** \class SkPixelRef diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h index 7bc2aa05ac73e..ad4c7dd6d8464 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h @@ -9,11 +9,21 @@ #define SkPixmap_DEFINED #include "include/core/SkColor.h" +#include "include/core/SkColorType.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkRect.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkSamplingOptions.h" +#include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" + +#include +#include class SkColorSpace; -class SkData; +enum SkAlphaType : int; struct SkMask; /** \class SkPixmap @@ -702,39 +712,21 @@ class SK_API SkPixmap { */ bool erase(SkColor color) const { return this->erase(color, this->bounds()); } - /** Writes color to pixels bounded by subset; returns true on success. - if subset is nullptr, writes colors pixels inside bounds(). Returns false if - colorType() is kUnknown_SkColorType, if subset is not nullptr and does - not intersect bounds(), or if subset is nullptr and bounds() is empty. - - @param color sRGB unpremultiplied color to write - @param subset bounding integer SkRect of pixels to write; may be nullptr - @return true if pixels are changed - - example: https://fiddle.skia.org/c/@Pixmap_erase_3 - */ - bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const { - return this->erase(color, nullptr, subset); - } - /** Writes color to pixels bounded by subset; returns true on success. if subset is nullptr, writes colors pixels inside bounds(). Returns false if colorType() is kUnknown_SkColorType, if subset is not nullptr and does not intersect bounds(), or if subset is nullptr and bounds() is empty. @param color unpremultiplied color to write - @param cs SkColorSpace of color @param subset bounding integer SkRect of pixels to write; may be nullptr @return true if pixels are changed */ - bool erase(const SkColor4f& color, SkColorSpace* cs, const SkIRect* subset = nullptr) const; + bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const; private: const void* fPixels; size_t fRowBytes; SkImageInfo fInfo; - - friend class SkPixmapPriv; }; #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h index 92cb0b7f09994..a5e7fa09fbab5 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h @@ -8,9 +8,11 @@ #ifndef SkPoint_DEFINED #define SkPoint_DEFINED -#include "include/core/SkMath.h" #include "include/core/SkScalar.h" -#include "include/private/SkSafe32.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkSafe32.h" + +#include struct SkIPoint; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h index 05434c0942517..0bd4034fdcda6 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h @@ -10,7 +10,7 @@ #include "include/core/SkTypes.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/core/SkRefCnt.h" #include "include/gpu/GrBackendSurface.h" /** @@ -41,6 +41,6 @@ class SK_API SkPromiseImageTexture : public SkNVRefCnt { GrBackendTexture fBackendTexture; }; -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) #endif // SkPromiseImageTexture_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h index 099385168ff73..73bc4a95b99ec 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h @@ -10,8 +10,12 @@ #include "include/core/SkPoint.h" #include "include/core/SkRect.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" + +#include +#include -class SkPath; class SkMatrix; class SkString; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h index 9467a331c3e19..1ed7823c23773 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h @@ -9,12 +9,15 @@ #define SkRect_DEFINED #include "include/core/SkPoint.h" +#include "include/core/SkScalar.h" #include "include/core/SkSize.h" -#include "include/private/SkSafe32.h" -#include "include/private/SkTFitsIn.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkSafe32.h" +#include "include/private/base/SkTFitsIn.h" +#include #include -#include +#include struct SkRect; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h index fc687b3840171..668de14e1d1af 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h @@ -9,14 +9,14 @@ #define SkRefCnt_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkDebug.h" -#include // std::atomic, std::memory_order_* -#include // std::nullptr_t -#include // std::basic_ostream -#include // TODO: unused -#include // std::enable_if, std::is_convertible -#include // std::forward, std::swap +#include +#include +#include +#include +#include +#include /** \class SkRefCntBase @@ -174,7 +174,7 @@ class SkNVRefCnt { bool unique() const { return 1 == fRefCnt.load(std::memory_order_acquire); } void ref() const { (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed); } - void unref() const { + void unref() const { if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) { // restore the 1 for our destructor's assert SkDEBUGCODE(fRefCnt.store(1, std::memory_order_relaxed)); @@ -217,12 +217,7 @@ class SkNVRefCnt { * may be considered as trivially relocatable by the compiler so that destroying-move operations * i.e. move constructor followed by destructor can be optimized to memcpy. */ -#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::trivial_abi) -#define SK_SP_TRIVIAL_ABI [[clang::trivial_abi]] -#else -#define SK_SP_TRIVIAL_ABI -#endif -template class SK_SP_TRIVIAL_ABI sk_sp { +template class SK_TRIVIAL_ABI sk_sp { public: using element_type = T; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h index 463a39ff36d54..6f8aa25d54282 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h @@ -9,7 +9,7 @@ #define SkRegion_DEFINED #include "include/core/SkRect.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTypeTraits.h" class SkPath; class SkRgnBuilder; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h index 2a6bb3ec361ef..f3e11b34c2504 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h @@ -8,10 +8,8 @@ #ifndef SkScalar_DEFINED #define SkScalar_DEFINED -#include "include/private/SkFloatingPoint.h" - -#undef SK_SCALAR_IS_FLOAT -#define SK_SCALAR_IS_FLOAT 1 +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkFloatingPoint.h" typedef float SkScalar; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h index 87e10d847ce6c..a9a0386370cd9 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h @@ -8,9 +8,15 @@ #ifndef SkSerialProcs_DEFINED #define SkSerialProcs_DEFINED -#include "include/core/SkImage.h" -#include "include/core/SkPicture.h" -#include "include/core/SkTypeface.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" + +#include + +class SkData; +class SkImage; +class SkPicture; +class SkTypeface; /** * A serial-proc is asked to serialize the specified object (e.g. picture or image). @@ -22,30 +28,32 @@ * The default action for typefaces is to use Skia's internal format. */ -typedef sk_sp (*SkSerialPictureProc)(SkPicture*, void* ctx); -typedef sk_sp (*SkSerialImageProc)(SkImage*, void* ctx); -typedef sk_sp (*SkSerialTypefaceProc)(SkTypeface*, void* ctx); +using SkSerialPictureProc = sk_sp (*)(SkPicture*, void* ctx); +using SkSerialImageProc = sk_sp (*)(SkImage*, void* ctx); +using SkSerialTypefaceProc = sk_sp (*)(SkTypeface*, void* ctx); /** * Called with the encoded form of a picture (previously written with a custom * SkSerialPictureProc proc). Return a picture object, or nullptr indicating failure. */ -typedef sk_sp (*SkDeserialPictureProc)(const void* data, size_t length, void* ctx); +using SkDeserialPictureProc = sk_sp (*)(const void* data, size_t length, void* ctx); /** - * Called with the encoded from of an image. The proc can return an image object, or if it + * Called with the encoded form of an image. The proc can return an image object, or if it * returns nullptr, then Skia will take its default action to try to create an image from the data. * + * This will also be used to decode the internal mipmap layers that are saved on some images. + * * Note that unlike SkDeserialPictureProc and SkDeserialTypefaceProc, return nullptr from this * does not indicate failure, but is a signal for Skia to take its default action. */ -typedef sk_sp (*SkDeserialImageProc)(const void* data, size_t length, void* ctx); +using SkDeserialImageProc = sk_sp (*)(const void* data, size_t length, void* ctx); /** * Called with the encoded form of a typeface (previously written with a custom * SkSerialTypefaceProc proc). Return a typeface object, or nullptr indicating failure. */ -typedef sk_sp (*SkDeserialTypefaceProc)(const void* data, size_t length, void* ctx); +using SkDeserialTypefaceProc = sk_sp (*)(const void* data, size_t length, void* ctx); struct SK_API SkSerialProcs { SkSerialPictureProc fPictureProc = nullptr; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h index 1c05c6238cb59..be42a87b9a9c6 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h @@ -56,69 +56,6 @@ class SK_API SkShader : public SkFlattenable { return this->isAImage(nullptr, (SkTileMode*)nullptr) != nullptr; } - // TODO(skbug.com/8941): Have Android use SkAndroidFrameworkUtils, move types to SkShaderBase, - // and delete asAGradient(). -#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK -private: -#endif - - /** - * If the shader subclass can be represented as a gradient, asAGradient - * returns the matching GradientType enum (or kNone_GradientType if it - * cannot). Also, if info is not null, asAGradient populates info with - * the relevant (see below) parameters for the gradient. fColorCount - * is both an input and output parameter. On input, it indicates how - * many entries in fColors and fColorOffsets can be used, if they are - * non-NULL. After asAGradient has run, fColorCount indicates how - * many color-offset pairs there are in the gradient. If there is - * insufficient space to store all of the color-offset pairs, fColors - * and fColorOffsets will not be altered. fColorOffsets specifies - * where on the range of 0 to 1 to transition to the given color. - * The meaning of fPoint and fRadius is dependant on the type of gradient. - * - * None: - * info is ignored. - * Color: - * fColorOffsets[0] is meaningless. - * Linear: - * fPoint[0] and fPoint[1] are the end-points of the gradient - * Radial: - * fPoint[0] and fRadius[0] are the center and radius - * Conical: - * fPoint[0] and fRadius[0] are the center and radius of the 1st circle - * fPoint[1] and fRadius[1] are the center and radius of the 2nd circle - * Sweep: - * fPoint[0] is the center of the sweep. - */ - - enum GradientType { - kNone_GradientType, - kColor_GradientType, - kLinear_GradientType, - kRadial_GradientType, - kSweep_GradientType, - kConical_GradientType, - }; - - struct GradientInfo { - int fColorCount = 0; //!< In-out parameter, specifies passed size - // of fColors/fColorOffsets on input, and - // actual number of colors/offsets on - // output. - SkColor* fColors = nullptr; //!< The colors in the gradient. - SkScalar* fColorOffsets = nullptr; //!< The unit offset for color transitions. - SkPoint fPoint[2]; //!< Type specific, see above. - SkScalar fRadius[2]; //!< Type specific, see above. - SkTileMode fTileMode; - uint32_t fGradientFlags = 0; //!< see SkGradientShader::Flags - }; - - GradientType asAGradient(GradientInfo* info) const; - -#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK -public: -#endif - ////////////////////////////////////////////////////////////////////////// // Methods to create combinations or variants of shaders @@ -148,7 +85,7 @@ class SK_API SkShaders { static sk_sp Color(const SkColor4f&, sk_sp); static sk_sp Blend(SkBlendMode mode, sk_sp dst, sk_sp src); static sk_sp Blend(sk_sp, sk_sp dst, sk_sp src); - + static sk_sp CoordClamp(sk_sp, const SkRect& subset); private: SkShaders() = delete; }; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h index 79d673775e8d1..867f4eeb97b90 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h @@ -10,6 +10,8 @@ #include "include/core/SkScalar.h" +#include + struct SkISize { int32_t fWidth; int32_t fHeight; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h index 03eb3b5b0fb66..37cac632b1e8d 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h @@ -5,117 +5,9 @@ * found in the LICENSE file. */ -#ifndef SkSpan_DEFINED -#define SkSpan_DEFINED +// We want SkSpan to be a public API, but it is also fundamental to many of our internal types. +// Thus, we have a public file that clients can include. This file defers to the private copy +// so we do not have a dependency cycle from our "base" files to our "core" files. -#include -#include -#include -#include -#include -#include "include/private/SkTLogic.h" +#include "include/private/base/SkSpan_impl.h" // IWYU pragma: export -// Add macro to check the lifetime of initializer_list arguments. initializer_list has a very -// short life span, and can only be used as a parameter, and not as a variable. -#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::lifetimebound) -#define SK_CHECK_IL_LIFETIME [[clang::lifetimebound]] -#else -#define SK_CHECK_IL_LIFETIME -#endif - -/** - * SkSpan holds a reference to contiguous data of type T along with a count. SkSpan does not own - * the data itself but is merely a reference, therefore you must take care with the lifetime of - * the underlying data. - * - * SkSpan is a count and a pointer into existing array or data type that stores its data in - * contiguous memory like std::vector. Any container that works with std::size() and std::data() - * can be used. - * - * SkSpan makes a convenient parameter for a routine to accept array like things. This allows you to - * write the routine without overloads for all different container types. - * - * Example: - * void routine(SkSpan a) { ... } - * - * std::vector v = {1, 2, 3, 4, 5}; - * - * routine(a); - * - * A word of caution when working with initializer_list, initializer_lists have a lifetime that is - * limited to the current statement. The following is correct and safe: - * - * Example: - * routine({1,2,3,4,5}); - * - * The following is undefined, and will result in erratic execution: - * - * Bad Example: - * initializer_list l = {1, 2, 3, 4, 5}; // The data behind l dies at the ;. - * routine(l); - */ -template -class SkSpan { -public: - constexpr SkSpan() : fPtr{nullptr}, fSize{0} {} - constexpr SkSpan(T* ptr, size_t size) : fPtr{ptr}, fSize{size} { - SkASSERT(ptr || size == 0); // disallow nullptr + a nonzero size - SkASSERT(size < kMaxSize); - } - template ::value>::type> - constexpr SkSpan(const SkSpan& that) : fPtr(std::data(that)), fSize{std::size(that)} {} - constexpr SkSpan(const SkSpan& o) = default; - template constexpr SkSpan(T(&a)[N]) : SkSpan(a, N) { } - template - constexpr SkSpan(Container& c) : SkSpan{std::data(c), std::size(c)} { } - SkSpan(std::initializer_list il SK_CHECK_IL_LIFETIME) - : SkSpan(std::data(il), std::size(il)) {} - - constexpr SkSpan& operator=(const SkSpan& that) = default; - - constexpr T& operator [] (size_t i) const { - SkASSERT(i < this->size()); - return fPtr[i]; - } - constexpr T& front() const { return fPtr[0]; } - constexpr T& back() const { return fPtr[fSize - 1]; } - constexpr T* begin() const { return fPtr; } - constexpr T* end() const { return fPtr + fSize; } - constexpr auto rbegin() const { return std::make_reverse_iterator(this->end()); } - constexpr auto rend() const { return std::make_reverse_iterator(this->begin()); } - constexpr T* data() const { return this->begin(); } - constexpr size_t size() const { return fSize; } - constexpr bool empty() const { return fSize == 0; } - constexpr size_t size_bytes() const { return fSize * sizeof(T); } - constexpr SkSpan first(size_t prefixLen) const { - SkASSERT(prefixLen <= this->size()); - return SkSpan{fPtr, prefixLen}; - } - constexpr SkSpan last(size_t postfixLen) const { - SkASSERT(postfixLen <= this->size()); - return SkSpan{fPtr + (this->size() - postfixLen), postfixLen}; - } - constexpr SkSpan subspan(size_t offset) const { - return this->subspan(offset, this->size() - offset); - } - constexpr SkSpan subspan(size_t offset, size_t count) const { - SkASSERT(offset <= this->size()); - SkASSERT(count <= this->size() - offset); - return SkSpan{fPtr + offset, count}; - } - -private: - static const constexpr size_t kMaxSize = std::numeric_limits::max() / sizeof(T); - T* fPtr; - size_t fSize; -}; - -template -SkSpan(Container&) -> - SkSpan()))>>; - -template -SkSpan(std::initializer_list) -> - SkSpan>()))>>; - -#endif // SkSpan_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h index 768de9b5a33d0..c582c80a0528c 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h @@ -11,15 +11,16 @@ #include "include/core/SkData.h" #include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" -#include "include/private/SkTo.h" - -#include - -class SkStream; -class SkStreamRewindable; -class SkStreamSeekable; +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkTo.h" + +#include +#include +#include +#include +#include class SkStreamAsset; -class SkStreamMemory; /** * SkStream -- abstraction for a source of bytes. Subclasses can be backed by @@ -255,10 +256,10 @@ class SK_API SkWStream { bool writeText(const char text[]) { SkASSERT(text); - return this->write(text, strlen(text)); + return this->write(text, std::strlen(text)); } - bool newline() { return this->write("\n", strlen("\n")); } + bool newline() { return this->write("\n", std::strlen("\n")); } bool writeDecAsText(int32_t); bool writeBigDecAsText(int64_t, int minDigits = 0); @@ -296,8 +297,6 @@ class SK_API SkNullWStream : public SkWStream { //////////////////////////////////////////////////////////////////////////////////////// -#include - /** A stream that wraps a C FILE* file stream. */ class SK_API SkFILEStream : public SkStreamAsset { public: diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkString.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkString.h index e659910c6f00e..1b27fbf44b07c 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkString.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkString.h @@ -11,15 +11,16 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" -#include -#include #include +#include +#include +#include #include #include +#include /* Some helper functions for C strings */ static inline bool SkStrStartsWith(const char string[], const char prefixStr[]) { @@ -128,6 +129,7 @@ class SK_API SkString { bool isEmpty() const { return 0 == fRec->fLength; } size_t size() const { return (size_t) fRec->fLength; } + const char* data() const { return fRec->data(); } const char* c_str() const { return fRec->data(); } char operator[](size_t n) const { return this->c_str()[n]; } @@ -173,8 +175,8 @@ class SK_API SkString { SkString& operator=(SkString&&); SkString& operator=(const char text[]); - char* writable_str(); - char& operator[](size_t n) { return this->writable_str()[n]; } + char* data(); + char& operator[](size_t n) { return this->data()[n]; } void reset(); /** String contents are preserved on resize. (For destructive resize, `set(nullptr, length)`.) @@ -286,22 +288,4 @@ static inline void swap(SkString& a, SkString& b) { a.swap(b); } -enum SkStrSplitMode { - // Strictly return all results. If the input is ",," and the separator is ',' this will return - // an array of three empty strings. - kStrict_SkStrSplitMode, - - // Only nonempty results will be added to the results. Multiple separators will be - // coalesced. Separators at the beginning and end of the input will be ignored. If the input is - // ",," and the separator is ',', this will return an empty vector. - kCoalesce_SkStrSplitMode -}; - -// Split str on any characters in delimiters into out. (Think, strtok with a sane API.) -void SkStrSplit(const char* str, const char* delimiters, SkStrSplitMode splitMode, - SkTArray* out); -inline void SkStrSplit(const char* str, const char* delimiters, SkTArray* out) { - SkStrSplit(str, delimiters, kCoalesce_SkStrSplitMode, out); -} - #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h index b4796fcbfa6ca..1257d04a844b7 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h @@ -9,7 +9,7 @@ #define SkStrokeRec_DEFINED #include "include/core/SkPaint.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" class SkPath; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h index 98dcfdefcb3db..3673d172b6d02 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h @@ -9,41 +9,61 @@ #define SkSurface_DEFINED #include "include/core/SkImage.h" +#include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkSamplingOptions.h" +#include "include/core/SkScalar.h" #include "include/core/SkSurfaceProps.h" +#include "include/core/SkTypes.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrTypes.h" +#else +enum GrSurfaceOrigin: int; +#endif + +#if defined(SK_GRAPHITE) +#include "include/gpu/GpuTypes.h" +namespace skgpu::graphite { +class BackendTexture; +} #endif #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 #include +class GrDirectContext; #endif -#if SK_SUPPORT_GPU && defined(SK_METAL) +#if defined(SK_GANESH) && defined(SK_METAL) #include "include/gpu/mtl/GrMtlTypes.h" #endif +#include +#include +#include + +class GrBackendRenderTarget; +class GrBackendSemaphore; +class GrBackendTexture; +class GrRecordingContext; +class SkBitmap; class SkCanvas; class SkCapabilities; +class SkColorSpace; class SkDeferredDisplayList; class SkPaint; class SkSurfaceCharacterization; -class GrBackendRenderTarget; -class GrBackendSemaphore; -class GrBackendTexture; -class GrDirectContext; -class GrRecordingContext; -class GrRenderTarget; -enum GrSurfaceOrigin: int; +enum SkColorType : int; +struct SkIRect; +struct SkISize; namespace skgpu { class MutableTextureState; +enum class Budgeted : bool; } namespace skgpu::graphite { -class BackendTexture; class Recorder; } @@ -206,7 +226,7 @@ class SK_API SkSurface : public SkRefCnt { backend API (accounting only for use of the texture by this surface). If SkSurface creation fails textureReleaseProc is called before this function returns. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param backendTexture texture residing on GPU @@ -241,7 +261,7 @@ class SK_API SkSurface : public SkRefCnt { backend API (accounting only for use of the render target by this surface). If SkSurface creation fails releaseProc is called before this function returns. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param backendRenderTarget GPU intermediate memory buffer @@ -276,7 +296,7 @@ class SK_API SkSurface : public SkRefCnt { shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace; @@ -287,9 +307,11 @@ class SK_API SkSurface : public SkRefCnt { @param shouldCreateWithMips hint that SkSurface will host mip map images @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, const SkImageInfo& imageInfo, - int sampleCount, GrSurfaceOrigin surfaceOrigin, + int sampleCount, + GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps* surfaceProps, bool shouldCreateWithMips = false); @@ -314,10 +336,12 @@ class SK_API SkSurface : public SkRefCnt { fonts; may be nullptr @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, - const SkImageInfo& imageInfo, int sampleCount, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, + const SkImageInfo& imageInfo, + int sampleCount, const SkSurfaceProps* surfaceProps) { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) return MakeRenderTarget(context, budgeted, imageInfo, sampleCount, kBottomLeft_GrSurfaceOrigin, surfaceProps); #else @@ -339,9 +363,10 @@ class SK_API SkSurface : public SkRefCnt { of raster surface; width, or height, or both, may be zero @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, const SkImageInfo& imageInfo) { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) if (!imageInfo.width() || !imageInfo.height()) { return nullptr; } @@ -362,8 +387,7 @@ class SK_API SkSurface : public SkRefCnt { */ static sk_sp MakeRenderTarget(GrRecordingContext* context, const SkSurfaceCharacterization& characterization, - SkBudgeted budgeted); - + skgpu::Budgeted budgeted); #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 /** Private. @@ -398,7 +422,7 @@ class SK_API SkSurface : public SkRefCnt { ); #endif -#ifdef SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) /** * In Graphite, while clients hold a ref on an SkSurface, the backing gpu object does _not_ * count against the budget. Once an SkSurface is freed, the backing gpu object may or may @@ -408,7 +432,7 @@ class SK_API SkSurface : public SkRefCnt { static sk_sp MakeGraphite( skgpu::graphite::Recorder*, const SkImageInfo& imageInfo, - skgpu::graphite::Mipmapped = skgpu::graphite::Mipmapped::kNo, + skgpu::Mipmapped = skgpu::Mipmapped::kNo, const SkSurfaceProps* surfaceProps = nullptr); /** @@ -430,9 +454,9 @@ class SK_API SkSurface : public SkRefCnt { sk_sp colorSpace, const SkSurfaceProps* props); -#endif // SK_GRAPHITE_ENABLED +#endif // SK_GRAPHITE -#if SK_SUPPORT_GPU && defined(SK_METAL) +#if defined(SK_GANESH) && defined(SK_METAL) /** Creates SkSurface from CAMetalLayer. Returned SkSurface takes a reference on the CAMetalLayer. The ref on the layer will be released when the SkSurface is destroyed. @@ -525,7 +549,7 @@ class SK_API SkSurface : public SkRefCnt { /** Returns an ImageInfo describing the surface. */ - SkImageInfo imageInfo(); + virtual SkImageInfo imageInfo() const { return SkImageInfo::MakeUnknown(fWidth, fHeight); } /** Returns unique value identifying the content of SkSurface. Returned value changes each time the content changes. Content is changed by drawing, or by calling @@ -566,7 +590,7 @@ class SK_API SkSurface : public SkRefCnt { */ skgpu::graphite::Recorder* recorder(); -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) enum BackendHandleAccess { kFlushRead_BackendHandleAccess, //!< back-end object is readable kFlushWrite_BackendHandleAccess, //!< back-end object is writable @@ -669,7 +693,7 @@ class SK_API SkSurface : public SkRefCnt { /** Returns SkImage capturing SkSurface contents. Subsequent drawing to SkSurface contents are not captured. SkImage allocation is accounted for if SkSurface was created with - SkBudgeted::kYes. + skgpu::Budgeted::kYes. @return SkImage initialized with SkSurface contents @@ -690,6 +714,34 @@ class SK_API SkSurface : public SkRefCnt { */ sk_sp makeImageSnapshot(const SkIRect& bounds); +#if defined(SK_GRAPHITE) + /** + * The 'asImage' and 'makeImageCopy' API/entry points are currently only available for + * Graphite. + * + * In this API, SkSurface no longer supports copy-on-write behavior. Instead, when creating + * an image for a surface, the client must explicitly indicate if a copy should be made. + * In both of the below calls the resource backing the surface will never change. + * + * The 'asImage' entry point has some major ramifications for the mutability of the + * returned SkImage. Since the originating surface and the returned image share the + * same backing, care must be taken by the client to ensure that the contents of the image + * reflect the desired contents when it is consumed by the gpu. + * Note: if the backing GPU buffer isn't textureable this method will return null. Graphite + * will not attempt to make a copy. + * Note: For 'asImage', the mipmapping of the image will match that of the source surface. + * + * The 'makeImageCopy' entry point allows subsetting and the addition of mipmaps (since + * a copy is already being made). + * + * In Graphite, the legacy API call (i.e., makeImageSnapshot) will just always make a copy. + */ + sk_sp asImage(); + + sk_sp makeImageCopy(const SkIRect* subset = nullptr, + skgpu::Mipmapped mipmapped = skgpu::Mipmapped::kNo); +#endif + /** Draws SkSurface contents to canvas, with its top-left corner at (x, y). If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter, and SkBlendMode. @@ -834,36 +886,6 @@ class SK_API SkSurface : public SkRefCnt { using RescaleGamma = SkImage::RescaleGamma; using RescaleMode = SkImage::RescaleMode; - /** Makes surface pixel data available to caller, possibly asynchronously. - - Currently asynchronous reads are only supported on the GPU backend and only when the - underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all - other cases this operates synchronously. - - Data is read from the source sub-rectangle, then converted to the color space, color type, - and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the surface - causes failure. - - When the pixel data is ready the caller's ReadPixelsCallback is called with a - AsyncReadResult containing pixel data in the requested color type, alpha type, and color - space. The AsyncReadResult will have count() == 1. Upon failure the callback is called - with nullptr for AsyncReadResult. For a GPU surface this flushes work but a submit must - occur to guarantee a finite time before the callback is called. - - The data is valid for the lifetime of AsyncReadResult with the exception that if the - SkSurface is GPU-backed the data is immediately invalidated if the context is abandoned - or destroyed. - - @param info info of the requested pixels - @param srcRect subrectangle of surface to read - @param callback function to call with result of the read - @param context passed to callback - */ - void asyncReadPixels(const SkImageInfo& info, - const SkIRect& srcRect, - ReadPixelsCallback callback, - ReadPixelsContext context); - /** Makes surface pixel data available to caller, possibly asynchronously. It can also rescale the surface pixels. @@ -994,7 +1016,7 @@ class SK_API SkSurface : public SkRefCnt { kPresent, //!< back-end surface will be used for presenting to screen }; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** If a surface is GPU texture backed, is being drawn with MSAA, and there is a resolve texture, this call will insert a resolve command into the stream of gpu commands. In order for the resolve to actually have an effect, the work still needs to be flushed and submitted @@ -1100,7 +1122,7 @@ class SK_API SkSurface : public SkRefCnt { */ GrSemaphoresSubmitted flush(const GrFlushInfo& info, const skgpu::MutableTextureState* newState = nullptr); -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) void flush(); diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h index 91b10e87bf7a9..0b65a10d03c4b 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h @@ -17,7 +17,7 @@ class SkColorSpace; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrContextThreadSafeProxy.h" #include "include/gpu/GrTypes.h" @@ -118,7 +118,7 @@ class SK_API SkSurfaceCharacterization { bool isCompatible(const GrBackendTexture&) const; private: - friend class SkSurface_Gpu; // for 'set' & 'config' + friend class SkSurface_Ganesh; // for 'set' & 'config' friend class GrVkSecondaryCBDrawContext; // for 'set' & 'config' friend class GrContextThreadSafeProxy; // for private ctor friend class SkDeferredDisplayListRecorder; // for 'config' @@ -210,7 +210,7 @@ class SK_API SkSurfaceCharacterization { SkSurfaceProps fSurfaceProps; }; -#else// !SK_SUPPORT_GPU +#else// !defined(SK_GANESH) class GrBackendFormat; class SK_API SkSurfaceCharacterization { diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h index 7b07554e5be34..4790f258e4ad5 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h @@ -9,6 +9,7 @@ #define SkSurfaceProps_DEFINED #include "include/core/SkTypes.h" +#include "include/private/base/SkTo.h" /** * Description of how the LCD strips are arranged for each pixel. If this is unknown, or the @@ -53,7 +54,10 @@ class SK_API SkSurfaceProps { enum Flags { kUseDeviceIndependentFonts_Flag = 1 << 0, // Use internal MSAA to render to non-MSAA GPU surfaces. - kDynamicMSAA_Flag = 1 << 1 + kDynamicMSAA_Flag = 1 << 1, + // If set, all rendering will have dithering enabled + // Currently this only impacts GPU backends + kAlwaysDither_Flag = 1 << 2, }; /** Deprecated alias used by Chromium. Will be removed. */ static const Flags kUseDistanceFieldFonts_Flag = kUseDeviceIndependentFonts_Flag; @@ -76,6 +80,10 @@ class SK_API SkSurfaceProps { return SkToBool(fFlags & kUseDeviceIndependentFonts_Flag); } + bool isAlwaysDither() const { + return SkToBool(fFlags & kAlwaysDither_Flag); + } + bool operator==(const SkSurfaceProps& that) const { return fFlags == that.fFlags && fPixelGeometry == that.fPixelGeometry; } diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h index e010ea9cc788d..8f6cb01c045ff 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h @@ -12,7 +12,7 @@ #include "include/core/SkPaint.h" #include "include/core/SkRefCnt.h" #include "include/core/SkString.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include @@ -491,7 +491,7 @@ class SK_API SkTextBlobBuilder { friend class SkTextBlobPriv; friend class SkTextBlobBuilderPriv; - SkAutoTMalloc fStorage; + skia_private::AutoTMalloc fStorage; size_t fStorageSize; size_t fStorageUsed; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h new file mode 100644 index 0000000000000..e9b441378d0c4 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h @@ -0,0 +1,30 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkTextureCompressionType_DEFINED +#define SkTextureCompressionType_DEFINED +/* + * Skia | GL_COMPRESSED_* | MTLPixelFormat* | VK_FORMAT_*_BLOCK + * -------------------------------------------------------------------------------------- + * kETC2_RGB8_UNORM | ETC1_RGB8 | ETC2_RGB8 (iOS-only) | ETC2_R8G8B8_UNORM + * | RGB8_ETC2 | | + * -------------------------------------------------------------------------------------- + * kBC1_RGB8_UNORM | RGB_S3TC_DXT1_EXT | N/A | BC1_RGB_UNORM + * -------------------------------------------------------------------------------------- + * kBC1_RGBA8_UNORM | RGBA_S3TC_DXT1_EXT | BC1_RGBA (macOS-only)| BC1_RGBA_UNORM + */ +enum class SkTextureCompressionType { + kNone, + kETC2_RGB8_UNORM, + + kBC1_RGB8_UNORM, + kBC1_RGBA8_UNORM, + kLast = kBC1_RGBA8_UNORM, + kETC1_RGB8 = kETC2_RGB8_UNORM, +}; + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h index 3da2c8c7715b9..9135c7e113c0d 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h @@ -11,7 +11,7 @@ #define SkTime_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" #include diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h index d4a13877152d3..9e099d41e37f5 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h @@ -14,8 +14,8 @@ #include "include/core/SkFontTypes.h" #include "include/core/SkRect.h" #include "include/core/SkString.h" -#include "include/private/SkOnce.h" #include "include/private/SkWeakRefCnt.h" +#include "include/private/base/SkOnce.h" class SkData; class SkDescriptor; @@ -360,6 +360,12 @@ class SK_API SkTypeface : public SkWeakRefCnt { return this->onGetCTFontRef(); } + /* Skia reserves all tags that begin with a lower case letter and 0 */ + using FactoryId = SkFourByteTag; + static void Register( + FactoryId id, + sk_sp (*make)(std::unique_ptr, const SkFontArguments&)); + protected: explicit SkTypeface(const SkFontStyle& style, bool isFixedPitch = false); ~SkTypeface() override; @@ -435,7 +441,8 @@ class SK_API SkTypeface : public SkWeakRefCnt { * typefaces that contain a COLR table. */ bool glyphMaskNeedsCurrentColor() const; - friend class SkStrikeServerImpl; // glyphMaskNeedsCurrentColor + friend class SkStrikeServerImpl; // glyphMaskNeedsCurrentColor + friend class SkTypefaceProxyPrototype; // glyphMaskNeedsCurrentColor /** Retrieve detailed typeface metrics. Used by the PDF backend. */ std::unique_ptr getAdvancedMetrics() const; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h index 8f7a2c0982b68..5530cc4463b39 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h @@ -8,235 +8,25 @@ #ifndef SkTypes_DEFINED #define SkTypes_DEFINED -/** \file SkTypes.h -*/ - -// Pre-SkUserConfig.h setup. - -// Allows embedders that want to disable macros that take arguments to just -// define that symbol to be one of these -#define SK_NOTHING_ARG1(arg1) -#define SK_NOTHING_ARG2(arg1, arg2) -#define SK_NOTHING_ARG3(arg1, arg2, arg3) - -#if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && \ - !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) - - #ifdef __APPLE__ - #include - #endif - - #if defined(_WIN32) || defined(__SYMBIAN32__) - #define SK_BUILD_FOR_WIN - #elif defined(ANDROID) || defined(__ANDROID__) - #define SK_BUILD_FOR_ANDROID - #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || \ - defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || \ - defined(__DragonFly__) || defined(__Fuchsia__) || \ - defined(__GLIBC__) || defined(__GNU__) || defined(__unix__) - #define SK_BUILD_FOR_UNIX - #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR - #define SK_BUILD_FOR_IOS - #else - #define SK_BUILD_FOR_MAC - #endif - -#endif - -#if defined(SK_BUILD_FOR_WIN) && !defined(__clang__) - #if !defined(SK_RESTRICT) - #define SK_RESTRICT __restrict - #endif - #if !defined(SK_WARN_UNUSED_RESULT) - #define SK_WARN_UNUSED_RESULT - #endif -#endif - -#if !defined(SK_RESTRICT) - #define SK_RESTRICT __restrict__ -#endif - -#if !defined(SK_WARN_UNUSED_RESULT) - #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#endif - -#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) - #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) - #define SK_CPU_BENDIAN - #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) - #define SK_CPU_LENDIAN - #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ - defined(__PPC__) || defined(__PPC64__) || \ - defined(_MIPSEB) || defined(__ARMEB__) || \ - defined(__s390__) || \ - (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ - (defined(__ia64) && defined(__BIG_ENDIAN__)) - #define SK_CPU_BENDIAN - #else - #define SK_CPU_LENDIAN - #endif -#endif - -#if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) - #define SK_CPU_X86 1 -#endif - -/** - * SK_CPU_SSE_LEVEL - * - * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. - * On non-intel CPU this should be undefined. - */ -#define SK_CPU_SSE_LEVEL_SSE1 10 -#define SK_CPU_SSE_LEVEL_SSE2 20 -#define SK_CPU_SSE_LEVEL_SSE3 30 -#define SK_CPU_SSE_LEVEL_SSSE3 31 -#define SK_CPU_SSE_LEVEL_SSE41 41 -#define SK_CPU_SSE_LEVEL_SSE42 42 -#define SK_CPU_SSE_LEVEL_AVX 51 -#define SK_CPU_SSE_LEVEL_AVX2 52 -#define SK_CPU_SSE_LEVEL_SKX 60 - -// Are we in GCC/Clang? -#ifndef SK_CPU_SSE_LEVEL - // These checks must be done in descending order to ensure we set the highest - // available SSE level. - #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ - defined(__AVX512BW__) && defined(__AVX512VL__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX - #elif defined(__AVX2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 - #elif defined(__AVX__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX - #elif defined(__SSE4_2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42 - #elif defined(__SSE4_1__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41 - #elif defined(__SSSE3__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 - #elif defined(__SSE3__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 - #elif defined(__SSE2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #endif -#endif - -// Are we in VisualStudio? -#ifndef SK_CPU_SSE_LEVEL - // These checks must be done in descending order to ensure we set the highest - // available SSE level. 64-bit intel guarantees at least SSE2 support. - #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ - defined(__AVX512BW__) && defined(__AVX512VL__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX - #elif defined(__AVX2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 - #elif defined(__AVX__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX - #elif defined(_M_X64) || defined(_M_AMD64) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #elif defined(_M_IX86_FP) - #if _M_IX86_FP >= 2 - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #elif _M_IX86_FP == 1 - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 - #endif - #endif -#endif - -// ARM defines -#if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) - #define SK_CPU_ARM32 -#elif defined(__aarch64__) - #define SK_CPU_ARM64 -#endif - -// All 64-bit ARM chips have NEON. Many 32-bit ARM chips do too. -#if !defined(SK_ARM_HAS_NEON) && defined(__ARM_NEON) - #define SK_ARM_HAS_NEON -#endif - -#if defined(__ARM_FEATURE_CRC32) - #define SK_ARM_HAS_CRC32 -#endif - - -// DLL/.so exports. -#if !defined(SKIA_IMPLEMENTATION) - #define SKIA_IMPLEMENTATION 0 -#endif -#if !defined(SK_API) - #if defined(SKIA_DLL) - #if defined(_MSC_VER) - #if SKIA_IMPLEMENTATION - #define SK_API __declspec(dllexport) - #else - #define SK_API __declspec(dllimport) - #endif - #else - #define SK_API __attribute__((visibility("default"))) - #endif - #else - #define SK_API - #endif -#endif - -// SK_SPI is functionally identical to SK_API, but used within src to clarify that it's less stable -#if !defined(SK_SPI) - #define SK_SPI SK_API -#endif - +// All of these files should be independent of things users can set via the user config file. +// They should also be able to be included in any order. // IWYU pragma: begin_exports -#if defined (SK_USER_CONFIG_HEADER) - #include SK_USER_CONFIG_HEADER -#else - #include "include/config/SkUserConfig.h" -#endif -// IWYU pragma: end_exports -#include -#include - -// Post SkUserConfig.h checks and such. -#if !defined(SK_DEBUG) && !defined(SK_RELEASE) - #ifdef NDEBUG - #define SK_RELEASE - #else - #define SK_DEBUG - #endif -#endif +#include "include/private/base/SkFeatures.h" -#if defined(SK_DEBUG) && defined(SK_RELEASE) -# error "cannot define both SK_DEBUG and SK_RELEASE" -#elif !defined(SK_DEBUG) && !defined(SK_RELEASE) -# error "must define either SK_DEBUG or SK_RELEASE" -#endif - -#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) -# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" -#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) -# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" -#endif - -#if defined(SK_CPU_BENDIAN) && !defined(I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN) - #error "The Skia team is not endian-savvy enough to support big-endian CPUs." - #error "If you still want to use Skia," - #error "please define I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN." -#endif +// Load and verify defines from the user config file. +#include "include/private/base/SkLoadUserConfig.h" -#if !defined(SK_ATTRIBUTE) -# if defined(__clang__) || defined(__GNUC__) -# define SK_ATTRIBUTE(attr) __attribute__((attr)) -# else -# define SK_ATTRIBUTE(attr) -# endif -#endif +// Any includes or defines below can be configured by the user config file. +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkDebug.h" +// IWYU pragma: end_exports -#if !defined(SK_SUPPORT_GPU) -# define SK_SUPPORT_GPU 1 -#endif +#include +#include -#if SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GANESH) || defined(SK_GRAPHITE) # if !defined(SK_ENABLE_SKSL) # define SK_ENABLE_SKSL # endif @@ -248,45 +38,6 @@ # undef SK_DIRECT3D #endif -#if !defined(SkUNREACHABLE) -# if defined(_MSC_VER) && !defined(__clang__) -# include -# define FAST_FAIL_INVALID_ARG 5 -// See https://developercommunity.visualstudio.com/content/problem/1128631/code-flow-doesnt-see-noreturn-with-extern-c.html -// for why this is wrapped. Hopefully removable after msvc++ 19.27 is no longer supported. -[[noreturn]] static inline void sk_fast_fail() { __fastfail(FAST_FAIL_INVALID_ARG); } -# define SkUNREACHABLE sk_fast_fail() -# else -# define SkUNREACHABLE __builtin_trap() -# endif -#endif - -#if defined(SK_BUILD_FOR_GOOGLE3) - void SkDebugfForDumpStackTrace(const char* data, void* unused); - namespace base { - void DumpStackTrace(int skip_count, void w(const char*, void*), void* arg); - } -# define SK_DUMP_GOOGLE3_STACK() ::base::DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr) -#else -# define SK_DUMP_GOOGLE3_STACK() -#endif - -#ifndef SK_ABORT -# ifdef SK_BUILD_FOR_WIN - // This style lets Visual Studio follow errors back to the source file. -# define SK_DUMP_LINE_FORMAT "%s(%d)" -# else -# define SK_DUMP_LINE_FORMAT "%s:%d" -# endif -# define SK_ABORT(message, ...) \ - do { \ - SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \ - __FILE__, __LINE__, ##__VA_ARGS__); \ - SK_DUMP_GOOGLE3_STACK(); \ - sk_abort_no_print(); \ - } while (false) -#endif - // If SK_R32_SHIFT is set, we'll use that to choose RGBA or BGRA. // If not, we'll default to RGBA everywhere except BGRA on Windows. #if defined(SK_R32_SHIFT) @@ -306,7 +57,6 @@ #define SK_G32_SHIFT 8 #define SK_A32_SHIFT 24 - /** * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. */ @@ -332,48 +82,6 @@ #undef free #endif -#if !defined(SK_UNUSED) -# if !defined(__clang__) && defined(_MSC_VER) -# define SK_UNUSED __pragma(warning(suppress:4189)) -# else -# define SK_UNUSED SK_ATTRIBUTE(unused) -# endif -#endif - -/** - * If your judgment is better than the compiler's (i.e. you've profiled it), - * you can use SK_ALWAYS_INLINE to force inlining. E.g. - * inline void someMethod() { ... } // may not be inlined - * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined - */ -#if !defined(SK_ALWAYS_INLINE) -# if defined(SK_BUILD_FOR_WIN) -# define SK_ALWAYS_INLINE __forceinline -# else -# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline -# endif -#endif - -/** - * If your judgment is better than the compiler's (i.e. you've profiled it), - * you can use SK_NEVER_INLINE to prevent inlining. - */ -#if !defined(SK_NEVER_INLINE) -# if defined(SK_BUILD_FOR_WIN) -# define SK_NEVER_INLINE __declspec(noinline) -# else -# define SK_NEVER_INLINE SK_ATTRIBUTE(noinline) -# endif -#endif - -#ifndef SK_PRINTF_LIKE -# if defined(__clang__) || defined(__GNUC__) -# define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) -# else -# define SK_PRINTF_LIKE(A, B) -# endif -#endif - #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 0 #endif @@ -386,11 +94,6 @@ # define GR_TEST_UTILS 0 #endif -#if !SK_SUPPORT_GPU - #define SK_GPU_V1 0 // always false if Ganesh is disabled -#elif !defined(SK_GPU_V1) -# define SK_GPU_V1 1 // otherwise default to v1 enabled -#endif #if defined(SK_HISTOGRAM_ENUMERATION) || \ defined(SK_HISTOGRAM_BOOLEAN) || \ @@ -420,145 +123,44 @@ #define SK_HISTOGRAM_PERCENTAGE(name, percent_as_int) \ SK_HISTOGRAM_EXACT_LINEAR(name, percent_as_int, 101) -#ifndef SK_DISABLE_LEGACY_SHADERCONTEXT -#define SK_ENABLE_LEGACY_SHADERCONTEXT +// The top-level define SK_ENABLE_OPTIMIZE_SIZE can be used to remove several large features at once +#if defined(SK_ENABLE_OPTIMIZE_SIZE) +# define SK_FORCE_RASTER_PIPELINE_BLITTER +# define SK_DISABLE_SDF_TEXT #endif -#ifdef SK_ENABLE_API_AVAILABLE -#define SK_API_AVAILABLE API_AVAILABLE -#else -#define SK_API_AVAILABLE(...) +#ifndef SK_DISABLE_LEGACY_SHADERCONTEXT +# define SK_ENABLE_LEGACY_SHADERCONTEXT #endif #if defined(SK_BUILD_FOR_LIBFUZZER) || defined(SK_BUILD_FOR_AFL_FUZZ) +#if !defined(SK_BUILD_FOR_FUZZER) #define SK_BUILD_FOR_FUZZER #endif +#endif -/** Called internally if we hit an unrecoverable error. - The platform implementation must not return, but should either throw - an exception or otherwise exit. -*/ -[[noreturn]] SK_API extern void sk_abort_no_print(void); +/** + * Gr defines are set to 0 or 1, rather than being undefined or defined + */ -#ifndef SkDebugf - SK_API void SkDebugf(const char format[], ...) SK_PRINTF_LIKE(1, 2); +#if !defined(GR_CACHE_STATS) + #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) + #define GR_CACHE_STATS 1 + #else + #define GR_CACHE_STATS 0 + #endif #endif -// SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g. -// uint32_t foo(int x) { -// SkASSERT(x > 4); -// return x - 4; -// } -// and are also written to be compatible with constexpr functions: -// constexpr uint32_t foo(int x) { -// return SkASSERT(x > 4), -// x - 4; -// } -#define SkASSERT_RELEASE(cond) \ - static_cast( (cond) ? (void)0 : []{ SK_ABORT("assert(%s)", #cond); }() ) - -#ifdef SK_DEBUG - #define SkASSERT(cond) SkASSERT_RELEASE(cond) - #define SkASSERTF(cond, fmt, ...) static_cast( (cond) ? (void)0 : [&]{ \ - SkDebugf(fmt"\n", ##__VA_ARGS__); \ - SK_ABORT("assert(%s)", #cond); \ - }() ) - #define SkDEBUGFAIL(message) SK_ABORT("%s", message) - #define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__) - #define SkDEBUGCODE(...) __VA_ARGS__ - #define SkDEBUGF(...) SkDebugf(__VA_ARGS__) - #define SkAssertResult(cond) SkASSERT(cond) -#else - #define SkASSERT(cond) static_cast(0) - #define SkASSERTF(cond, fmt, ...) static_cast(0) - #define SkDEBUGFAIL(message) - #define SkDEBUGFAILF(fmt, ...) - #define SkDEBUGCODE(...) - #define SkDEBUGF(...) - - // unlike SkASSERT, this macro executes its condition in the non-debug build. - // The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT. - #define SkAssertResult(cond) if (cond) {} do {} while(false) +#if !defined(GR_GPU_STATS) + #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || GR_TEST_UTILS + #define GR_GPU_STATS 1 + #else + #define GR_GPU_STATS 0 + #endif #endif //////////////////////////////////////////////////////////////////////////////// -/** Fast type for unsigned 8 bits. Use for parameter passing and local - variables, not for storage -*/ -typedef unsigned U8CPU; - -/** Fast type for unsigned 16 bits. Use for parameter passing and local - variables, not for storage -*/ -typedef unsigned U16CPU; - -/** @return false or true based on the condition -*/ -template static constexpr bool SkToBool(const T& x) { - return (bool)x; -} - -static constexpr int16_t SK_MaxS16 = INT16_MAX; -static constexpr int16_t SK_MinS16 = -SK_MaxS16; - -static constexpr int32_t SK_MaxS32 = INT32_MAX; -static constexpr int32_t SK_MinS32 = -SK_MaxS32; -static constexpr int32_t SK_NaN32 = INT32_MIN; - -static constexpr int64_t SK_MaxS64 = INT64_MAX; -static constexpr int64_t SK_MinS64 = -SK_MaxS64; - -static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { - return (int32_t) ((uint32_t) value << shift); -} - -static inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) { - return (int64_t) ((uint64_t) value << shift); -} - -//////////////////////////////////////////////////////////////////////////////// - -/** @return the number of entries in an array (not a pointer) -*/ -// The SkArrayCountHelper template returns a type 'char (&)[N]', a reference to an array of -// char with N elements, where N is deduced using function parameter type deduction. This is then -// used in the sizeof operator in SK_ARRAY_COUNT. The sizeof operator ignores the reference, and -// just evaluates the size of the array type. -// -// DEPRECATED: use std::size() instead. -// Note: Rarely, std::size(z) can't deduce the type of z during compile time for static_assert -// while SK_ARRAY_COUNT can. It can't be deduced because z is part of class, and the class' this -// pointer is not a valid constexpr expression. Use SkASSERT instead. -template char (&SkArrayCountHelper(T (&array)[N]))[N]; -#define SK_ARRAY_COUNT(array) (sizeof(SkArrayCountHelper(array))) - -//////////////////////////////////////////////////////////////////////////////// - -template static constexpr T SkAlign2(T x) { return (x + 1) >> 1 << 1; } -template static constexpr T SkAlign4(T x) { return (x + 3) >> 2 << 2; } -template static constexpr T SkAlign8(T x) { return (x + 7) >> 3 << 3; } - -template static constexpr bool SkIsAlign2(T x) { return 0 == (x & 1); } -template static constexpr bool SkIsAlign4(T x) { return 0 == (x & 3); } -template static constexpr bool SkIsAlign8(T x) { return 0 == (x & 7); } - -template static constexpr T SkAlignPtr(T x) { - return sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x); -} -template static constexpr bool SkIsAlignPtr(T x) { - return sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x); -} - -/** - * align up to a power of 2 - */ -static inline constexpr size_t SkAlignTo(size_t x, size_t alignment) { - // The same as alignment && SkIsPow2(value), w/o a dependency cycle. - SkASSERT(alignment && (alignment & (alignment - 1)) == 0); - return (x + alignment - 1) & ~(alignment - 1); -} - typedef uint32_t SkFourByteTag; static inline constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d) { return (((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | (uint32_t)d); @@ -591,36 +193,5 @@ static constexpr uint32_t SK_InvalidGenID = 0; */ static constexpr uint32_t SK_InvalidUniqueID = 0; -static inline int32_t SkAbs32(int32_t value) { - SkASSERT(value != SK_NaN32); // The most negative int32_t can't be negated. - if (value < 0) { - value = -value; - } - return value; -} - -template static inline T SkTAbs(T value) { - if (value < 0) { - value = -value; - } - return value; -} - -//////////////////////////////////////////////////////////////////////////////// - -/** Indicates whether an allocation should count against a cache budget. -*/ -enum class SkBudgeted : bool { - kNo = false, - kYes = true -}; - -/** Indicates whether a backing store needs to be an exact match or can be - larger than is strictly necessary -*/ -enum class SkBackingFit { - kApprox, - kExact -}; #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h index fc53e9d01aaf8..2c3f784a42674 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h @@ -12,6 +12,8 @@ #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include + class SkData; struct SkPoint; class SkVerticesPriv; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h index a3cf210f37099..bbbae5d383d94 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h @@ -10,9 +10,13 @@ #include "include/codec/SkEncodedOrigin.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkMatrix.h" #include "include/core/SkSize.h" +#include "include/core/SkTypes.h" #include +#include +#include #include /** diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h index de04ab14dc3c9..2ecb9005df1af 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h @@ -8,14 +8,20 @@ #ifndef SkYUVAPixmaps_DEFINED #define SkYUVAPixmaps_DEFINED +#include "include/core/SkColorType.h" #include "include/core/SkData.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSize.h" +#include "include/core/SkTypes.h" #include "include/core/SkYUVAInfo.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" #include #include +#include +#include class GrImageContext; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h index bf131848baa12..16e953be5e5ed 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h @@ -12,7 +12,7 @@ #include "include/core/SkScalar.h" #include "include/core/SkString.h" #include "include/core/SkTime.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #define SKPDF_STRING(X) SKPDF_STRING_IMPL(X) #define SKPDF_STRING_IMPL(X) #X @@ -143,6 +143,17 @@ struct Metadata { */ SkExecutor* fExecutor = nullptr; + /** PDF streams may be compressed to save space. + Use this to specify the desired compression vs time tradeoff. + */ + enum class CompressionLevel : int { + Default = -1, + None = 0, + LowButFast = 1, + Average = 6, + HighButSlow = 9, + } fCompressionLevel = CompressionLevel::Default; + /** Preferred Subsetter. Only respected if both are compiled in. The Sfntly subsetter is deprecated. diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h index ee470f96d38b2..5092278f0def3 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h @@ -8,12 +8,13 @@ #ifndef SkColorMatrix_DEFINED #define SkColorMatrix_DEFINED -#include "include/core/SkImageInfo.h" #include "include/core/SkTypes.h" #include #include +enum SkYUVColorSpace : int; + class SK_API SkColorMatrix { public: constexpr SkColorMatrix() : SkColorMatrix(1, 0, 0, 0, 0, diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h index df08c96f59322..43a67e242e11e 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h @@ -62,10 +62,43 @@ class SK_API SkGradientShader { struct Interpolation { enum class InPremul : bool { kNo = false, kYes = true }; - InPremul fInPremul = InPremul::kNo; + enum class ColorSpace : uint8_t { + // Default Skia behavior: interpolate in the color space of the destination surface + kDestination, + + // https://www.w3.org/TR/css-color-4/#interpolation-space + kSRGBLinear, + kLab, + kOKLab, + kLCH, + kOKLCH, + kSRGB, + kHSL, + kHWB, + + kLastColorSpace = kHWB, + }; + static constexpr int kColorSpaceCount = static_cast(ColorSpace::kLastColorSpace) + 1; + + enum class HueMethod : uint8_t { + // https://www.w3.org/TR/css-color-4/#hue-interpolation + kShorter, + kLonger, + kIncreasing, + kDecreasing, + + kLastHueMethod = kDecreasing, + }; + static constexpr int kHueMethodCount = static_cast(HueMethod::kLastHueMethod) + 1; + + InPremul fInPremul = InPremul::kNo; + ColorSpace fColorSpace = ColorSpace::kDestination; + HueMethod fHueMethod = HueMethod::kShorter; // Only relevant for LCH, OKLCH, HSL, or HWB static Interpolation FromFlags(uint32_t flags) { - return {flags & kInterpolateColorsInPremul_Flag ? InPremul::kYes : InPremul::kNo}; + return {flags & kInterpolateColorsInPremul_Flag ? InPremul::kYes : InPremul::kNo, + ColorSpace::kDestination, + HueMethod::kShorter}; } }; @@ -76,8 +109,11 @@ class SK_API SkGradientShader { @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the start and end point. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >=2. The number of colors (and pos if not NULL) entries. @param mode The tiling mode @@ -95,8 +131,11 @@ class SK_API SkGradientShader { @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the start and end point. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >=2. The number of colors (and pos if not NULL) entries. @param mode The tiling mode @@ -123,8 +162,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the center and edge of the circle. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode The tiling mode */ @@ -141,8 +183,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the center and edge of the circle. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode The tiling mode */ @@ -214,8 +259,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, then the colors are distributed evenly within the angular range. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode Tiling mode: controls drawing outside of the gradient angular range. @param startAngle Start of the angular range, corresponding to pos == 0. @@ -250,8 +298,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, then the colors are distributed evenly within the angular range. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode Tiling mode: controls drawing outside of the gradient angular range. @param startAngle Start of the angular range, corresponding to pos == 0. diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h index 5665c607015c7..75d2cb0bcc54f 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h @@ -310,17 +310,6 @@ class SK_API SkImageFilters { static sk_sp Offset(SkScalar dx, SkScalar dy, sk_sp input, const CropRect& cropRect = {}); - /** - * Create a filter that fills the output with the given paint. - * @param paint The paint to fill - * @param cropRect Optional rectangle that will be filled. If null, the source bitmap's bounds - * are filled even though the source bitmap itself is not used. - * - * DEPRECATED: Use Shader() instead, since many features of SkPaint are ignored when filling - * the target output, and paint color/alpha can be emulated with SkShaders::Color(). - */ - static sk_sp Paint(const SkPaint& paint, const CropRect& cropRect = {}); - /** * Create a filter that produces the SkPicture as its output, drawn into targetRect. Note that * the targetRect is not the same as the SkIRect cropRect that many filters accept. Returns diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h index a8e0f4d7dc837..4d3450ee25878 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h @@ -16,8 +16,10 @@ #include "include/core/SkShader.h" #include "include/core/SkSpan.h" #include "include/core/SkString.h" -#include "include/private/SkOnce.h" +#include "include/core/SkTypes.h" #include "include/private/SkSLSampleUsage.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkTemplates.h" #include #include @@ -34,6 +36,7 @@ class SkRuntimeImageFilter; namespace SkSL { class DebugTrace; +class DebugTracePriv; class ErrorReporter; class FunctionDefinition; struct Program; @@ -43,7 +46,11 @@ struct ProgramSettings; namespace skvm { class Program; -} // namespace skvm +} + +namespace SkSL::RP { +class Program; +} /* * SkRuntimeEffect supports creating custom SkShader and SkColorFilter objects using Skia's SkSL @@ -126,9 +133,9 @@ class SK_API SkRuntimeEffect : public SkRefCnt { friend class SkRuntimeEffect; friend class SkRuntimeEffectPriv; - // Public SkSL does not allow access to sk_FragCoord. The semantics of that variable are - // confusing, and expose clients to implementation details of saveLayer and image filters. - bool usePrivateRTShaderModule = false; + // This flag allows Runtime Effects to access Skia implementation details like sk_FragCoord + // and functions with private identifiers (e.g. $rgb_to_hsl). + bool allowPrivateAccess = false; // TODO(skia:11209) - Replace this with a promised SkCapabilities? // This flag lifts the ES2 restrictions on Runtime Effects that are gated by the @@ -276,6 +283,7 @@ class SK_API SkRuntimeEffect : public SkRefCnt { kSamplesOutsideMain_Flag = 0x10, kUsesColorTransform_Flag = 0x20, kAlwaysOpaque_Flag = 0x40, + kAlphaUnchanged_Flag = 0x80, }; SkRuntimeEffect(std::unique_ptr baseProgram, @@ -301,15 +309,17 @@ class SK_API SkRuntimeEffect : public SkRefCnt { bool samplesOutsideMain() const { return (fFlags & kSamplesOutsideMain_Flag); } bool usesColorTransform() const { return (fFlags & kUsesColorTransform_Flag); } bool alwaysOpaque() const { return (fFlags & kAlwaysOpaque_Flag); } + bool isAlphaUnchanged() const { return (fFlags & kAlphaUnchanged_Flag); } const SkFilterColorProgram* getFilterColorProgram() const; + const SkSL::RP::Program* getRPProgram(SkSL::DebugTracePriv* debugTrace) const; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) friend class GrSkSLFP; // fBaseProgram, fSampleUsages friend class GrGLSLSkSLFP; // #endif - friend class SkRTShader; // fBaseProgram, fMain + friend class SkRTShader; // fBaseProgram, fMain, fSampleUsages, getRPProgram() friend class SkRuntimeBlender; // friend class SkRuntimeColorFilter; // @@ -319,6 +329,8 @@ class SK_API SkRuntimeEffect : public SkRefCnt { uint32_t fHash; std::unique_ptr fBaseProgram; + std::unique_ptr fRPProgram; + mutable SkOnce fCompileRPProgramOnce; const SkSL::FunctionDefinition& fMain; std::vector fUniforms; std::vector fChildren; @@ -415,6 +427,11 @@ class SkRuntimeEffectBuilder { BuilderUniform uniform(std::string_view name) { return { this, fEffect->findUniform(name) }; } BuilderChild child(std::string_view name) { return { this, fEffect->findChild(name) }; } + // Get access to the collated uniforms and children (in the order expected by APIs like + // makeShader on the effect): + sk_sp uniforms() { return fUniforms; } + SkSpan children() { return fChildren; } + protected: SkRuntimeEffectBuilder() = delete; explicit SkRuntimeEffectBuilder(sk_sp effect) @@ -432,10 +449,6 @@ class SkRuntimeEffectBuilder { SkRuntimeEffectBuilder& operator=(SkRuntimeEffectBuilder&&) = delete; SkRuntimeEffectBuilder& operator=(const SkRuntimeEffectBuilder&) = delete; - sk_sp uniforms() { return fUniforms; } - SkRuntimeEffect::ChildPtr* children() { return fChildren.data(); } - size_t numChildren() { return fChildren.size(); } - private: void* writableUniformData() { if (!fUniforms->unique()) { @@ -492,6 +505,23 @@ class SK_API SkRuntimeShaderBuilder : public SkRuntimeEffectBuilder { friend class SkRuntimeImageFilter; }; +/** + * SkRuntimeColorFilterBuilder makes it easy to setup and assign uniforms to runtime color filters. + */ +class SK_API SkRuntimeColorFilterBuilder : public SkRuntimeEffectBuilder { +public: + explicit SkRuntimeColorFilterBuilder(sk_sp); + ~SkRuntimeColorFilterBuilder(); + + SkRuntimeColorFilterBuilder(const SkRuntimeColorFilterBuilder&) = delete; + SkRuntimeColorFilterBuilder& operator=(const SkRuntimeColorFilterBuilder&) = delete; + + sk_sp makeColorFilter(); + +private: + using INHERITED = SkRuntimeEffectBuilder; +}; + /** * SkRuntimeBlendBuilder is a utility to simplify creation and uniform setup of runtime blenders. */ diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h index 657b9a98a96c7..8f76e8016c848 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h @@ -9,8 +9,12 @@ #define SkEncoder_DEFINED #include "include/core/SkPixmap.h" -#include "include/private/SkNoncopyable.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkNoncopyable.h" +#include "include/private/base/SkTemplates.h" + +#include +#include class SK_API SkEncoder : SkNoncopyable { public: @@ -53,7 +57,7 @@ class SK_API SkEncoder : SkNoncopyable { const SkPixmap& fSrc; int fCurrRow; - SkAutoTMalloc fStorage; + skia_private::AutoTMalloc fStorage; }; #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h new file mode 100644 index 0000000000000..b14836b2ab6aa --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h @@ -0,0 +1,36 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkICC_DEFINED +#define SkICC_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" + +#include + +class SkData; +struct skcms_ICCProfile; +struct skcms_Matrix3x3; +struct skcms_TransferFunction; + +SK_API sk_sp SkWriteICCProfile(const skcms_TransferFunction&, + const skcms_Matrix3x3& toXYZD50); + +SK_API sk_sp SkWriteICCProfile(const skcms_ICCProfile*, const char* description); + +// Utility function for populating the grid_16 member of skcms_A2B and skcms_B2A +// structures. This converts a point in XYZD50 to its representation in grid_16_lab. +// It will write 6 bytes. The behavior of this function matches how skcms will decode +// values, but might not match the specification, see https://crbug.com/skia/13807. +SK_API void SkICCFloatXYZD50ToGrid16Lab(const float* float_xyz, uint8_t* grid16_lab); + +// Utility function for popluating the table_16 member of skcms_Curve structure. +// This converts a float to its representation in table_16. It will write 2 bytes. +SK_API void SkICCFloatToTable16(const float f, uint8_t* table_16); + +#endif//SkICC_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h index f2107f1263a38..f7e8effa7fa5b 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h @@ -8,90 +8,121 @@ #ifndef SkJpegEncoder_DEFINED #define SkJpegEncoder_DEFINED -#include "include/encode/SkEncoder.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" -class SkJpegEncoderMgr; +#include + +class SkColorSpace; +class SkData; +class SkEncoder; +class SkPixmap; class SkWStream; +class SkImage; +class GrDirectContext; +class SkYUVAPixmaps; +struct skcms_ICCProfile; + +namespace SkJpegEncoder { -class SK_API SkJpegEncoder : public SkEncoder { -public: - - enum class AlphaOption { - kIgnore, - kBlendOnBlack, - }; - - enum class Downsample { - /** - * Reduction by a factor of two in both the horizontal and vertical directions. - */ - k420, - - /** - * Reduction by a factor of two in the horizontal direction. - */ - k422, - - /** - * No downsampling. - */ - k444, - }; - - struct Options { - /** - * |fQuality| must be in [0, 100] where 0 corresponds to the lowest quality. - */ - int fQuality = 100; - - /** - * Choose the downsampling factor for the U and V components. This is only - * meaningful if the |src| is not kGray, since kGray will not be encoded as YUV. - * - * Our default value matches the libjpeg-turbo default. - */ - Downsample fDownsample = Downsample::k420; - - /** - * Jpegs must be opaque. This instructs the encoder on how to handle input - * images with alpha. - * - * The default is to ignore the alpha channel and treat the image as opaque. - * Another option is to blend the pixels onto a black background before encoding. - * In the second case, the encoder supports linear or legacy blending. - */ - AlphaOption fAlphaOption = AlphaOption::kIgnore; - }; +enum class AlphaOption { + kIgnore, + kBlendOnBlack, +}; +enum class Downsample { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * Reduction by a factor of two in both the horizontal and vertical directions. */ - static bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + k420, /** - * Create a jpeg encoder that will encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * |dst| is unowned but must remain valid for the lifetime of the object. - * - * This returns nullptr on an invalid or unsupported |src|. + * Reduction by a factor of two in the horizontal direction. */ - static std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, - const Options& options); + k422, - ~SkJpegEncoder() override; + /** + * No downsampling. + */ + k444, +}; + +struct Options { + /** + * |fQuality| must be in [0, 100] where 0 corresponds to the lowest quality. + */ + int fQuality = 100; + + /** + * Choose the downsampling factor for the U and V components. This is only + * meaningful if the |src| is not kGray, since kGray will not be encoded as YUV. + * This is ignored in favor of |src|'s subsampling when |src| is an SkYUVAPixmaps. + * + * Our default value matches the libjpeg-turbo default. + */ + Downsample fDownsample = Downsample::k420; -protected: - bool onEncodeRows(int numRows) override; + /** + * Jpegs must be opaque. This instructs the encoder on how to handle input + * images with alpha. + * + * The default is to ignore the alpha channel and treat the image as opaque. + * Another option is to blend the pixels onto a black background before encoding. + * In the second case, the encoder supports linear or legacy blending. + */ + AlphaOption fAlphaOption = AlphaOption::kIgnore; -private: - SkJpegEncoder(std::unique_ptr, const SkPixmap& src); + /** + * Optional XMP metadata. + */ + const SkData* xmpMetadata = nullptr; - std::unique_ptr fEncoderMgr; - using INHERITED = SkEncoder; + /** + * An optional ICC profile to override the default behavior. + * + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. + */ + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; }; +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); +SK_API bool Encode(SkWStream* dst, + const SkYUVAPixmaps& src, + const SkColorSpace* srcColorSpace, + const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Create a jpeg encoder that will encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * |dst| is unowned but must remain valid for the lifetime of the object. + * + * This returns nullptr on an invalid or unsupported |src|. + */ +SK_API std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, const Options& options); +SK_API std::unique_ptr Make(SkWStream* dst, + const SkYUVAPixmaps& src, + const SkColorSpace* srcColorSpace, + const Options& options); +} // namespace SkJpegEncoder + #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h index ccfa292f747d7..b26befa323ef3 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h @@ -9,91 +9,109 @@ #define SkPngEncoder_DEFINED #include "include/core/SkDataTable.h" -#include "include/encode/SkEncoder.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" -class SkPngEncoderMgr; +// TODO(kjlubick) update clients to directly include this +#include "include/encode/SkEncoder.h" // IWYU pragma: keep + +#include + +class GrDirectContext; +class SkData; +class SkImage; +class SkPixmap; class SkWStream; +struct skcms_ICCProfile; + +namespace SkPngEncoder { + +enum class FilterFlag : int { + kZero = 0x00, + kNone = 0x08, + kSub = 0x10, + kUp = 0x20, + kAvg = 0x40, + kPaeth = 0x80, + kAll = kNone | kSub | kUp | kAvg | kPaeth, +}; -class SK_API SkPngEncoder : public SkEncoder { -public: - - enum class FilterFlag : int { - kZero = 0x00, - kNone = 0x08, - kSub = 0x10, - kUp = 0x20, - kAvg = 0x40, - kPaeth = 0x80, - kAll = kNone | kSub | kUp | kAvg | kPaeth, - }; - - struct Options { - /** - * Selects which filtering strategies to use. - * - * If a single filter is chosen, libpng will use that filter for every row. - * - * If multiple filters are chosen, libpng will use a heuristic to guess which filter - * will encode smallest, then apply that filter. This happens on a per row basis, - * different rows can use different filters. - * - * Using a single filter (or less filters) is typically faster. Trying all of the - * filters may help minimize the output file size. - * - * Our default value matches libpng's default. - */ - FilterFlag fFilterFlags = FilterFlag::kAll; - - /** - * Must be in [0, 9] where 9 corresponds to maximal compression. This value is passed - * directly to zlib. 0 is a special case to skip zlib entirely, creating dramatically - * larger pngs. - * - * Our default value matches libpng's default. - */ - int fZLibLevel = 6; - - /** - * Represents comments in the tEXt ancillary chunk of the png. - * The 2i-th entry is the keyword for the i-th comment, - * and the (2i + 1)-th entry is the text for the i-th comment. - */ - sk_sp fComments; - }; +inline FilterFlag operator|(FilterFlag x, FilterFlag y) { return (FilterFlag)((int)x | (int)y); } +struct Options { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * Selects which filtering strategies to use. + * + * If a single filter is chosen, libpng will use that filter for every row. + * + * If multiple filters are chosen, libpng will use a heuristic to guess which filter + * will encode smallest, then apply that filter. This happens on a per row basis, + * different rows can use different filters. + * + * Using a single filter (or less filters) is typically faster. Trying all of the + * filters may help minimize the output file size. * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * Our default value matches libpng's default. */ - static bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + FilterFlag fFilterFlags = FilterFlag::kAll; /** - * Create a png encoder that will encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * Must be in [0, 9] where 9 corresponds to maximal compression. This value is passed + * directly to zlib. 0 is a special case to skip zlib entirely, creating dramatically + * larger pngs. * - * |dst| is unowned but must remain valid for the lifetime of the object. - * - * This returns nullptr on an invalid or unsupported |src|. + * Our default value matches libpng's default. */ - static std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, - const Options& options); - - ~SkPngEncoder() override; - -protected: - bool onEncodeRows(int numRows) override; + int fZLibLevel = 6; - SkPngEncoder(std::unique_ptr, const SkPixmap& src); + /** + * Represents comments in the tEXt ancillary chunk of the png. + * The 2i-th entry is the keyword for the i-th comment, + * and the (2i + 1)-th entry is the text for the i-th comment. + */ + sk_sp fComments; - std::unique_ptr fEncoderMgr; - using INHERITED = SkEncoder; + /** + * An optional ICC profile to override the default behavior. + * + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. + */ + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; }; -static inline SkPngEncoder::FilterFlag operator|(SkPngEncoder::FilterFlag x, - SkPngEncoder::FilterFlag y) { - return (SkPngEncoder::FilterFlag)((int)x | (int)y); -} +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Create a png encoder that will encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * The primary use of this is incremental encoding of the pixels. + * + * |dst| is unowned but must remain valid for the lifetime of the object. + * + * This returns nullptr on an invalid or unsupported |src|. + */ +SK_API std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, const Options& options); + +} // namespace SkPngEncoder #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h index 1930e4099f84a..fe11044e73804 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h @@ -8,58 +8,85 @@ #ifndef SkWebpEncoder_DEFINED #define SkWebpEncoder_DEFINED -#include "include/core/SkSpan.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSpan.h" // IWYU pragma: keep #include "include/encode/SkEncoder.h" +#include "include/private/base/SkAPI.h" +class SkPixmap; class SkWStream; +class SkData; +class GrDirectContext; +class SkImage; +struct skcms_ICCProfile; namespace SkWebpEncoder { - enum class Compression { - kLossy, - kLossless, - }; - - struct SK_API Options { - /** - * |fCompression| determines whether we will use webp lossy or lossless compression. - * - * |fQuality| must be in [0.0f, 100.0f]. - * If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the - * encoding. Decreasing the quality will result in a smaller encoded image. - * If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort - * put into the encoding. Lower values will compress faster into larger files, - * while larger values will compress slower into smaller files. - * - * This scheme is designed to match the libwebp API. - */ - Compression fCompression = Compression::kLossy; - float fQuality = 100.0f; - }; +enum class Compression { + kLossy, + kLossless, +}; +struct SK_API Options { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * |fCompression| determines whether we will use webp lossy or lossless compression. + * + * |fQuality| must be in [0.0f, 100.0f]. + * If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the + * encoding. Decreasing the quality will result in a smaller encoded image. + * If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort + * put into the encoding. Lower values will compress faster into larger files, + * while larger values will compress slower into smaller files. * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * This scheme is designed to match the libwebp API. */ - SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + Compression fCompression = Compression::kLossy; + float fQuality = 100.0f; /** - * Encode the |src| frames to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * The size of the first frame will be used as the canvas size. If any other frame does - * not match the canvas size, this is an error. - * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * An optional ICC profile to override the default behavior. * - * Note: libwebp API also supports set background color, loop limit and customize - * lossy/lossless for each frame. These could be added later as needed. + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. */ - SK_API bool EncodeAnimated(SkWStream* dst, - SkSpan src, - const Options& options); + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; +}; + +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Encode the |src| frames to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * The size of the first frame will be used as the canvas size. If any other frame does + * not match the canvas size, this is an error. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + * + * Note: libwebp API also supports set background color, loop limit and customize + * lossy/lossless for each frame. These could be added later as needed. + */ +SK_API bool EncodeAnimated(SkWStream* dst, + SkSpan src, + const Options& options); } // namespace SkWebpEncoder #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h index 2eb88a8d433ce..e2e3961f8b9e5 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h @@ -26,16 +26,29 @@ enum class BackendApi : unsigned { kMock, }; +/** Indicates whether an allocation should count against a cache budget. */ +enum class Budgeted : bool { + kNo = false, + kYes = true, +}; + /** * Value passed into various callbacks to tell the client the result of operations connected to a * specific callback. The actual interpretation of kFailed and kSuccess are dependent on the * specific callbacks and are documented with the callback itself. */ enum class CallbackResult : bool { - kFailed = true, + kFailed = false, kSuccess = true, }; +/** + * Is the texture mipmapped or not + */ +enum class Mipmapped : bool { + kNo = false, + kYes = true, +}; /** * Is the data protected on the GPU or not. @@ -45,6 +58,15 @@ enum class Protected : bool { kYes = true, }; +/** + * Is a texture renderable or not + */ +enum class Renderable : bool { + kNo = false, + kYes = true, +}; + } // namespace skgpu + #endif // skgpu_GpuTypes_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h index 759cc1d39837a..37ab666d52ec4 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h @@ -35,6 +35,7 @@ class GrVkImageLayout; class GrGLTextureParameters; class GrColorFormatDesc; +enum class SkTextureCompressionType; namespace skgpu { class MutableTextureStateRef; @@ -57,7 +58,7 @@ class GrD3DResourceState; class SkString; #endif -#if !SK_SUPPORT_GPU +#if !defined(SK_GANESH) // SkSurfaceCharacterization always needs a minimal version of this class SK_API GrBackendFormat { @@ -124,7 +125,8 @@ class SK_API GrBackendFormat { } #endif - static GrBackendFormat MakeMock(GrColorType colorType, SkImage::CompressionType compression, + static GrBackendFormat MakeMock(GrColorType colorType, + SkTextureCompressionType compression, bool isStencilFormat = false); bool operator==(const GrBackendFormat& that) const; @@ -191,7 +193,7 @@ class SK_API GrBackendFormat { * kUnknown, the compression type is not kNone, or this is a mock stencil format. */ GrColorType asMockColorType() const; - SkImage::CompressionType asMockCompressionType() const; + SkTextureCompressionType asMockCompressionType() const; bool isMockStencilFormat() const; // If possible, copies the GrBackendFormat and forces the texture type to be Texture2D. If the @@ -228,7 +230,7 @@ class SK_API GrBackendFormat { GrBackendFormat(DXGI_FORMAT dxgiFormat); #endif - GrBackendFormat(GrColorType, SkImage::CompressionType, bool isStencilFormat); + GrBackendFormat(GrColorType, SkTextureCompressionType, bool isStencilFormat); #ifdef SK_DEBUG bool validateMock() const; @@ -259,9 +261,9 @@ class SK_API GrBackendFormat { DXGI_FORMAT fDxgiFormat; #endif struct { - GrColorType fColorType; - SkImage::CompressionType fCompressionType; - bool fIsStencilFormat; + GrColorType fColorType; + SkTextureCompressionType fCompressionType; + bool fIsStencilFormat; } fMock; }; GrTextureType fTextureType = GrTextureType::kNone; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h deleted file mode 100644 index 9fe6629dd7ead..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h +++ /dev/null @@ -1,53 +0,0 @@ - -/* - * Copyright 2010 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrConfig_DEFINED -#define GrConfig_DEFINED - -#include "include/core/SkTypes.h" - -/** - * Gr defines are set to 0 or 1, rather than being undefined or defined - */ - -#if !defined(GR_CACHE_STATS) - #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) - #define GR_CACHE_STATS 1 - #else - #define GR_CACHE_STATS 0 - #endif -#endif - -#if !defined(GR_GPU_STATS) - #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || GR_TEST_UTILS - #define GR_GPU_STATS 1 - #else - #define GR_GPU_STATS 0 - #endif -#endif - -#endif - -/** - * GR_STRING makes a string of X where X is expanded before conversion to a string - * if X itself contains macros. - */ -#define GR_STRING(X) GR_STRING_IMPL(X) -#define GR_STRING_IMPL(X) #X - -/** - * GR_CONCAT concatenates X and Y where each is expanded before - * contanenation if either contains macros. - */ -#define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y) -#define GR_CONCAT_IMPL(X,Y) X##Y - -/** - * Creates a string of the form "() : " - */ -#define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : " diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h index 28675297a1331..bf4ca409a8f6d 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h @@ -20,7 +20,7 @@ class SkExecutor; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) struct SK_API GrContextOptions { enum class Enable { /** Forces an option to be disabled. */ @@ -80,8 +80,9 @@ struct SK_API GrContextOptions { /** * Controls whether we check for GL errors after functions that allocate resources (e.g. - * glTexImage2D), for shader compilation success, and program link success. Ignored on - * backends other than GL. + * glTexImage2D), at the end of a GPU submission, or checking framebuffer completeness. The + * results of shader compilation and program linking are always checked, regardless of this + * option. Ignored on backends other than GL. */ Enable fSkipGLErrorChecks = Enable::kDefault; @@ -244,6 +245,12 @@ struct SK_API GrContextOptions { */ bool fSuppressMipmapSupport = false; + /** + * If true, the TessellationPathRenderer will not be used for path rendering. + * If false, will fallback to any driver workarounds, if set. + */ + bool fDisableTessellationPathRenderer = false; + /** * If true, and if supported, enables hardware tessellation in the caps. * DEPRECATED: This value is ignored; experimental hardware tessellation is always disabled. @@ -254,13 +261,7 @@ struct SK_API GrContextOptions { * If true, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp * rendering of all glyphs. This must be set to true to use Slugs. */ - #if defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_STRIKE_SERIALIZE) - bool fSupportBilerpFromGlyphAtlas = true; - #else bool fSupportBilerpFromGlyphAtlas = false; - #endif /** * Uses a reduced variety of shaders. May perform less optimally in steady state but can reduce @@ -273,6 +274,24 @@ struct SK_API GrContextOptions { */ bool fAllowMSAAOnNewIntel = false; + /** + * Currently on ARM Android we disable the use of GL TexStorage because of memory regressions. + * However, some clients may still want to use TexStorage. For example, TexStorage support is + * required for creating protected textures. + * + * This flag has no impact on non GL backends. + */ + bool fAlwaysUseTexStorageWhenAvailable = false; + + /** + * Optional callback that can be passed into the GrDirectContext which will be called when the + * GrDirectContext is about to be destroyed. When this call is made, it will be safe for the + * client to delete the GPU backend context that is backing the GrDirectContext. The + * GrDirectContextDestroyedContext will be passed back to the client in the callback. + */ + GrDirectContextDestroyedContext fContextDeleteContext = nullptr; + GrDirectContextDestroyedProc fContextDeleteProc = nullptr; + #if GR_TEST_UTILS /** * Private options that are only meant for testing within Skia's tools. diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h index 7e1ee65ffcdd5..eb755553647b9 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h @@ -10,9 +10,10 @@ #include "include/core/SkRefCnt.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/core/SkImageInfo.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/GrContextOptions.h" #include "include/gpu/GrTypes.h" @@ -25,6 +26,7 @@ class GrThreadSafeCache; class GrThreadSafePipelineBuilder; class SkSurfaceCharacterization; class SkSurfaceProps; +enum class SkTextureCompressionType; namespace sktext::gpu { class TextBlobRedrawCoordinator; } @@ -107,13 +109,13 @@ class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt fAbandoned{false}; }; -#else // !SK_SUPPORT_GPU +#else // !defined(SK_GANESH) class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt {}; #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h index 903623fb7161d..a22fc4fe5784c 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h @@ -8,46 +8,52 @@ #ifndef GrDirectContext_DEFINED #define GrDirectContext_DEFINED +#include "include/core/SkColor.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" +#include "include/gpu/GpuTypes.h" +#include "include/gpu/GrContextOptions.h" #include "include/gpu/GrRecordingContext.h" +#include "include/gpu/GrTypes.h" -#include "include/gpu/GrBackendSurface.h" - -// We shouldn't need this but currently Android is relying on this being include transitively. -#include "include/core/SkUnPreMultiply.h" +#include +#include +#include +#include +#include class GrAtlasManager; class GrBackendSemaphore; +class GrBackendFormat; +class GrBackendTexture; +class GrBackendRenderTarget; class GrClientMappedBufferManager; -class GrDirectContextPriv; class GrContextThreadSafeProxy; -struct GrD3DBackendContext; -class GrFragmentProcessor; +class GrDirectContextPriv; class GrGpu; -struct GrGLInterface; -struct GrMtlBackendContext; -struct GrMockOptions; -class GrPath; class GrResourceCache; class GrResourceProvider; -class GrSurfaceProxy; -class GrTextureProxy; -struct GrVkBackendContext; - +class SkData; class SkImage; -class SkString; -class SkSurfaceCharacterization; -class SkSurfaceProps; +class SkPixmap; class SkTaskGroup; class SkTraceMemoryDump; +enum SkColorType : int; +enum class SkTextureCompressionType; +struct GrGLInterface; +struct GrMockOptions; +struct GrVkBackendContext; // IWYU pragma: keep +struct GrD3DBackendContext; // IWYU pragma: keep +struct GrMtlBackendContext; // IWYU pragma: keep namespace skgpu { -class Swizzle; -namespace v1 { class SmallPathAtlasMgr; } -} - -namespace sktext::gpu { -class StrikeCache; + class MutableTextureState; +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + namespace ganesh { class SmallPathAtlasMgr; } +#endif } +namespace sktext { namespace gpu { class StrikeCache; } } +namespace wgpu { class Device; } // IWYU pragma: keep class SK_API GrDirectContext : public GrRecordingContext { public: @@ -387,7 +393,24 @@ class SK_API GrDirectContext : public GrRecordingContext { */ GrSemaphoresSubmitted flush(const GrFlushInfo& info); - void flush() { this->flush({}); } + void flush() { this->flush(GrFlushInfo()); } + + /** Flushes any pending uses of texture-backed images in the GPU backend. If the image is not + * texture-backed (including promise texture images) or if the GrDirectContext does not + * have the same context ID as the context backing the image then this is a no-op. + * If the image was not used in any non-culled draws in the current queue of work for the + * passed GrDirectContext then this is a no-op unless the GrFlushInfo contains semaphores or + * a finish proc. Those are respected even when the image has not been used. + * @param image the non-null image to flush. + * @param info flush options + */ + GrSemaphoresSubmitted flush(sk_sp image, const GrFlushInfo& info); + void flush(sk_sp image); + + /** Version of flush() that uses a default GrFlushInfo. Also submits the flushed work to the + GPU. + */ + void flushAndSubmit(sk_sp image); /** * Submit outstanding work to the gpu from all previously un-submitted flushes. The return @@ -548,10 +571,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(&srcData, 1, textureOrigin, renderable, isProtected, - finishedProc, finishedContext, label); - } + std::string_view label = {}); // Deprecated versions that do not take origin and assume top-left. GrBackendTexture createBackendTexture(const SkPixmap srcData[], @@ -560,30 +580,14 @@ class SK_API GrDirectContext : public GrRecordingContext { GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(srcData, - numLevels, - kTopLeft_GrSurfaceOrigin, - renderable, - isProtected, - finishedProc, - finishedContext, - label); - } + std::string_view label = {}); + GrBackendTexture createBackendTexture(const SkPixmap& srcData, GrRenderable renderable, GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(&srcData, - 1, - renderable, - isProtected, - finishedProc, - finishedContext, - label); - } + std::string_view label = {}); /** * If possible, updates a backend texture to be filled to a particular color. The client should @@ -662,17 +666,10 @@ class SK_API GrDirectContext : public GrRecordingContext { const SkPixmap srcData[], int numLevels, GrGpuFinishedProc finishedProc, - GrGpuFinishedContext finishedContext) { - return this->updateBackendTexture(texture, - srcData, - numLevels, - kTopLeft_GrSurfaceOrigin, - finishedProc, - finishedContext); - } + GrGpuFinishedContext finishedContext); /** - * Retrieve the GrBackendFormat for a given SkImage::CompressionType. This is + * Retrieve the GrBackendFormat for a given SkTextureCompressionType. This is * guaranteed to match the backend format used by the following * createCompressedBackendTexture methods that take a CompressionType. * @@ -698,7 +695,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrGpuFinishedContext finishedContext = nullptr); GrBackendTexture createCompressedBackendTexture(int width, int height, - SkImage::CompressionType, + SkTextureCompressionType, const SkColor4f& color, GrMipmapped, GrProtected = GrProtected::kNo, @@ -726,7 +723,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrGpuFinishedContext finishedContext = nullptr); GrBackendTexture createCompressedBackendTexture(int width, int height, - SkImage::CompressionType, + SkTextureCompressionType, const void* data, size_t dataSize, GrMipmapped, GrProtected = GrProtected::kNo, @@ -850,7 +847,9 @@ class SK_API GrDirectContext : public GrRecordingContext { bool init() override; GrAtlasManager* onGetAtlasManager() { return fAtlasManager.get(); } - skgpu::v1::SmallPathAtlasMgr* onGetSmallPathAtlasMgr(); +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + skgpu::ganesh::SmallPathAtlasMgr* onGetSmallPathAtlasMgr(); +#endif GrDirectContext* asDirectContext() override { return this; } @@ -868,6 +867,28 @@ class SK_API GrDirectContext : public GrRecordingContext { // bool is used for this signal. void syncAllOutstandingGpuWork(bool shouldExecuteWhileAbandoned); + // This delete callback needs to be the first thing on the GrDirectContext so that it is the + // last thing destroyed. The callback may signal the client to clean up things that may need + // to survive the lifetime of some of the other objects on the GrDirectCotnext. So make sure + // we don't call it until all else has been destroyed. + class DeleteCallbackHelper { + public: + DeleteCallbackHelper(GrDirectContextDestroyedContext context, + GrDirectContextDestroyedProc proc) + : fContext(context), fProc(proc) {} + + ~DeleteCallbackHelper() { + if (fProc) { + fProc(fContext); + } + } + + private: + GrDirectContextDestroyedContext fContext; + GrDirectContextDestroyedProc fProc; + }; + std::unique_ptr fDeleteCallbackHelper; + const DirectContextID fDirectContextID; // fTaskGroup must appear before anything that uses it (e.g. fGpu), so that it is destroyed // after all of its users. Clients of fTaskGroup will generally want to ensure that they call @@ -894,11 +915,11 @@ class SK_API GrDirectContext : public GrRecordingContext { std::unique_ptr fMappedBufferManager; std::unique_ptr fAtlasManager; - std::unique_ptr fSmallPathAtlasMgr; +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + std::unique_ptr fSmallPathAtlasMgr; +#endif friend class GrDirectContextPriv; - - using INHERITED = GrRecordingContext; }; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h index c57efc6016586..1aa995c79177a 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h @@ -13,7 +13,8 @@ #ifdef SK_GPU_WORKAROUNDS_HEADER #include SK_GPU_WORKAROUNDS_HEADER #else -// To regenerate this file, set gn arg "skia_generate_workarounds = true". +// To regenerate this file, set gn arg "skia_generate_workarounds = true" +// or invoke `bazel run //tools:generate_workarounds` // This is not rebuilt by default to avoid embedders having to have extra // build steps. #include "include/gpu/GrDriverBugWorkaroundsAutogen.h" diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h index f8b9c3f39230a..85cc77c051c8f 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h @@ -9,7 +9,8 @@ #define GrRecordingContext_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkTArray.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkTArray.h" #include "include/private/gpu/ganesh/GrImageContext.h" #if GR_GPU_STATS && GR_TEST_UTILS @@ -190,7 +191,7 @@ class GrRecordingContext : public GrImageContext { // of the programInfos matches the intended use. For example, in DDL-record mode it // is known that all the programInfos will have been allocated in an arena with the // same lifetime at the DDL itself. - virtual void detachProgramData(SkTArray*) {} + virtual void detachProgramData(skia_private::TArray*) {} sktext::gpu::TextBlobRedrawCoordinator* getTextBlobRedrawCoordinator(); const sktext::gpu::TextBlobRedrawCoordinator* getTextBlobRedrawCoordinator() const; @@ -223,7 +224,8 @@ class GrRecordingContext : public GrImageContext { #if GR_TEST_UTILS void dump(SkString* out) const; - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const; + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const; #endif private: @@ -236,14 +238,16 @@ class GrRecordingContext : public GrImageContext { #if GR_TEST_UTILS void dump(SkString*) const {} - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const {} + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const {} #endif #endif // GR_GPU_STATS } fStats; #if GR_GPU_STATS && GR_TEST_UTILS struct DMSAAStats { - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const; + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const; void dump() const; void merge(const DMSAAStats&); int fNumRenderPasses = 0; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h index f8895345d658a..177a35a9437f9 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h @@ -8,13 +8,18 @@ #ifndef GrTypes_DEFINED #define GrTypes_DEFINED -#include "include/core/SkMath.h" #include "include/core/SkTypes.h" -#include "include/gpu/GrConfig.h" +#include "include/private/base/SkTo.h" // IWYU pragma: keep +#include +#include class GrBackendSemaphore; -class SkImage; -class SkSurface; + +namespace skgpu { +enum class Mipmapped : bool; +enum class Protected : bool; +enum class Renderable : bool; +} //////////////////////////////////////////////////////////////////////////////// @@ -122,28 +127,20 @@ static constexpr GrBackendApi kMock_GrBackend = GrBackendApi::kMock; /** * Used to say whether a texture has mip levels allocated or not. */ -enum class GrMipmapped : bool { - kNo = false, - kYes = true -}; -/** Deprecated legacy alias of GrMipmapped. */ -using GrMipMapped = GrMipmapped; +/** Deprecated legacy alias of skgpu::Mipmapped. */ +using GrMipmapped = skgpu::Mipmapped; +/** Deprecated legacy alias of skgpu::Mipmapped. */ +using GrMipMapped = skgpu::Mipmapped; /* * Can a GrBackendObject be rendered to? */ -enum class GrRenderable : bool { - kNo = false, - kYes = true -}; +using GrRenderable = skgpu::Renderable; /* * Used to say whether texture is backed by protected memory. */ -enum class GrProtected : bool { - kNo = false, - kYes = true -}; +using GrProtected = skgpu::Protected; /////////////////////////////////////////////////////////////////////////////// @@ -188,6 +185,9 @@ typedef void (*GrGpuFinishedProc)(GrGpuFinishedContext finishedContext); typedef void* GrGpuSubmittedContext; typedef void (*GrGpuSubmittedProc)(GrGpuSubmittedContext submittedContext, bool success); +typedef void* GrDirectContextDestroyedContext; +typedef void (*GrDirectContextDestroyedProc)(GrDirectContextDestroyedContext destroyedContext); + /** * Struct to supply options to flush calls. * diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h index d2e890f780a1f..b595422e8692a 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h @@ -22,7 +22,7 @@ // prepared to rename those identifiers. #include "include/core/SkRefCnt.h" -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include #include @@ -184,7 +184,7 @@ struct GrD3DTextureResourceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; unsigned int fSampleQualityPattern = DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrD3DTextureResourceInfo() = default; @@ -195,7 +195,7 @@ struct GrD3DTextureResourceInfo { uint32_t sampleCount, uint32_t levelCount, unsigned int sampleQualityLevel, - GrProtected isProtected = GrProtected::kNo) + skgpu::Protected isProtected = skgpu::Protected::kNo) : fResource(resource) , fAlloc(alloc) , fResourceState(resourceState) @@ -239,7 +239,7 @@ struct GrD3DFenceInfo { struct GrD3DSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; DXGI_FORMAT fFormat = DXGI_FORMAT_UNKNOWN; unsigned int fSampleQualityPattern = DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h index 70a2f9f6d6c5d..fbd3dbaf55cb1 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h @@ -8,7 +8,7 @@ #ifndef GrDawnTypes_DEFINED #define GrDawnTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #ifdef Always #undef Always @@ -22,7 +22,7 @@ static constexpr int Success = 0; #undef None static constexpr int None = 0L; #endif -#include "webgpu/webgpu_cpp.h" +#include "webgpu/webgpu_cpp.h" // IWYU pragma: export struct GrDawnTextureInfo { wgpu::Texture fTexture; @@ -87,7 +87,7 @@ struct GrDawnRenderTargetInfo { struct GrDawnSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; wgpu::TextureFormat fFormat; }; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h new file mode 100644 index 0000000000000..68f13ce4b5119 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h @@ -0,0 +1,77 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrTextureGenerator_DEFINED +#define GrTextureGenerator_DEFINED + +#include "include/core/SkImageGenerator.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GrTypes.h" +#include "include/private/base/SkAPI.h" + +#include +#include + +class GrRecordingContext; +class GrSurfaceProxyView; +class SkImage; +enum class GrImageTexGenPolicy : int; +namespace skgpu { enum class Mipmapped : bool; } +struct SkImageInfo; + +class SK_API GrTextureGenerator : public SkImageGenerator { +public: + bool isTextureGenerator() const final { return true; } + + /** + * If the generator can natively/efficiently return its pixels as a GPU image (backed by a + * texture) this will return that image. If not, this will return NULL. + * + * Regarding the GrRecordingContext parameter: + * + * It must be non-NULL. The generator should only succeed if: + * - its internal context is the same + * - it can somehow convert its texture into one that is valid for the provided context. + * + * If the mipmapped parameter is kYes, the generator should try to create a TextureProxy that + * at least has the mip levels allocated and the base layer filled in. If this is not possible, + * the generator is allowed to return a non mipped proxy, but this will have some additional + * overhead in later allocating mips and copying of the base layer. + * + * GrImageTexGenPolicy determines whether or not a new texture must be created (and its budget + * status) or whether this may (but is not required to) return a pre-existing texture that is + * retained by the generator (kDraw). + */ + GrSurfaceProxyView generateTexture(GrRecordingContext*, + const SkImageInfo& info, + skgpu::Mipmapped mipmapped, + GrImageTexGenPolicy); + + virtual GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&, + skgpu::Mipmapped, GrImageTexGenPolicy) = 0; + + // Most internal SkImageGenerators produce textures and views that use kTopLeft_GrSurfaceOrigin. + // If the generator may produce textures with different origins (e.g. + // GrAHardwareBufferImageGenerator) it should override this function to return the correct + // origin. Implementations should be thread-safe. + virtual GrSurfaceOrigin origin() const { return kTopLeft_GrSurfaceOrigin; } + +protected: + GrTextureGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID); +}; + +namespace SkImages { +/** + * Like SkImages::DeferredFromGenerator except allows for the use of SkGaneshTextureGenerator. + * + * @param gen producer of textures + * @return created SkImage, or nullptr + */ +SK_API sk_sp DeferredFromTextureGenerator(std::unique_ptr gen); +} + +#endif // GrTextureGenerator_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h new file mode 100644 index 0000000000000..296d90d17e3f9 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h @@ -0,0 +1,385 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkImageGanesh_DEFINED +#define SkImageGanesh_DEFINED + +#include "include/core/SkImage.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GpuTypes.h" +#include "include/gpu/GrTypes.h" +#include "include/private/base/SkAPI.h" + +#include +#include + +class GrBackendFormat; +class GrBackendTexture; +class GrContextThreadSafeProxy; +class GrDirectContext; +class GrRecordingContext; +class GrYUVABackendTextureInfo; +class GrYUVABackendTextures; +class SkColorSpace; +class SkData; +class SkPixmap; +class SkPromiseImageTexture; +class SkYUVAPixmaps; +enum SkAlphaType : int; +enum SkColorType : int; +enum class SkTextureCompressionType; +struct SkISize; + +/** + * All factories in this file refer to the Ganesh GPU backend when they say GPU. + */ + +namespace SkImages { +/** Defines a callback function, taking one parameter of type GrBackendTexture with + no return value. Function is called when backend texture is to be released. +*/ +using BackendTextureReleaseProc = std::function; +/** User function called when supplied texture may be deleted. */ +using TextureReleaseProc = void (*)(ReleaseContext); + +/** Creates GPU-backed SkImage from backendTexture associated with context. + Skia will assume ownership of the resource and will release it when no longer needed. + A non-null SkImage is returned if format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @param context GPU context + @param backendTexture texture residing on GPU + @param textureOrigin origin of backendTexture + @param colorType color type of the resulting image + @param alphaType alpha type of the resulting image + @param colorSpace range of colors; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType); +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType, + SkAlphaType alphaType); +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace); + +/** Creates GPU-backed SkImage from the provided GPU texture associated with context. + GPU texture must stay valid and unchanged until textureReleaseProc is called by Skia. + Skia will call textureReleaseProc with the passed-in releaseContext when SkImage + is deleted or no longer refers to the texture. + A non-null SkImage is returned if format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @note When using a DDL recording context, textureReleaseProc will be called on the + GPU thread after the DDL is played back on the direct context. + @param context GPU context + @param backendTexture texture residing on GPU + @param colorSpace This describes the color space of this image's contents, as + seen after sampling. In general, if the format of the backend + texture is SRGB, some linear colorSpace should be supplied + (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the + backend texture is linear, then the colorSpace should include + a description of the transfer function as + well (e.g., SkColorSpace::MakeSRGB()). + @param textureReleaseProc function called when texture can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp BorrowTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); + +/** Creates a GPU-backed SkImage from pixmap. It is uploaded to GPU backend using context. + Created SkImage is available to other GPU contexts, and is available across thread + boundaries. All contexts must be in the same GPU share group, or otherwise + share resources. + When SkImage is no longer referenced, context releases texture memory + asynchronously. + SkColorSpace of SkImage is determined by pixmap.colorSpace(). + SkImage is returned referring to GPU backend if context is not nullptr, + format of data is recognized and supported, and if context supports moving + resources between contexts. Otherwise, pixmap pixel data is copied and SkImage + as returned in raster format if possible; nullptr may be returned. + Recognized GPU formats vary by platform and GPU backend. + @param context GPU context + @param pixmap SkImageInfo, pixel address, and row bytes + @param buildMips create SkImage as mip map if true + @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary + @return created SkImage, or nullptr +*/ +SK_API sk_sp CrossContextTextureFromPixmap(GrDirectContext* context, + const SkPixmap& pixmap, + bool buildMips, + bool limitToMaxTextureSize = false); + +/** Creates a GPU-backed SkImage from a GPU backend texture. The backend texture must stay + valid and unchanged until textureReleaseProc is called. The textureReleaseProc is + called when the SkImage is deleted or no longer refers to the texture and will be + passed the releaseContext. + An SkImage is returned if the format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @note When using a DDL recording context, textureReleaseProc will be called on the + GPU thread after the DDL is played back on the direct context. + @param context the GPU context + @param backendTexture a texture already allocated by the GPU + @param alphaType This characterizes the nature of the alpha values in the + backend texture. For opaque compressed formats (e.g., ETC1) + this should usually be set to kOpaq + ue_SkAlphaType. + @param colorSpace This describes the color space of this image's contents, as + seen after sampling. In general, if the format of the backend + texture is SRGB, some linear colorSpace should be supplied + (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the + backend texture is linear, then the colorSpace should include + a description of the transfer function as + well (e.g., SkColorSpace::MakeSRGB()). + @param textureReleaseProc function called when the backend texture can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromCompressedTexture(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, + SkAlphaType alphaType, + sk_sp colorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); + +/** Creates a GPU-backed SkImage from compressed data. + This method will return an SkImage representing the compressed data. + If the GPU doesn't support the specified compression method, the data + will be decompressed and then wrapped in a GPU-backed image. + Note: one can query the supported compression formats via + GrRecordingContext::compressedBackendFormat. + @param context GPU context + @param data compressed data to store in SkImage + @param width width of full SkImage + @param height height of full SkImage + @param type type of compression used + @param mipmapped does 'data' contain data for all the mipmap levels? + @param isProtected do the contents of 'data' require DRM protection (on Vulkan)? + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromCompressedTextureData(GrDirectContext* direct, + sk_sp data, + int width, + int height, + SkTextureCompressionType type, + GrMipmapped mipmapped = GrMipmapped::kNo, + GrProtected isProtected = GrProtected::kNo); + +/** Returns SkImage backed by GPU texture associated with context. Returned SkImage is + compatible with SkSurface created with dstColorSpace. The returned SkImage respects + mipmapped setting; if mipmapped equals skgpu::Mipmapped::kYes, the backing texture + allocates mip map levels. + The mipmapped parameter is effectively treated as kNo if MIP maps are not supported by the + GPU. + Returns original SkImage if the image is already texture-backed, the context matches, and + mipmapped is compatible with the backing GPU texture. skgpu::Budgeted is ignored in this + case. + Returns nullptr if context is nullptr, or if SkImage was created with another + GrDirectContext. + @param GrDirectContext the GrDirectContext in play, if it exists + @param SkImage a non-null pointer to an SkImage. + @param skgpu::Mipmapped Whether created SkImage texture must allocate mip map levels. + Defaults to no. + @param skgpu::Budgeted Whether to count a newly created texture for the returned image + counts against the context's budget. Defaults to yes. + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromImage(GrDirectContext*, + const SkImage*, + skgpu::Mipmapped = skgpu::Mipmapped::kNo, + skgpu::Budgeted = skgpu::Budgeted::kYes); +inline sk_sp TextureFromImage(GrDirectContext* ctx, + sk_sp img, + skgpu::Mipmapped m = skgpu::Mipmapped::kNo, + skgpu::Budgeted b = skgpu::Budgeted::kYes) { + return TextureFromImage(ctx, img.get(), m, b); +} + +/** Creates a GPU-backed SkImage from SkYUVAPixmaps. + The image will remain planar with each plane converted to a texture using the passed + GrRecordingContext. + SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. + The SkColorSpace of the resulting RGB values is specified by imageColorSpace. This will + be the SkColorSpace reported by the image and when drawn the RGB values will be converted + from this space into the destination space (if the destination is tagged). + Currently, this is only supported using the GPU backend and will fail if context is nullptr. + SkYUVAPixmaps does not need to remain valid after this returns. + @param context GPU context + @param pixmaps The planes as pixmaps with supported SkYUVAInfo that + specifies conversion to RGB. + @param buildMips create internal YUVA textures as mip map if kYes. This is + silently ignored if the context does not support mip maps. + @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary + @param imageColorSpace range of colors of the resulting image; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromYUVAPixmaps(GrRecordingContext* context, + const SkYUVAPixmaps& pixmaps, + GrMipmapped buildMips, + bool limitToMaxTextureSize, + sk_sp imageColorSpace); +SK_API sk_sp TextureFromYUVAPixmaps(GrRecordingContext* context, + const SkYUVAPixmaps& pixmaps, + GrMipmapped buildMips = GrMipmapped::kNo, + bool limitToMaxTextureSize = false); + +/** Creates a GPU-backed SkImage from YUV[A] planar textures. This requires that the textures + * stay valid for the lifetime of the image. The ReleaseContext can be used to know when it is + * safe to either delete or overwrite the textures. If ReleaseProc is provided it is also called + * before return on failure. + @param context GPU context + @param yuvaTextures A set of textures containing YUVA data and a description of the + data and transformation to RGBA. + @param imageColorSpace range of colors of the resulting image after conversion to RGB; + may be nullptr + @param textureReleaseProc called when the backend textures can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromYUVATextures(GrRecordingContext* context, + const GrYUVABackendTextures& yuvaTextures, + sk_sp imageColorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); +SK_API sk_sp TextureFromYUVATextures(GrRecordingContext* context, + const GrYUVABackendTextures& yuvaTextures); + +using PromiseImageTextureContext = void*; +using PromiseImageTextureFulfillProc = sk_sp (*)(PromiseImageTextureContext); +using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); + +/** Create a new GPU-backed SkImage that is very similar to an SkImage created by BorrowTextureFrom. + The difference is that the caller need not have created the texture nor populated it with the + image pixel data. Moreover, the SkImage may be created on a thread as the creation of the + image does not require access to the backend API or GrDirectContext. Instead of passing a + GrBackendTexture the client supplies a description of the texture consisting of + GrBackendFormat, width, height, and GrMipmapped state. The resulting SkImage can be drawn + to a SkDeferredDisplayListRecorder or directly to a GPU-backed SkSurface. + When the actual texture is required to perform a backend API draw, textureFulfillProc will + be called to receive a GrBackendTexture. The properties of the GrBackendTexture must match + those set during the SkImage creation, and it must refer to a valid existing texture in the + backend API context/device, and be populated with the image pixel data. The texture cannot + be deleted until textureReleaseProc is called. + There is at most one call to each of textureFulfillProc and textureReleaseProc. + textureReleaseProc is always called even if image creation fails or if the + image is never fulfilled (e.g. it is never drawn or all draws are clipped out) + @param gpuContextProxy the thread-safe proxy of the gpu context. required. + @param backendFormat format of promised gpu texture + @param dimensions width & height of promised gpu texture + @param mipmapped mip mapped state of promised gpu texture + @param origin surface origin of promised gpu texture + @param colorType color type of promised gpu texture + @param alphaType alpha type of promised gpu texture + @param colorSpace range of colors; may be nullptr + @param textureFulfillProc function called to get actual gpu texture + @param textureReleaseProc function called when texture can be deleted + @param textureContext state passed to textureFulfillProc and textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp PromiseTextureFrom(sk_sp gpuContextProxy, + const GrBackendFormat& backendFormat, + SkISize dimensions, + GrMipmapped mipmapped, + GrSurfaceOrigin origin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace, + PromiseImageTextureFulfillProc textureFulfillProc, + PromiseImageTextureReleaseProc textureReleaseProc, + PromiseImageTextureContext textureContext); + +/** This is similar to 'PromiseTextureFrom' but it creates a GPU-backed SkImage from YUV[A] data. + The source data may be planar (i.e. spread across multiple textures). In + the extreme Y, U, V, and A are all in different planes and thus the image is specified by + four textures. 'backendTextureInfo' describes the planar arrangement, texture formats, + conversion to RGB, and origin of the textures. Separate 'textureFulfillProc' and + 'textureReleaseProc' calls are made for each texture. Each texture has its own + PromiseImageTextureContext. If 'backendTextureInfo' is not valid then no release proc + calls are made. Otherwise, the calls will be made even on failure. 'textureContexts' has one + entry for each of the up to four textures, as indicated by 'backendTextureInfo'. + Currently the mip mapped property of 'backendTextureInfo' is ignored. However, in the + near future it will be required that if it is kYes then textureFulfillProc must return + a mip mapped texture for each plane in order to successfully draw the image. + @param gpuContextProxy the thread-safe proxy of the gpu context. required. + @param backendTextureInfo info about the promised yuva gpu texture + @param imageColorSpace range of colors; may be nullptr + @param textureFulfillProc function called to get actual gpu texture + @param textureReleaseProc function called when texture can be deleted + @param textureContexts state passed to textureFulfillProc and textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp PromiseTextureFromYUVA(sk_sp gpuContextProxy, + const GrYUVABackendTextureInfo& backendTextureInfo, + sk_sp imageColorSpace, + PromiseImageTextureFulfillProc textureFulfillProc, + PromiseImageTextureReleaseProc textureReleaseProc, + PromiseImageTextureContext textureContexts[]); + +/** Retrieves the existing backend texture. If SkImage is not a Ganesh-backend texture image + or otherwise does not have such a texture, false is returned. Otherwise, outTexture will + be set to the image's texture. + + If flushPendingGrContextIO is true, completes deferred I/O operations. + If origin in not nullptr, copies location of content drawn into SkImage. + @param outTexture Will be set to the underlying texture of the image if non-null. + @param flushPendingGrContextIO flag to flush outstanding requests + @param origin Will be set to the origin orientation of the image if non-null. + @return false if a Ganesh backend texture cannot be retrieved. +*/ +SK_API bool GetBackendTextureFromImage(const SkImage* img, + GrBackendTexture* outTexture, + bool flushPendingGrContextIO, + GrSurfaceOrigin* origin = nullptr); +inline bool GetBackendTextureFromImage(sk_sp img, + GrBackendTexture* outTexture, + bool flushPendingGrContextIO, + GrSurfaceOrigin* origin = nullptr) { + return GetBackendTextureFromImage(img.get(), outTexture, flushPendingGrContextIO, origin); +} + +/** Extracts the backendTexture from an existing SkImage. + If the image is not already GPU-backed, the raster data will be uploaded as a texture + and returned. + If this is the only reference to the image, the old image's texture will be + moved out of the passed in image. + If the image is shared (has a refcount > 1), the texture will be copied and then returned. + @param context GPU context + @param image image, either CPU-backed or GPU-backed + @param backendTexture Will be set to the underlying texture of the image. + @param backendTextureReleaseProc Called when the texture is released + @return false if image cannot be uploaded. +*/ +SK_API bool MakeBackendTextureFromImage(GrDirectContext* context, + sk_sp image, + GrBackendTexture* backendTexture, + BackendTextureReleaseProc* backendTextureReleaseProc); +// Legacy name +inline bool GetBackendTextureFromImage(GrDirectContext* context, + sk_sp image, + GrBackendTexture* backendTexture, + BackendTextureReleaseProc* backendTextureReleaseProc) { + return MakeBackendTextureFromImage(context, std::move(image), backendTexture, + backendTextureReleaseProc); +} + +} // namespace SkImages + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h index 1e2823f71a95b..0ae85f07a0349 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h @@ -10,7 +10,7 @@ #include "include/core/SkString.h" #include "include/gpu/gl/GrGLFunctions.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include @@ -66,13 +66,13 @@ class SK_API GrGLExtensions { */ void add(const char[]); - void reset() { fStrings.reset(); } + void reset() { fStrings.clear(); } void dumpJSON(SkJSONWriter*) const; private: bool fInitialized = false; - SkTArray fStrings; + skia_private::TArray fStrings; }; #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h index 59b9cd9e18d55..4e488abcad432 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h @@ -11,7 +11,7 @@ #include #include "include/gpu/gl/GrGLTypes.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkTLogic.h" extern "C" { diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h index 5d6e3bb2d5f3d..64ca419b9b16a 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h @@ -304,9 +304,6 @@ struct SK_API GrGLInterface : public SkRefCnt { GrGLFunction fVertexAttribPointer; GrGLFunction fViewport; - /* NV_framebuffer_mixed_samples */ - GrGLFunction fCoverageModulation; - /* ARB_sync */ GrGLFunction fFenceSync; GrGLFunction fIsSync; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h index d5167787c1e05..3af4802eaacc2 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h @@ -10,6 +10,7 @@ #define GrGLTypes_DEFINED #include "include/core/SkRefCnt.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/gl/GrGLConfig.h" /** @@ -198,7 +199,7 @@ struct GrGLFramebufferInfo { struct GrGLSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrGLenum fTarget = 0; GrGLenum fFormat = 0; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h index f12d22ebb4f04..82a662ab13fdf 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h @@ -8,29 +8,71 @@ #ifndef skgpu_graphite_BackendTexture_DEFINED #define skgpu_graphite_BackendTexture_DEFINED +#include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/graphite/TextureInfo.h" +#ifdef SK_DAWN +#include "include/gpu/graphite/dawn/DawnTypes.h" +#endif + #ifdef SK_METAL -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" #endif #ifdef SK_VULKAN #include "include/private/gpu/vk/SkiaVulkan.h" #endif +namespace skgpu { +class MutableTextureState; +class MutableTextureStateRef; +} + namespace skgpu::graphite { -class BackendTexture { +class SK_API BackendTexture { public: - BackendTexture() {} + BackendTexture(); +#ifdef SK_DAWN + // Create a BackendTexture from a WGPUTexture. Texture info will be + // queried from the texture. Comparing to WGPUTextureView, + // SkImage::readPixels(), SkSurface::readPixels() and + // SkSurface::writePixels() are implemented by direct buffer copy. They + // should be more efficient. For WGPUTextureView, those methods will use + // create an intermediate WGPUTexture, and use it to transfer pixels. + // Note: + // - for better performance, using WGPUTexture IS RECOMMENDED. + // - The BackendTexture will not call retain or release on the passed in + // WGPUTexture. Thus the client must keep the WGPUTexture valid until + // they are no longer using the BackendTexture. + BackendTexture(WGPUTexture texture); + // Create a BackendTexture from a WGPUTextureView. Texture dimensions and + // info have to be provided. + // Note: + // - this method is for importing WGPUTextureView from wgpu::SwapChain only. + // - The BackendTexture will not call retain or release on the passed in + // WGPUTextureView. Thus the client must keep the WGPUTextureView valid + // until they are no longer using the BackendTexture. + BackendTexture(SkISize dimensions, + const DawnTextureInfo& info, + WGPUTextureView textureView); +#endif #ifdef SK_METAL // The BackendTexture will not call retain or release on the passed in MtlHandle. Thus the // client must keep the MtlHandle valid until they are no longer using the BackendTexture. BackendTexture(SkISize dimensions, MtlHandle mtlTexture); #endif +#ifdef SK_VULKAN + BackendTexture(SkISize dimensions, + const VulkanTextureInfo&, + VkImageLayout, + uint32_t queueFamilyIndex, + VkImage); +#endif + BackendTexture(const BackendTexture&); ~BackendTexture(); @@ -47,15 +89,42 @@ class BackendTexture { const TextureInfo& info() const { return fInfo; } + // If the client changes any of the mutable backend of the GrBackendTexture they should call + // this function to inform Skia that those values have changed. The backend API specific state + // that can be set from this function are: + // + // Vulkan: VkImageLayout and QueueFamilyIndex + void setMutableState(const skgpu::MutableTextureState&); + +#ifdef SK_DAWN + WGPUTexture getDawnTexturePtr() const; + WGPUTextureView getDawnTextureViewPtr() const; +#endif #ifdef SK_METAL MtlHandle getMtlTexture() const; #endif +#ifdef SK_VULKAN + VkImage getVkImage() const; + VkImageLayout getVkImageLayout() const; + uint32_t getVkQueueFamilyIndex() const; +#endif + private: + sk_sp mutableState() const; + SkISize fDimensions; TextureInfo fInfo; + sk_sp fMutableState; + union { +#ifdef SK_DAWN + struct { + WGPUTexture fDawnTexture; + WGPUTextureView fDawnTextureView; + }; +#endif #ifdef SK_METAL MtlHandle fMtlTexture; #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h deleted file mode 100644 index a0c977b283bf5..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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 skgpu_graphite_CombinationBuilder_DEFINED -#define skgpu_graphite_CombinationBuilder_DEFINED - -#include "include/core/SkTypes.h" - -#ifdef SK_ENABLE_PRECOMPILE - -#include -#include -#include -#include "include/core/SkBlendMode.h" -#include "include/core/SkSpan.h" -#include "include/core/SkTileMode.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTHash.h" - -class SkArenaAllocWithReset; -class SkKeyContext; -class SkPaintParamsKeyBuilder; -class SkShaderCodeDictionary; -class SkUniquePaintParamsID; - -namespace skgpu::graphite { - -class CombinationBuilder; -class CombinationBuilderTestAccess; -class Context; -class Option; - -enum class ShaderType : uint32_t { - kSolidColor, - - kLinearGradient, - kRadialGradient, - kSweepGradient, - kConicalGradient, - - kLocalMatrix, - kImage, - kPorterDuffBlendShader, - kBlendShader, - - kLast = kBlendShader -}; - -static constexpr int kShaderTypeCount = static_cast(ShaderType::kLast) + 1; - -struct TileModePair { - SkTileMode fX; - SkTileMode fY; - - bool operator==(const TileModePair& other) const { return fX == other.fX && fY == other.fY; } - bool operator!=(const TileModePair& other) const { return !(*this == other); } -}; - -// TODO: add ShaderID and ColorFilterID too -class BlenderID { -public: - BlenderID() : fID(0) {} // 0 is an invalid blender ID - BlenderID(const BlenderID& src) : fID(src.fID) {} - - bool isValid() const { return fID > 0; } - - bool operator==(const BlenderID& other) const { return fID == other.fID; } - - BlenderID& operator=(const BlenderID& src) { - fID = src.fID; - return *this; - } - -private: - friend class ::SkShaderCodeDictionary; // for ctor and asUInt access - friend class CombinationBuilder; // for asUInt access - - BlenderID(uint32_t id) : fID(id) {} - - uint32_t asUInt() const { return fID; } - - uint32_t fID; -}; - -// When combination options are added to the combination builder an CombinationOption -// object is frequently returned. This allows options to be added, recursively, to the -// previously added options. -// Note: CombinationOptions are stable memory-wise so, once returned, they are valid -// until CombinationBuilder::reset is called. -class CombinationOption { -public: - CombinationOption addChildOption(int childIndex, ShaderType); - - CombinationOption addChildOption(int childIndex, ShaderType, - int minNumStops, int maxNumStops); - - CombinationOption addChildOption(int childIndex, ShaderType, - SkSpan tileModes); - - bool isValid() const { return fDataInArena; } - -private: - friend class CombinationBuilder; // for ctor - friend class CombinationBuilderTestAccess; - - CombinationOption(CombinationBuilder* builder, Option* dataInArena) - : fBuilder(builder) - , fDataInArena(dataInArena) {} - - ShaderType type() const; - int numChildSlots() const; - SkDEBUGCODE(int epoch() const;) - - CombinationBuilder* fBuilder; - Option* fDataInArena; -}; - -class CombinationBuilder { -public: - enum class BlendModeGroup { - kPorterDuff, // [ kClear .. kScreen ] - kAdvanced, // [ kOverlay .. kMultiply ] - kColorAware, // [ kHue .. kLuminosity ] - kAll - }; - - CombinationBuilder(SkShaderCodeDictionary*); - ~CombinationBuilder(); - - // Blend Modes - void addOption(SkBlendMode); - void addOption(SkBlendMode rangeStart, SkBlendMode rangeEnd); // inclusive - void addOption(BlendModeGroup); - - // TODO: have this variant return an CombinationOption object - void addOption(BlenderID); - - // Shaders - CombinationOption addOption(ShaderType); - CombinationOption addOption(ShaderType, int minNumStops, int maxNumStops); // inclusive - CombinationOption addOption(ShaderType, SkSpan tileModes); - - void reset(); - -private: - friend class Context; // for access to 'buildCombinations' - friend class CombinationOption; // for 'addOptionInternal' and 'arena' - friend class CombinationBuilderTestAccess; // for 'num*Combinations' and 'epoch' - - int numShaderCombinations() const; - int numBlendModeCombinations() const; - int numCombinations() { - return this->numShaderCombinations() * this->numBlendModeCombinations(); - } - - // 'desiredCombination' must be less than numCombinations - void createKey(const SkKeyContext&, int desiredCombination, SkPaintParamsKeyBuilder*); - -#ifdef SK_DEBUG - void dump() const; - int epoch() const { return fEpoch; } -#endif - - SkArenaAllocWithReset* arena() { return fArena.get(); } - - template - Option* allocInArena(Args&&... args); - - Option* addOptionInternal(ShaderType); - Option* addOptionInternal(ShaderType, int minNumStops, int maxNumStops); - Option* addOptionInternal(ShaderType, SkSpan tileModes); - - void buildCombinations(SkShaderCodeDictionary*, - const std::function&); - - SkShaderCodeDictionary* fDictionary; - std::unique_ptr fArena; - SkTArray fShaderOptions; - - uint32_t fBlendModes; - // TODO: store the SkBlender-based blenders in the arena - SkTHashSet fBlenders; - - SkDEBUGCODE(int fEpoch = 0;) -}; - -} // namespace skgpu::graphite - -#endif // SK_ENABLE_PRECOMPILE - -#endif // skgpu_graphite_CombinationBuilder_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h index c5ff91e6cb7e0..0fb6eee418687 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h @@ -8,36 +8,34 @@ #ifndef skgpu_graphite_Context_DEFINED #define skgpu_graphite_Context_DEFINED +#include "include/core/SkImage.h" #include "include/core/SkRefCnt.h" #include "include/core/SkShader.h" #include "include/gpu/graphite/ContextOptions.h" #include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/graphite/Recorder.h" -#include "include/private/SingleOwner.h" +#include "include/private/base/SingleOwner.h" +#include #include class SkRuntimeEffect; -namespace skgpu { struct VulkanBackendContext; } - namespace skgpu::graphite { class BackendTexture; +class Buffer; +class ClientMappedBufferManager; class Context; class ContextPriv; -struct DawnBackendContext; class GlobalCache; -struct MtlBackendContext; +class PaintOptions; +class PlotUploadTracker; class QueueManager; class Recording; class ResourceProvider; class SharedContext; - -#ifdef SK_ENABLE_PRECOMPILE -class BlenderID; -class CombinationBuilder; -#endif +class TextureProxy; class SK_API Context final { public: @@ -48,37 +46,30 @@ class SK_API Context final { ~Context(); -#ifdef SK_DAWN - static std::unique_ptr MakeDawn(const DawnBackendContext&, const ContextOptions&); -#endif -#ifdef SK_METAL - static std::unique_ptr MakeMetal(const MtlBackendContext&, const ContextOptions&); -#endif - -#ifdef SK_VULKAN - static std::unique_ptr MakeVulkan(const VulkanBackendContext&, const ContextOptions&); -#endif - BackendApi backend() const; std::unique_ptr makeRecorder(const RecorderOptions& = {}); - void insertRecording(const InsertRecordingInfo&); - void submit(SyncToCpu = SyncToCpu::kNo); + bool insertRecording(const InsertRecordingInfo&); + bool submit(SyncToCpu = SyncToCpu::kNo); + + void asyncReadPixels(const SkImage* image, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); + + void asyncReadPixels(const SkSurface* surface, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); /** * Checks whether any asynchronous work is complete and if so calls related callbacks. */ void checkAsyncWorkCompletion(); -#ifdef SK_ENABLE_PRECOMPILE - // TODO: add "ShaderID addUserDefinedShader(sk_sp)" here - // TODO: add "ColorFilterID addUserDefinedColorFilter(sk_sp)" here - BlenderID addUserDefinedBlender(sk_sp); - - void precompile(CombinationBuilder*); -#endif - /** * Called to delete the passed in BackendTexture. This should only be called if the * BackendTexture was created by calling Recorder::createBackendTexture on a Recorder created @@ -94,21 +85,83 @@ class SK_API Context final { ContextPriv priv(); const ContextPriv priv() const; // NOLINT(readability-const-return-type) + class ContextID { + public: + static Context::ContextID Next(); + + ContextID() : fID(SK_InvalidUniqueID) {} + + bool operator==(const ContextID& that) const { return fID == that.fID; } + bool operator!=(const ContextID& that) const { return !(*this == that); } + + void makeInvalid() { fID = SK_InvalidUniqueID; } + bool isValid() const { return fID != SK_InvalidUniqueID; } + + private: + constexpr ContextID(uint32_t id) : fID(id) {} + uint32_t fID; + }; + + ContextID contextID() const { return fContextID; } + protected: - Context(sk_sp, std::unique_ptr); + Context(sk_sp, std::unique_ptr, const ContextOptions&); private: friend class ContextPriv; + friend class ContextCtorAccessor; SingleOwner* singleOwner() const { return &fSingleOwner; } + // Must be called in Make() to handle one-time GPU setup operations that can possibly fail and + // require Context::Make() to return a nullptr. + bool finishInitialization(); + + void asyncReadPixels(const TextureProxy* textureProxy, + const SkImageInfo& srcImageInfo, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); + + // Inserts a texture to buffer transfer task, used by asyncReadPixels methods + struct PixelTransferResult { + using ConversionFn = void(void* dst, const void* mappedBuffer); + // If null then the transfer could not be performed. Otherwise this buffer will contain + // the pixel data when the transfer is complete. + sk_sp fTransferBuffer; + // RowBytes for transfer buffer data + size_t fRowBytes; + // If this is null then the transfer buffer will contain the data in the requested + // color type. Otherwise, when the transfer is done this must be called to convert + // from the transfer buffer's color type to the requested color type. + std::function fPixelConverter; + }; + PixelTransferResult transferPixels(const TextureProxy*, + const SkImageInfo& srcImageInfo, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect); + sk_sp fSharedContext; std::unique_ptr fResourceProvider; std::unique_ptr fQueueManager; + std::unique_ptr fMappedBufferManager; + std::unique_ptr fPlotUploadTracker; // In debug builds we guard against improper thread handling. This guard is passed to the // ResourceCache for the Context. mutable SingleOwner fSingleOwner; + +#if GRAPHITE_TEST_UTILS + // In test builds a Recorder may track the Context that was used to create it. + bool fStoreContextRefInRecorder = false; + // If this tracking is on, to allow the client to safely delete this Context or its Recorders + // in any order we must also track the Recorders created here. + std::vector fTrackedRecorders; +#endif + + // Needed for MessageBox handling + const ContextID fContextID; }; } // namespace skgpu::graphite diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h index d55351a774c1d..b9ac1b09d1619 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h @@ -8,6 +8,8 @@ #ifndef skgpu_graphite_ContextOptions_DEFINED #define skgpu_graphite_ContextOptions_DEFINED +#include "include/private/base/SkAPI.h" + namespace skgpu { class ShaderErrorHandler; } namespace skgpu::graphite { @@ -15,6 +17,13 @@ namespace skgpu::graphite { struct SK_API ContextOptions { ContextOptions() {} + /** + * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. + * This does not affect code path choices that are made for perfomance reasons nor does it + * override other ContextOption settings. + */ + bool fDisableDriverCorrectnessWorkarounds = false; + /** * If present, use this object to report shader compilation failures. If not, report failures * via SkDebugf and assert. @@ -55,18 +64,7 @@ struct SK_API ContextOptions { * fGlypheCacheTextureMaximumBytes. */ bool fAllowMultipleGlyphCacheTextures = true; - - /** - * If true, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp - * rendering of all glyphs. This must be set to true to use Slugs. - */ - #if defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_STRIKE_SERIALIZE) - bool fSupportBilerpFromGlyphAtlas = true; - #else bool fSupportBilerpFromGlyphAtlas = false; - #endif #if GRAPHITE_TEST_UTILS /** @@ -77,6 +75,12 @@ struct SK_API ContextOptions { * Maximum width and height of internal texture atlases. */ int fMaxTextureAtlasSize = 2048; + + /** + * If true, will store a pointer in Recorder that points back to the Context + * that created it. Used by readPixels() and other methods that normally require a Context. + */ + bool fStoreContextRefInRecorder = false; #endif }; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h index 474e5089fcf2a..231f2a5e1454d 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h @@ -8,14 +8,18 @@ #ifndef skgpu_graphite_GraphiteTypes_DEFINED #define skgpu_graphite_GraphiteTypes_DEFINED +#include "include/core/SkPoint.h" #include "include/core/SkTypes.h" #include "include/gpu/GpuTypes.h" #include +class SkSurface; + namespace skgpu::graphite { class Recording; +class Task; using GpuFinishedContext = void*; using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackResult); @@ -27,9 +31,33 @@ using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackRes * the Recording that they may be holding onto. If the Recording is successfully submitted to the * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All * other cases where some failure occured it will be called with CallbackResult::kFailed. + * + * The fTargetSurface, if provided, is used as a target for any draws recorded onto a deferred + * canvas returned from Recorder::makeDeferredCanvas. This target surface must be provided iff + * the Recording contains any such draws. It must be Graphite-backed and its backing texture's + * TextureInfo must match the info provided to the Recorder when making the deferred canvas. + * + * fTargetTranslation is an additional translation applied to draws targeting fTargetSurface. */ struct InsertRecordingInfo { Recording* fRecording = nullptr; + + SkSurface* fTargetSurface = nullptr; + SkIVector fTargetTranslation = {0, 0}; + + GpuFinishedContext fFinishedContext = nullptr; + GpuFinishedProc fFinishedProc = nullptr; +}; + +/** + * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or + * when there is a failure that caused it not to be submitted. The callback will always be called + * and the caller can use the callback to know it is safe to free any resources associated with + * the Recording that they may be holding onto. If the Recording is successfully submitted to the + * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All + * other cases where some failure occured it will be called with CallbackResult::kFailed. + */ +struct InsertFinishInfo { GpuFinishedContext fFinishedContext = nullptr; GpuFinishedProc fFinishedProc = nullptr; }; @@ -42,12 +70,34 @@ enum class SyncToCpu : bool { kNo = false }; -/** - * Is the texture mipmapped or not +/* + * For Promise Images - should the Promise Image be fulfilled every time a Recording that references + * it is inserted into the Context. */ -enum class Mipmapped : bool { - kNo = false, - kYes = true, +enum class Volatile : bool { + kNo = false, // only fulfilled once + kYes = true // fulfilled on every insertion call +}; + +/* + * Graphite's different rendering methods each only apply to certain types of draws. This + * enum supports decision-making regarding the different renderers and what is being drawn. + */ +enum DrawTypeFlags : uint8_t { + + kNone = 0b000, + + // SkCanvas:: drawSimpleText, drawString, drawGlyphs, drawTextBlob, drawSlug + kText = 0b001, + + // SkCanvas::drawVertices + kDrawVertices = 0b010, + + // All other canvas draw calls + kShape = 0b100, + + kMostCommon = kText | kShape, + kAll = kText | kDrawVertices | kShape }; } // namespace skgpu::graphite diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h index 748b678c5ffa9..3c071fe9ea3e7 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h @@ -13,7 +13,6 @@ namespace skgpu::graphite { -enum class Mipmapped : bool; class Recorder; /* @@ -23,9 +22,12 @@ class Recorder; * return a Graphite-backed version of the provided SkImage that meets the specified * requirements. * - * Skia requires that 'findOrCreate' return a Graphite-backed image that preserves the dimensions, - * number of channels and alpha type of the original image. The bit depth of the - * individual channels can change (e.g., 4444 -> 8888 is allowed). + * Skia requires that 'findOrCreate' return a Graphite-backed image that preserves the + * dimensions and alpha type of the original image. The bit depth of the + * individual channels can change (e.g., 4444 -> 8888 is allowed) as well as the channels - as + * long as the returned image has a superset of the original image's channels + * (e.g., 565 -> 8888 opaque is allowed). + * * Wrt mipmapping, the returned image can have different mipmap settings than requested. If * mipmapping was requested but not returned, the sampling level will be reduced to linear. * If the requirements are not met by the returned image (modulo the flexibility wrt mipmapping) diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h index 82cbd0f1698cf..6e911a4e72c72 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h @@ -11,17 +11,20 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/gpu/graphite/GraphiteTypes.h" -#include "include/private/SingleOwner.h" -#include "include/private/SkTHash.h" +#include "include/gpu/graphite/Recording.h" +#include "include/private/base/SingleOwner.h" +#include "include/private/base/SkTArray.h" #include +class SkCanvas; +struct SkImageInfo; class SkPixmap; -class SkRuntimeEffectDictionary; -class SkTextureDataBlock; -class SkUniformDataBlock; -namespace skgpu { class TokenTracker; } +namespace skgpu { +class RefCntedCallback; +class TokenTracker; +} namespace sktext::gpu { class StrikeCache; @@ -33,22 +36,26 @@ namespace skgpu::graphite { class AtlasManager; class BackendTexture; class Caps; +class Context; class Device; class DrawBufferManager; class GlobalCache; class ImageProvider; +class ProxyCache; class RecorderPriv; -class Recording; class ResourceProvider; +class RuntimeEffectDictionary; class SharedContext; class Task; class TaskGraph; +class TextureDataBlock; class TextureInfo; +class UniformDataBlock; class UploadBufferManager; template class PipelineDataCache; -using UniformDataCache = PipelineDataCache; -using TextureDataCache = PipelineDataCache; +using UniformDataCache = PipelineDataCache; +using TextureDataCache = PipelineDataCache; struct SK_API RecorderOptions final { RecorderOptions(); @@ -115,11 +122,23 @@ class SK_API Recorder final { */ void deleteBackendTexture(BackendTexture&); + // Adds a proc that will be moved to the Recording upon snap, subsequently attached to the + // CommandBuffer when the Recording is added, and called when that CommandBuffer is submitted + // and finishes. If the Recorder or Recording is deleted before the proc is added to the + // CommandBuffer, it will be called with result Failure. + void addFinishInfo(const InsertFinishInfo&); + + // Returns a canvas that will record to a proxy surface, which must be instantiated on replay. + // This can only be called once per Recording; subsequent calls will return null until a + // Recording is snapped. Additionally, the returned SkCanvas is only valid until the next + // Recording snap, at which point it is deleted. + SkCanvas* makeDeferredCanvas(const SkImageInfo&, const TextureInfo&); + // Provides access to functions that aren't part of the public API. RecorderPriv priv(); const RecorderPriv priv() const; // NOLINT(readability-const-return-type) -#if GR_TEST_UTILS +#if GRAPHITE_TEST_UTILS bool deviceIsRegistered(Device*); #endif @@ -156,7 +175,7 @@ class SK_API Recorder final { sk_sp fSharedContext; std::unique_ptr fResourceProvider; - std::unique_ptr fRuntimeEffectDict; + std::unique_ptr fRuntimeEffectDict; std::unique_ptr fGraph; std::unique_ptr fUniformDataCache; @@ -176,6 +195,17 @@ class SK_API Recorder final { // This guard is passed to the ResourceCache. // TODO: Should we also pass this to Device, DrawContext, and similar classes? mutable SingleOwner fSingleOwner; + + sk_sp fTargetProxyDevice; + std::unique_ptr fTargetProxyCanvas; + std::unique_ptr fTargetProxyData; + + skia_private::TArray> fFinishedProcs; + +#if GRAPHITE_TEST_UTILS + // For testing use only -- the Context used to create this Recorder + Context* fContext = nullptr; +#endif }; } // namespace skgpu::graphite diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h index b1cb770bf0667..4a60e5b936626 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h @@ -9,10 +9,17 @@ #define skgpu_graphite_Recording_DEFINED #include "include/core/SkRefCnt.h" +#include "include/private/SkChecksum.h" +#include "include/private/base/SkTArray.h" #include +#include #include +namespace skgpu { +class RefCntedCallback; +} + namespace skgpu::graphite { class CommandBuffer; @@ -20,18 +27,51 @@ class RecordingPriv; class Resource; class ResourceProvider; class TaskGraph; +class Texture; +class TextureInfo; +class TextureProxy; -class Recording final { +class SK_API Recording final { public: ~Recording(); RecordingPriv priv(); +#if GRAPHITE_TEST_UTILS + bool isTargetProxyInstantiated() const; +#endif + private: - friend class Recorder; // for ctor + friend class Recorder; // for ctor and LazyProxyData friend class RecordingPriv; - Recording(std::unique_ptr); + // LazyProxyData is used if this recording should be replayed to a target that is provided on + // replay, and it handles the target proxy's instantiation with the provided target. + class LazyProxyData { + public: + LazyProxyData(const TextureInfo&); + + TextureProxy* lazyProxy(); + sk_sp refLazyProxy(); + + bool lazyInstantiate(ResourceProvider*, sk_sp); + + private: + sk_sp fTarget; + sk_sp fTargetProxy; + }; + + struct ProxyHash { + std::size_t operator()(const sk_sp& proxy) const { + return SkGoodHash()(proxy.get()); + } + }; + + Recording(std::unique_ptr, + std::unordered_set, ProxyHash>&& nonVolatileLazyProxies, + std::unordered_set, ProxyHash>&& volatileLazyProxies, + std::unique_ptr targetProxyData, + skia_private::TArray>&& finishedProcs); bool addCommands(CommandBuffer*, ResourceProvider*); void addResourceRef(sk_sp); @@ -42,6 +82,13 @@ class Recording final { // Those refs are stored in the array here and will eventually be passed onto a CommandBuffer // when the Recording adds its commands. std::vector> fExtraResourceRefs; + + std::unordered_set, ProxyHash> fNonVolatileLazyProxies; + std::unordered_set, ProxyHash> fVolatileLazyProxies; + + std::unique_ptr fTargetProxyData; + + skia_private::TArray> fFinishedProcs; }; } // namespace skgpu::graphite diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h index 15f3081e55f73..9a30839ab43e8 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h @@ -10,8 +10,12 @@ #include "include/gpu/graphite/GraphiteTypes.h" +#ifdef SK_DAWN +#include "include/private/gpu/graphite/DawnTypesPriv.h" +#endif + #ifdef SK_METAL -#include "include/private/gpu/graphite/MtlTypesPriv.h" +#include "include/private/gpu/graphite/MtlGraphiteTypesPriv.h" #endif #ifdef SK_VULKAN @@ -20,15 +24,25 @@ namespace skgpu::graphite { -class TextureInfo { +class SK_API TextureInfo { public: TextureInfo() {} +#ifdef SK_DAWN + TextureInfo(const DawnTextureInfo& dawnInfo) + : fBackend(BackendApi::kDawn) + , fValid(true) + , fSampleCount(dawnInfo.fSampleCount) + , fMipmapped(dawnInfo.fMipmapped) + , fProtected(Protected::kNo) + , fDawnSpec(dawnInfo) {} +#endif + #ifdef SK_METAL TextureInfo(const MtlTextureInfo& mtlInfo) : fBackend(BackendApi::kMetal) , fValid(true) , fSampleCount(mtlInfo.fSampleCount) - , fLevelCount(mtlInfo.fLevelCount) + , fMipmapped(mtlInfo.fMipmapped) , fProtected(Protected::kNo) , fMtlSpec(mtlInfo) {} #endif @@ -38,7 +52,7 @@ class TextureInfo { : fBackend(BackendApi::kVulkan) , fValid(true) , fSampleCount(vkInfo.fSampleCount) - , fLevelCount(vkInfo.fLevelCount) + , fMipmapped(vkInfo.fMipmapped) , fProtected(Protected::kNo) , fVkSpec(vkInfo) { if (vkInfo.fFlags & VK_IMAGE_CREATE_PROTECTED_BIT) { @@ -58,15 +72,25 @@ class TextureInfo { BackendApi backend() const { return fBackend; } uint32_t numSamples() const { return fSampleCount; } - uint32_t numMipLevels() const { return fLevelCount; } + Mipmapped mipmapped() const { return fMipmapped; } Protected isProtected() const { return fProtected; } +#ifdef SK_DAWN + bool getDawnTextureInfo(DawnTextureInfo* info) const { + if (!this->isValid() || fBackend != BackendApi::kDawn) { + return false; + } + *info = DawnTextureSpecToTextureInfo(fDawnSpec, fSampleCount, fMipmapped); + return true; + } +#endif + #ifdef SK_METAL bool getMtlTextureInfo(MtlTextureInfo* info) const { if (!this->isValid() || fBackend != BackendApi::kMetal) { return false; } - *info = MtlTextureSpecToTextureInfo(fMtlSpec, fSampleCount, fLevelCount); + *info = MtlTextureSpecToTextureInfo(fMtlSpec, fSampleCount, fMipmapped); return true; } #endif @@ -76,12 +100,24 @@ class TextureInfo { if (!this->isValid() || fBackend != BackendApi::kVulkan) { return false; } - *info = VulkanTextureSpecToTextureInfo(fVkSpec, fSampleCount, fLevelCount); + *info = VulkanTextureSpecToTextureInfo(fVkSpec, fSampleCount, fMipmapped); return true; } #endif private: +#ifdef SK_DAWN + friend class DawnCaps; + friend class DawnCommandBuffer; + friend class DawnGraphicsPipeline; + friend class DawnResourceProvider; + friend class DawnTexture; + const DawnTextureSpec& dawnTextureSpec() const { + SkASSERT(fValid && fBackend == BackendApi::kDawn); + return fDawnSpec; + } +#endif + #ifdef SK_METAL friend class MtlCaps; friend class MtlGraphicsPipeline; @@ -105,10 +141,13 @@ class TextureInfo { bool fValid = false; uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + Mipmapped fMipmapped = Mipmapped::kNo; Protected fProtected = Protected::kNo; union { +#ifdef SK_DAWN + DawnTextureSpec fDawnSpec; +#endif #ifdef SK_METAL MtlTextureSpec fMtlSpec; #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h new file mode 100644 index 0000000000000..c3b80ae196e32 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h @@ -0,0 +1,139 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef skgpu_graphite_YUVABackendTextures_DEFINED +#define skgpu_graphite_YUVABackendTextures_DEFINED + +#include "include/core/SkSpan.h" +#include "include/core/SkYUVAInfo.h" +#include "include/gpu/graphite/BackendTexture.h" + +#include + +namespace skgpu::graphite { +class Recorder; + +/** + * A description of a set of BackendTextures that hold the planar data described by a SkYUVAInfo. + */ +class SK_API YUVABackendTextureInfo { +public: + static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; + + /** Default YUVABackendTextureInfo is invalid. */ + YUVABackendTextureInfo() = default; + YUVABackendTextureInfo(const YUVABackendTextureInfo&) = default; + YUVABackendTextureInfo& operator=(const YUVABackendTextureInfo&) = default; + + /** + * Initializes a YUVABackendTextureInfo to describe a set of textures that can store the + * planes indicated by the SkYUVAInfo. The texture dimensions are taken from the SkYUVAInfo's + * plane dimensions. All the described textures share a common origin. The planar image this + * describes will be mip mapped if all the textures are individually mip mapped as indicated + * by Mipmapped. This will produce an invalid result (return false from isValid()) if the + * passed formats' channels don't agree with SkYUVAInfo. + */ + YUVABackendTextureInfo(const Recorder*, + const SkYUVAInfo&, + const TextureInfo[kMaxPlanes], + Mipmapped); + + bool operator==(const YUVABackendTextureInfo&) const; + bool operator!=(const YUVABackendTextureInfo& that) const { return !(*this == that); } + + /** TextureInfo for the ith plane, or invalid if i >= numPlanes() */ + const TextureInfo& planeTextureInfo(int i) const { + SkASSERT(i >= 0); + return fPlaneTextureInfos[static_cast(i)]; + } + + const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } + + SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } + + Mipmapped mipmapped() const { return fMipmapped; } + + /** The number of planes, 0 if this YUVABackendTextureInfo is invalid. */ + int numPlanes() const { return fYUVAInfo.numPlanes(); } + + /** + * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture + * formats. + */ + bool isValid() const { return fYUVAInfo.isValid(); } + + /** + * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be + * valid if this->isValid(). + */ + SkYUVAInfo::YUVALocations toYUVALocations() const; + +private: + SkYUVAInfo fYUVAInfo; + std::array fPlaneTextureInfos; + std::array fPlaneChannelMasks; + Mipmapped fMipmapped = Mipmapped::kNo; +}; + +/** + * A set of BackendTextures that hold the planar data for an image described a SkYUVAInfo. + */ +class SK_API YUVABackendTextures { +public: + static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; + + YUVABackendTextures() = default; + YUVABackendTextures(const YUVABackendTextures&) = delete; + YUVABackendTextures& operator=(const YUVABackendTextures&) = delete; + + /** + * Initializes a YUVABackendTextures object from a set of textures that store the planes + * indicated by the SkYUVAInfo. This will produce an invalid result (return false from + * isValid()) if the passed texture formats' channels don't agree with SkYUVAInfo. + */ + YUVABackendTextures(const Recorder*, + const SkYUVAInfo&, + const BackendTexture[kMaxPlanes]); + + SkSpan planeTextures() const { + return SkSpan(fPlaneTextures); + } + + /** BackendTexture for the ith plane, or invalid if i >= numPlanes() */ + BackendTexture planeTexture(int i) const { + SkASSERT(i >= 0); + return fPlaneTextures[static_cast(i)]; + } + + const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } + + SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } + + /** The number of planes, 0 if this YUVABackendTextureInfo is invalid. */ + int numPlanes() const { return fYUVAInfo.numPlanes(); } + + /** + * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture + * formats. + */ + bool isValid() const { return fYUVAInfo.isValid(); } + + /** + * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be + * valid if this->isValid(). + */ + SkYUVAInfo::YUVALocations toYUVALocations() const; + +private: + SkYUVAInfo fYUVAInfo; + std::array fPlaneTextures; + std::array fPlaneChannelMasks; +}; + +} // End of namespace skgpu::graphite + +#endif // skgpu_graphite_YUVABackendTextures_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h new file mode 100644 index 0000000000000..291be756306e7 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h @@ -0,0 +1,40 @@ +/* + * 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 skgpu_graphite_DawnTypes_DEFINED +#define skgpu_graphite_DawnTypes_DEFINED + +#include "include/gpu/graphite/GraphiteTypes.h" +#include "webgpu/webgpu_cpp.h" + +namespace skgpu::graphite { + +struct DawnTextureInfo { + uint32_t fSampleCount = 1; + Mipmapped fMipmapped = Mipmapped::kNo; + + // wgpu::TextureDescriptor properties + wgpu::TextureFormat fFormat = wgpu::TextureFormat::Undefined; + wgpu::TextureUsage fUsage = wgpu::TextureUsage::None; + + DawnTextureInfo() = default; + DawnTextureInfo(const wgpu::Texture& texture); + DawnTextureInfo(uint32_t sampleCount, + Mipmapped mipmapped, + wgpu::TextureFormat format, + wgpu::TextureUsage usage) + : fSampleCount(sampleCount) + , fMipmapped(mipmapped) + , fFormat(format) + , fUsage(usage) {} +}; + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_DawnTypes_DEFINED + + diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h new file mode 100644 index 0000000000000..059d128ef59d6 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h @@ -0,0 +1,28 @@ +/* + * 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 skgpu_graphite_DawnUtils_DEFINED +#define skgpu_graphite_DawnUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; +struct DawnBackendContext; + +namespace ContextFactory { +SK_API std::unique_ptr MakeDawn(const DawnBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + + +#endif // skgpu_graphite_DawnUtils_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h index de5f917a9aa04..9d6d0192d170d 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h @@ -8,7 +8,7 @@ #ifndef skgpu_graphite_MtlBackendContext_DEFINED #define skgpu_graphite_MtlBackendContext_DEFINED -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" namespace skgpu::graphite { diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h similarity index 85% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h index 5f4c4c8dccff6..bc04421643db2 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h @@ -5,9 +5,10 @@ * found in the LICENSE file. */ -#ifndef skgpu_graphite_MtlTypes_DEFINED -#define skgpu_graphite_MtlTypes_DEFINED +#ifndef skgpu_graphite_MtlGraphiteTypes_DEFINED +#define skgpu_graphite_MtlGraphiteTypes_DEFINED +#include "include/gpu/graphite/GraphiteTypes.h" #include "include/ports/SkCFObject.h" /////////////////////////////////////////////////////////////////////////////// @@ -38,7 +39,7 @@ using MtlHandle = const void*; struct MtlTextureInfo { uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + skgpu::Mipmapped fMipmapped = skgpu::Mipmapped::kNo; // Since we aren't in an Obj-C header we can't directly use Mtl types here. Each of these can // cast to their mapped Mtl types list below. @@ -50,13 +51,13 @@ struct MtlTextureInfo { MtlTextureInfo() = default; MtlTextureInfo(MtlHandle mtlTexture); MtlTextureInfo(uint32_t sampleCount, - uint32_t levelCount, + skgpu::Mipmapped mipmapped, MtlPixelFormat format, MtlTextureUsage usage, MtlStorageMode storageMode, bool framebufferOnly) : fSampleCount(sampleCount) - , fLevelCount(levelCount) + , fMipmapped(mipmapped) , fFormat(format) , fUsage(usage) , fStorageMode(storageMode) @@ -65,4 +66,4 @@ struct MtlTextureInfo { } // namespace skgpu::graphite -#endif // skgpu_graphite_MtlTypes_DEFINED +#endif // skgpu_graphite_MtlGraphiteTypes_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h new file mode 100644 index 0000000000000..cd7837f86c238 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.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 skgpu_graphite_MtlGraphiteUtils_DEFINED +#define skgpu_graphite_MtlGraphiteUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; +struct MtlBackendContext; + +namespace ContextFactory { +SK_API std::unique_ptr MakeMetal(const MtlBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_MtlGraphiteUtils_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h index 4e9802dbca9dc..bd448d2ca6c1e 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h @@ -8,13 +8,14 @@ #ifndef skgpu_graphite_VulkanGraphiteTypes_DEFINED #define skgpu_graphite_VulkanGraphiteTypes_DEFINED +#include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/vk/VulkanTypes.h" namespace skgpu::graphite { struct VulkanTextureInfo { uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + Mipmapped fMipmapped = Mipmapped::kNo; // VkImageCreateInfo properties // Currently the only supported flag is VK_IMAGE_CREATE_PROTECTED_BIT. Any other flag will not @@ -24,8 +25,6 @@ struct VulkanTextureInfo { VkImageTiling fImageTiling = VK_IMAGE_TILING_OPTIMAL; VkImageUsageFlags fImageUsageFlags = 0; VkSharingMode fSharingMode = VK_SHARING_MODE_EXCLUSIVE; - uint32_t fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED; - VkImageLayout fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; // Properties related to the image view and sampling. These are less inherent properties of the // VkImage but describe how the VkImage should be used within Skia. @@ -41,24 +40,20 @@ struct VulkanTextureInfo { VulkanTextureInfo() = default; VulkanTextureInfo(uint32_t sampleCount, - uint32_t levelCount, + Mipmapped mipmapped, VkImageCreateFlags flags, VkFormat format, VkImageTiling imageTiling, VkImageUsageFlags imageUsageFlags, VkSharingMode sharingMode, - uint32_t currentQueueFamily, - VkImageLayout imageLayout, VkImageAspectFlags aspectMask) : fSampleCount(sampleCount) - , fLevelCount(levelCount) + , fMipmapped(mipmapped) , fFlags(flags) , fFormat(format) , fImageTiling(imageTiling) , fImageUsageFlags(imageUsageFlags) , fSharingMode(sharingMode) - , fCurrentQueueFamily(currentQueueFamily) - , fImageLayout(imageLayout) , fAspectMask(aspectMask) {} }; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h new file mode 100644 index 0000000000000..0cfa0e9bf0a40 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h @@ -0,0 +1,28 @@ +/* + * 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 skgpu_graphite_VulkanGraphiteUtils_DEFINED +#define skgpu_graphite_VulkanGraphiteUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu { struct VulkanBackendContext; } + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; + +namespace ContextFactory { +SK_API std::unique_ptr MakeVulkan(const VulkanBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_VulkanGraphiteUtils_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h index ac866167bc679..b3e4b7b84268d 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h @@ -8,7 +8,8 @@ #ifndef GrMockOptions_DEFINED #define GrMockOptions_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/core/SkTextureCompressionType.h" +#include "include/gpu/GpuTypes.h" #include "include/private/gpu/ganesh/GrTypesPriv.h" class GrBackendFormat; @@ -16,17 +17,17 @@ class GrBackendFormat; struct GrMockTextureInfo { GrMockTextureInfo() : fColorType(GrColorType::kUnknown) - , fCompressionType(SkImage::CompressionType::kNone) + , fCompressionType(SkTextureCompressionType::kNone) , fID(0) {} GrMockTextureInfo(GrColorType colorType, - SkImage::CompressionType compressionType, + SkTextureCompressionType compressionType, int id) : fColorType(colorType) , fCompressionType(compressionType) , fID(id) { SkASSERT(fID); - if (fCompressionType != SkImage::CompressionType::kNone) { + if (fCompressionType != SkTextureCompressionType::kNone) { SkASSERT(colorType == GrColorType::kUnknown); } } @@ -39,10 +40,10 @@ struct GrMockTextureInfo { GrBackendFormat getBackendFormat() const; - SkImage::CompressionType compressionType() const { return fCompressionType; } + SkTextureCompressionType compressionType() const { return fCompressionType; } GrColorType colorType() const { - SkASSERT(fCompressionType == SkImage::CompressionType::kNone); + SkASSERT(fCompressionType == SkTextureCompressionType::kNone); return fColorType; } @@ -50,7 +51,7 @@ struct GrMockTextureInfo { private: GrColorType fColorType; - SkImage::CompressionType fCompressionType; + SkTextureCompressionType fCompressionType; int fID; }; @@ -82,12 +83,15 @@ struct GrMockRenderTargetInfo { struct GrMockSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrColorType fColorType = GrColorType::kUnknown; - SkImage::CompressionType fCompressionType = SkImage::CompressionType::kNone; + SkTextureCompressionType fCompressionType = SkTextureCompressionType::kNone; }; +static constexpr int kSkTextureCompressionTypeCount = + static_cast(SkTextureCompressionType::kLast) + 1; + /** * A pointer to this type is used as the GrBackendContext when creating a Mock GrContext. It can be * used to specify capability options for the mock context. If nullptr is used a default constructed @@ -105,9 +109,9 @@ struct GrMockOptions { fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888]; - fCompressedOptions[(int)SkImage::CompressionType::kETC2_RGB8_UNORM].fTexturable = true; - fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGB8_UNORM].fTexturable = true; - fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGBA8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kETC2_RGB8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kBC1_RGB8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kBC1_RGBA8_UNORM].fTexturable = true; } struct ConfigOptions { @@ -126,7 +130,7 @@ struct GrMockOptions { int fMaxWindowRectangles = 0; int fMaxVertexAttributes = 16; ConfigOptions fConfigOptions[kGrColorTypeCnt]; - ConfigOptions fCompressedOptions[SkImage::kCompressionTypeCount]; + ConfigOptions fCompressedOptions[kSkTextureCompressionTypeCount]; // GrShaderCaps options. bool fIntegerSupport = false; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h index f7a232e3c6cea..7c0d620e06412 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h @@ -8,7 +8,7 @@ #ifndef GrMtlTypes_DEFINED #define GrMtlTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include "include/ports/SkCFObject.h" /** @@ -49,7 +49,7 @@ struct GrMtlTextureInfo { struct GrMtlSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; // Since we aren't in an Obj-C header we can't directly use Mtl types here. Each of these can // cast to their mapped Mtl types list below. diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h index b166e59920676..23c1b0deaf4a5 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h @@ -72,7 +72,7 @@ struct SK_API GrVkBackendContext { bool fOwnsInstanceAndDevice = false; // Indicates that we are working with protected content and all CommandPool and Queue operations // should be done in a protected context. - GrProtected fProtectedContext = GrProtected::kNo; + skgpu::Protected fProtectedContext = skgpu::Protected::kNo; }; #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h index 9d0a4c2c60133..ae680a8af5521 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h @@ -9,7 +9,7 @@ #ifndef GrVkTypes_DEFINED #define GrVkTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/vk/VulkanTypes.h" using GrVkBackendMemory = skgpu::VulkanBackendMemory; @@ -72,7 +72,7 @@ struct GrVkImageInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; uint32_t fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrVkYcbcrConversionInfo fYcbcrConversionInfo; VkSharingMode fSharingMode = VK_SHARING_MODE_EXCLUSIVE; #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK @@ -137,7 +137,7 @@ struct GrVkDrawableInfo { struct GrVkSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; VkImageTiling fImageTiling = VK_IMAGE_TILING_OPTIMAL; VkFormat fFormat = VK_FORMAT_UNDEFINED; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h index 445fd53908333..90a40c0e674d8 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h @@ -10,7 +10,7 @@ #include "include/core/SkString.h" #include "include/gpu/vk/VulkanTypes.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" namespace skgpu { @@ -48,7 +48,7 @@ class SK_API VulkanExtensions { #ifdef SK_DEBUG void dump() const { SkDebugf("**Vulkan Extensions**\n"); - for (int i = 0; i < fExtensions.count(); ++i) { + for (int i = 0; i < fExtensions.size(); ++i) { SkDebugf("%s. Version: %d\n", fExtensions[i].fName.c_str(), fExtensions[i].fSpecVersion); } @@ -59,7 +59,7 @@ class SK_API VulkanExtensions { private: void getSpecVersions(VulkanGetProc getProc, VkInstance, VkPhysicalDevice); - SkTArray fExtensions; + skia_private::TArray fExtensions; }; } // namespace skgpu diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h index 9d73fdf4bdf65..ebaa28ed1b4b0 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h @@ -35,7 +35,7 @@ class VulkanMemoryAllocator : public SkRefCnt { }; enum class BufferUsage { - // Buffers that will only be accessed from the device (large const buffers). Will always be + // Buffers that will only be accessed from the device (large const buffers) will always be // in device local memory. kGpuOnly, // Buffers that typically will be updated multiple times by the host and read on the gpu @@ -103,12 +103,10 @@ class VulkanMemoryAllocator : public SkRefCnt { virtual void freeMemory(const skgpu::VulkanBackendMemory&) = 0; - // Returns the total amount of memory that is allocated and in use by an allocation for this - // allocator. - virtual uint64_t totalUsedMemory() const = 0; - - // Returns the total amount of memory that is allocated by this allocator. - virtual uint64_t totalAllocatedMemory() const = 0; + // Returns the total amount of memory that is allocated as well as total + // amount of memory in use by an allocation from this allocator. + // Return 1st param is total allocated memory, 2nd is total used memory. + virtual std::pair totalAllocatedAndUsedMemory() const = 0; }; } // namespace skgpu diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h index 18c71562e08c0..47d2b3118fbf6 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h @@ -9,8 +9,8 @@ #include "include/core/SkPath.h" #include "include/core/SkTypes.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkTDArray.h" struct SkRect; @@ -102,7 +102,7 @@ class SK_API SkOpBuilder { bool resolve(SkPath* result); private: - SkTArray fPathRefs; + skia_private::TArray fPathRefs; SkTDArray fOps; static bool FixWinding(SkPath* path); diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h new file mode 100644 index 0000000000000..6a22365af433b --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h @@ -0,0 +1,22 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkFontMgr_data_DEFINED +#define SkFontMgr_data_DEFINED + +#include "include/core/SkData.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSpan.h" +#include "include/core/SkTypes.h" + +class SkFontMgr; + +/** Create a custom font manager which wraps a collection of SkData-stored fonts. + * This font manager uses FreeType for rendering. + */ +SK_API sk_sp SkFontMgr_New_Custom_Data(SkSpan>); + +#endif // SkFontMgr_data_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h index 73210bc9a546b..99a1813456f09 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h @@ -13,9 +13,9 @@ #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" #include "include/ports/SkRemotableFontMgr.h" -#include "include/private/SkMutex.h" -#include "include/private/SkOnce.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkTArray.h" class SkData; class SkFontStyle; @@ -34,18 +34,18 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { protected: int onCountFamilies() const override; void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onCreateStyleSet(int index) const override; + sk_sp onCreateStyleSet(int index) const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkTypeface* onMatchFamilyStyle(const char familyName[], - const SkFontStyle& fontStyle) const override; + sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle& fontStyle) const override; - SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], - const SkFontStyle&, - const char* bcp47[], - int bcp47Count, - SkUnichar character) const override; + sk_sp onMatchFamilyStyleCharacter(const char familyName[], + const SkFontStyle&, + const char* bcp47[], + int bcp47Count, + SkUnichar character) const override; sk_sp onMakeFromStreamIndex(std::unique_ptr, int ttcIndex) const override; sk_sp onMakeFromStreamArgs(std::unique_ptr stream, @@ -55,7 +55,7 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { sk_sp onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override; private: - SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const; + sk_sp createTypefaceFromFontId(const SkFontIdentity& fontId) const; sk_sp fImpl; sk_sp fProxy; @@ -93,7 +93,7 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { * typefaces with that data id. By storing the index next to the typeface, * this data cache also acts as a typeface cache. */ - mutable SkTArray fDataCache; + mutable skia_private::TArray fDataCache; mutable SkMutex fDataCacheMutex; friend class SkStyleSet_Indirect; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h index 8017b77cd9a76..eacb6bde9c540 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h @@ -11,7 +11,7 @@ #include "include/core/SkFontStyle.h" #include "include/core/SkRefCnt.h" #include "include/core/SkTypes.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" class SkDataTable; class SkStreamAsset; @@ -48,7 +48,7 @@ class SK_API SkRemotableFontIdentitySet : public SkRefCnt { friend SkRemotableFontIdentitySet* sk_remotable_font_identity_set_new(); int fCount; - SkAutoTArray fData; + skia_private::AutoTArray fData; using INHERITED = SkRefCnt; }; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h index 8437e7a5143ac..0f0d21ad2a67c 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h @@ -8,6 +8,7 @@ #ifndef SkTypeface_win_DEFINED #define SkTypeface_win_DEFINED +#include "include/core/SkRefCnt.h" #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" @@ -26,7 +27,7 @@ typedef LOGFONTA LOGFONT; * corresponding typeface for the specified logfont. The caller is responsible * for calling unref() when it is finished. */ -SK_API SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT&); +SK_API sk_sp SkCreateTypefaceFromLOGFONT(const LOGFONT&); /** * Copy the LOGFONT associated with this typeface into the lf parameter. Note diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h index 235649feec3e3..e703b622bf363 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h @@ -10,17 +10,22 @@ #include "include/core/SkString.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" #include "include/private/SkOpts_spi.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkTLogic.h" #include #include +#include -class SkChecksum : SkNoncopyable { +class SkChecksum { public: + SkChecksum() = default; + // Make noncopyable + SkChecksum(const SkChecksum&) = delete; + SkChecksum& operator=(const SkChecksum&) = delete; + /** - * uint32_t -> uint32_t hash, useful for when you're about to trucate this hash but you + * uint32_t -> uint32_t hash, useful for when you're about to truncate this hash but you * suspect its low bits aren't well mixed. * * This is the Murmur3 finalizer. @@ -35,7 +40,7 @@ class SkChecksum : SkNoncopyable { } /** - * uint32_t -> uint32_t hash, useful for when you're about to trucate this hash but you + * uint32_t -> uint32_t hash, useful for when you're about to truncate this hash but you * suspect its low bits aren't well mixed. * * This version is 2-lines cheaper than Mix, but seems to be sufficient for the font cache. @@ -52,12 +57,14 @@ class SkChecksum : SkNoncopyable { // It should be both reasonably fast and high quality. struct SkGoodHash { template - std::enable_if_t operator()(const K& k) const { + std::enable_if_t::value && sizeof(K) == 4, uint32_t> + operator()(const K& k) const { return SkChecksum::Mix(*(const uint32_t*)&k); } template - std::enable_if_t operator()(const K& k) const { + std::enable_if_t::value && sizeof(K) != 4, uint32_t> + operator()(const K& k) const { return SkOpts::hash_fn(&k, sizeof(K), 0); } @@ -74,4 +81,22 @@ struct SkGoodHash { } }; +// The default hashing behavior in SkGoodHash requires the type to have a unique object +// representation (i.e. all bits in contribute to its identity so can be hashed directly). This is +// false when a struct has padding for alignment (which can be avoided by using +// SK_BEGIN|END_REQUIRE_DENSE) or if the struct has floating point members since there are multiple +// bit representations for NaN. +// +// Often Skia code has externally removed the possibility of NaN so the bit representation of a +// non-NaN float will still hash correctly. SkForceDirectHash produces the same as SkGoodHash +// for K's that do not satisfy std::has_unique_object_representation. It should be used sparingly +// and it's use may highlight design issues with the key's data that might warrant an explicitly +// implemented hash function. +template +struct SkForceDirectHash { + uint32_t operator()(const K& k) const { + return SkOpts::hash_fn(&k, sizeof(K), 0); + } +}; + #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h index 5761df2c0b5d4..1bef596a3628f 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h @@ -10,8 +10,7 @@ #include "include/core/SkColor.h" #include "include/core/SkColorPriv.h" -#include "include/private/SkTo.h" -#include "include/private/SkVx.h" +#include "include/private/base/SkTo.h" //////////////////////////////////////////////////////////////////////////////////////////// // Convert a 16bit pixel to a 32bit pixel @@ -374,30 +373,6 @@ static inline SkPMColor SkPixel4444ToPixel32(U16CPU c) { return d | (d << 4); } -static inline skvx::float4 swizzle_rb(const skvx::float4& x) { - return skvx::shuffle<2, 1, 0, 3>(x); -} - -static inline skvx::float4 swizzle_rb_if_bgra(const skvx::float4& x) { -#ifdef SK_PMCOLOR_IS_BGRA - return swizzle_rb(x); -#else - return x; -#endif -} - -static inline skvx::float4 Sk4f_fromL32(uint32_t px) { - return skvx::cast(skvx::byte4::Load(&px)) * (1 / 255.0f); -} - -static inline uint32_t Sk4f_toL32(const skvx::float4& px) { - uint32_t l32; - // For the expected positive color values, the +0.5 before the pin and cast effectively rounds - // to the nearest int without having to call round() or lrint(). - skvx::cast(pin(px * 255.f + 0.5f, skvx::float4(0.f), skvx::float4(255.f))).store(&l32); - return l32; -} - using SkPMColor4f = SkRGBA4f; constexpr SkPMColor4f SK_PMColor4fTRANSPARENT = { 0, 0, 0, 0 }; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h new file mode 100644 index 0000000000000..8cf511a10c265 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h @@ -0,0 +1,97 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkGainmapInfo_DEFINED +#define SkGainmapInfo_DEFINED + +#include "include/core/SkColor.h" + +/** + * Gainmap rendering parameters. Suppose our display has HDR to SDR ratio of H and we wish to + * display an image with gainmap on this display. Let B be the pixel value from the base image + * in a color space that has the primaries of the base image and a linear transfer function. Let + * G be the pixel value from the gainmap. Let D be the output pixel in the same color space as B. + * The value of D is computed as follows: + * + * First, let W be a weight parameter determing how much the gainmap will be applied. + * W = clamp((log(H) - log(fDisplayRatioSdr)) / + * (log(fDisplayRatioHdr) - log(fDisplayRatioSdr), 0, 1) + * + * Next, let L be the gainmap value in log space. We compute this from the value G that was + * sampled from the texture as follows: + * L = mix(log(fGainmapRatioMin), log(fGainmapRatioMax), pow(G, fGainmapGamma)) + * + * Finally, apply the gainmap to compute D, the displayed pixel. If the base image is SDR then + * compute: + * D = (B + fEpsilonSdr) * exp(L * W) - fEpsilonHdr + * If the base image is HDR then compute: + * D = (B + fEpsilonHdr) * exp(L * (W - 1)) - fEpsilonSdr + * + * In the above math, log() is a natural logarithm and exp() is natural exponentiation. Note, + * however, that the base used for the log() and exp() functions does not affect the results of + * the computation (it cancels out, as long as the same base is used throughout). + */ +struct SkGainmapInfo { + /** + * Parameters for converting the gainmap from its image encoding to log space. These are + * specified per color channel. The alpha value is unused. + */ + SkColor4f fGainmapRatioMin = {1.f, 1.f, 1.f, 1.0}; + SkColor4f fGainmapRatioMax = {2.f, 2.f, 2.f, 1.0}; + SkColor4f fGainmapGamma = {1.f, 1.f, 1.f, 1.f}; + + /** + * Parameters sometimes used in gainmap computation to avoid numerical instability. + */ + SkColor4f fEpsilonSdr = {0.f, 0.f, 0.f, 1.0}; + SkColor4f fEpsilonHdr = {0.f, 0.f, 0.f, 1.0}; + + /** + * If the output display's HDR to SDR ratio is less or equal than fDisplayRatioSdr then the SDR + * rendition is displayed. If the output display's HDR to SDR ratio is greater or equal than + * fDisplayRatioHdr then the HDR rendition is displayed. If the output display's HDR to SDR + * ratio is between these values then an interpolation between the two is displayed using the + * math above. + */ + float fDisplayRatioSdr = 1.f; + float fDisplayRatioHdr = 2.f; + + /** + * Whether the base image is the SDR image or the HDR image. + */ + enum class BaseImageType { + kSDR, + kHDR, + }; + BaseImageType fBaseImageType = BaseImageType::kSDR; + + inline bool operator==(const SkGainmapInfo& other) { + return fGainmapRatioMin == other.fGainmapRatioMin && + fGainmapRatioMax == other.fGainmapRatioMax && fGainmapGamma == other.fGainmapGamma && + fEpsilonSdr == other.fEpsilonSdr && fEpsilonHdr == other.fEpsilonHdr && + fDisplayRatioSdr == other.fDisplayRatioSdr && + fDisplayRatioHdr == other.fDisplayRatioHdr && fBaseImageType == other.fBaseImageType; + } + inline bool operator!=(const SkGainmapInfo& other) { return !(*this == other); } + + // TODO(ccameron): Remove these parameters once we are certain they are not used in Android. + enum class Type { + kUnknown, + kMultiPicture, + kJpegR_Linear, + kJpegR_HLG, + kJpegR_PQ, + kHDRGM, + }; + SkColor4f fLogRatioMin = {0.f, 0.f, 0.f, 1.0}; + SkColor4f fLogRatioMax = {1.f, 1.f, 1.f, 1.0}; + float fHdrRatioMin = 1.f; + float fHdrRatioMax = 50.f; + Type fType = Type::kUnknown; +}; + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h new file mode 100644 index 0000000000000..f490ab96a4cfc --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h @@ -0,0 +1,53 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkGainmapShader_DEFINED +#define SkGainmapShader_DEFINED + +#include "include/core/SkRefCnt.h" + +class SkColorSpace; +class SkShader; +class SkImage; +struct SkGainmapInfo; +struct SkRect; +struct SkSamplingOptions; + +/** + * A gainmap shader will apply a gainmap to an base image using the math described alongside the + * definition of SkGainmapInfo. + */ +class SK_API SkGainmapShader { +public: + /** + * Make a gainmap shader. + * + * When sampling the base image baseImage, the rectangle baseRect will be sampled to map to + * the rectangle dstRect. Sampling will be done according to baseSamplingOptions. + * + * When sampling the gainmap image gainmapImage, the rectangle gainmapRect will be sampled to + * map to the rectangle dstRect. Sampling will be done according to gainmapSamplingOptions. + * + * The gainmap will be applied according to the HDR to SDR ratio specified in dstHdrRatio. + * + * This shader must know the color space of the canvas that it will be rendered to. This color + * space must be specified in dstColorSpace. + * TODO(ccameron): Remove the need for dstColorSpace. + */ + static sk_sp Make(const sk_sp& baseImage, + const SkRect& baseRect, + const SkSamplingOptions& baseSamplingOptions, + const sk_sp& gainmapImage, + const SkRect& gainmapRect, + const SkSamplingOptions& gainmapSamplingOptions, + const SkGainmapInfo& gainmapInfo, + const SkRect& dstRect, + float dstHdrRatio, + sk_sp dstColorSpace); +}; + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h deleted file mode 100644 index 0888869607db7..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkHalf_DEFINED -#define SkHalf_DEFINED - -#include "include/core/SkTypes.h" -#include "include/private/SkVx.h" - -// 16-bit floating point value -// format is 1 bit sign, 5 bits exponent, 10 bits mantissa -// only used for storage -typedef uint16_t SkHalf; - -static constexpr uint16_t SK_HalfMin = 0x0400; // 2^-14 (minimum positive normal value) -static constexpr uint16_t SK_HalfMax = 0x7bff; // 65504 -static constexpr uint16_t SK_HalfEpsilon = 0x1400; // 2^-10 -static constexpr uint16_t SK_Half1 = 0x3C00; // 1 - -// convert between half and single precision floating point -float SkHalfToFloat(SkHalf h); -SkHalf SkFloatToHalf(float f); - -// Convert between half and single precision floating point, -// assuming inputs and outputs are both finite, and may -// flush values which would be denormal half floats to zero. -static inline skvx::float4 SkHalfToFloat_finite_ftz(uint64_t rgba) { - return skvx::from_half(skvx::half4::Load(&rgba)); -} -static inline skvx::half4 SkFloatToHalf_finite_ftz(const skvx::float4& c) { - return skvx::to_half(c); -} - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h index f7a5900e0e1ff..8ebb6ca18e53f 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h @@ -9,8 +9,9 @@ #define SkIDChangeListener_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkThreadAnnotations.h" #include @@ -65,7 +66,7 @@ class SkIDChangeListener : public SkRefCnt { private: mutable SkMutex fMutex; - SkTDArray fListeners SK_GUARDED_BY(fMutex); // pointers are reffed + skia_private::STArray<1, sk_sp> fListeners SK_GUARDED_BY(fMutex); }; private: diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h deleted file mode 100644 index 70b9d715f06b6..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkImageInfoPriv_DEFINED -#define SkImageInfoPriv_DEFINED - -#include "include/core/SkColor.h" -#include "include/core/SkImageInfo.h" - -static inline uint32_t SkColorTypeChannelFlags(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: return 0; - case kAlpha_8_SkColorType: return kAlpha_SkColorChannelFlag; - case kRGB_565_SkColorType: return kRGB_SkColorChannelFlags; - case kARGB_4444_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGB_888x_SkColorType: return kRGB_SkColorChannelFlags; - case kBGRA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_1010102_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGB_101010x_SkColorType: return kRGB_SkColorChannelFlags; - case kBGRA_1010102_SkColorType: return kRGBA_SkColorChannelFlags; - case kBGR_101010x_SkColorType: return kRGB_SkColorChannelFlags; - case kGray_8_SkColorType: return kGray_SkColorChannelFlag; - case kRGBA_F16Norm_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_F16_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_F32_SkColorType: return kRGBA_SkColorChannelFlags; - case kR8G8_unorm_SkColorType: return kRG_SkColorChannelFlags; - case kA16_unorm_SkColorType: return kAlpha_SkColorChannelFlag; - case kR16G16_unorm_SkColorType: return kRG_SkColorChannelFlags; - case kA16_float_SkColorType: return kAlpha_SkColorChannelFlag; - case kR16G16_float_SkColorType: return kRG_SkColorChannelFlags; - case kR16G16B16A16_unorm_SkColorType: return kRGBA_SkColorChannelFlags; - case kSRGBA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kR8_unorm_SkColorType: return kRed_SkColorChannelFlag; - } - SkUNREACHABLE; -} - -static inline bool SkColorTypeIsAlphaOnly(SkColorType ct) { - return SkColorTypeChannelFlags(ct) == kAlpha_SkColorChannelFlag; -} - -static inline bool SkAlphaTypeIsValid(unsigned value) { - return value <= kLastEnum_SkAlphaType; -} - -static int SkColorTypeShiftPerPixel(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: return 0; - case kAlpha_8_SkColorType: return 0; - case kRGB_565_SkColorType: return 1; - case kARGB_4444_SkColorType: return 1; - case kRGBA_8888_SkColorType: return 2; - case kRGB_888x_SkColorType: return 2; - case kBGRA_8888_SkColorType: return 2; - case kRGBA_1010102_SkColorType: return 2; - case kRGB_101010x_SkColorType: return 2; - case kBGRA_1010102_SkColorType: return 2; - case kBGR_101010x_SkColorType: return 2; - case kGray_8_SkColorType: return 0; - case kRGBA_F16Norm_SkColorType: return 3; - case kRGBA_F16_SkColorType: return 3; - case kRGBA_F32_SkColorType: return 4; - case kR8G8_unorm_SkColorType: return 1; - case kA16_unorm_SkColorType: return 1; - case kR16G16_unorm_SkColorType: return 2; - case kA16_float_SkColorType: return 1; - case kR16G16_float_SkColorType: return 2; - case kR16G16B16A16_unorm_SkColorType: return 3; - case kSRGBA_8888_SkColorType: return 2; - case kR8_unorm_SkColorType: return 0; - } - SkUNREACHABLE; -} - -static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { - return (size_t)(width * SkColorTypeBytesPerPixel(ct)); -} - -static inline bool SkColorTypeIsValid(unsigned value) { - return value <= kLastEnum_SkColorType; -} - -static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) { - if (kUnknown_SkColorType == ct) { - return 0; - } - return (size_t)y * rowBytes + ((size_t)x << SkColorTypeShiftPerPixel(ct)); -} - -static inline bool SkColorTypeIsNormalized(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: - case kAlpha_8_SkColorType: - case kRGB_565_SkColorType: - case kARGB_4444_SkColorType: - case kRGBA_8888_SkColorType: - case kRGB_888x_SkColorType: - case kBGRA_8888_SkColorType: - case kRGBA_1010102_SkColorType: - case kRGB_101010x_SkColorType: - case kBGRA_1010102_SkColorType: - case kBGR_101010x_SkColorType: - case kGray_8_SkColorType: - case kRGBA_F16Norm_SkColorType: - case kR8G8_unorm_SkColorType: - case kA16_unorm_SkColorType: - case kA16_float_SkColorType: /*subtle... alpha is always [0,1]*/ - case kR16G16_unorm_SkColorType: - case kR16G16B16A16_unorm_SkColorType: - case kSRGBA_8888_SkColorType: - case kR8_unorm_SkColorType: - return true; - - case kRGBA_F16_SkColorType: - case kRGBA_F32_SkColorType: - case kR16G16_float_SkColorType: - return false; - } - SkUNREACHABLE; -} - -static inline int SkColorTypeMaxBitsPerChannel(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: - return 0; - - case kARGB_4444_SkColorType: - return 4; - - case kRGB_565_SkColorType: - return 6; - - case kAlpha_8_SkColorType: - case kRGBA_8888_SkColorType: - case kRGB_888x_SkColorType: - case kBGRA_8888_SkColorType: - case kGray_8_SkColorType: - case kR8G8_unorm_SkColorType: - case kSRGBA_8888_SkColorType: - case kR8_unorm_SkColorType: - return 8; - - case kRGBA_1010102_SkColorType: - case kRGB_101010x_SkColorType: - case kBGRA_1010102_SkColorType: - case kBGR_101010x_SkColorType: - return 10; - - case kRGBA_F16Norm_SkColorType: - case kA16_unorm_SkColorType: - case kA16_float_SkColorType: - case kR16G16_unorm_SkColorType: - case kR16G16B16A16_unorm_SkColorType: - case kRGBA_F16_SkColorType: - case kR16G16_float_SkColorType: - return 16; - - case kRGBA_F32_SkColorType: - return 32; - } - SkUNREACHABLE; -} - -/** - * Returns true if |info| contains a valid colorType and alphaType. - */ -static inline bool SkColorInfoIsValid(const SkColorInfo& info) { - return info.colorType() != kUnknown_SkColorType && info.alphaType() != kUnknown_SkAlphaType; -} - -/** - * Returns true if |info| contains a valid combination of width, height and colorInfo. - */ -static inline bool SkImageInfoIsValid(const SkImageInfo& info) { - if (info.width() <= 0 || info.height() <= 0) { - return false; - } - - const int kMaxDimension = SK_MaxS32 >> 2; - if (info.width() > kMaxDimension || info.height() > kMaxDimension) { - return false; - } - - return SkColorInfoIsValid(info.colorInfo()); -} - -/** - * Returns true if Skia has defined a pixel conversion from the |src| to the |dst|. - * Returns false otherwise. - */ -static inline bool SkImageInfoValidConversion(const SkImageInfo& dst, const SkImageInfo& src) { - return SkImageInfoIsValid(dst) && SkImageInfoIsValid(src); -} -#endif // SkImageInfoPriv_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h new file mode 100644 index 0000000000000..756de78b23101 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h @@ -0,0 +1,71 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkJpegGainmapEncoder_DEFINED +#define SkJpegGainmapEncoder_DEFINED + +#include "include/encode/SkJpegEncoder.h" + +class SkPixmap; +class SkWStream; +struct SkGainmapInfo; + +class SK_API SkJpegGainmapEncoder { +public: + /** + * Encode a JpegR image to |dst|. + * + * The base image is specified by |base|, and |baseOptions| controls the encoding behavior for + * the base image. + * + * The gainmap image is specified by |gainmap|, and |gainmapOptions| controls the encoding + * behavior for the gainmap image. + * + * The rendering behavior of the gainmap image is provided in |gainmapInfo|. Not all gainmap + * based images are compatible with JpegR. If the image is not compatible with JpegR, then + * convert the gainmap to a format that is capable with JpegR. This conversion may result in + * less precise quantization of the gainmap image. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ + static bool EncodeJpegR(SkWStream* dst, + const SkPixmap& base, + const SkJpegEncoder::Options& baseOptions, + const SkPixmap& gainmap, + const SkJpegEncoder::Options& gainmapOptions, + const SkGainmapInfo& gainmapInfo); + + /** + * Encode an HDRGM image to |dst|. + * + * The base image is specified by |base|, and |baseOptions| controls the encoding behavior for + * the base image. + * + * The gainmap image is specified by |gainmap|, and |gainmapOptions| controls the encoding + * behavior for the gainmap image. + * + * The rendering behavior of the gainmap image is provided in |gainmapInfo|. + * + * If |baseOptions| or |gainmapOptions| specify XMP metadata, then that metadata will be + * overwritten. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ + static bool EncodeHDRGM(SkWStream* dst, + const SkPixmap& base, + const SkJpegEncoder::Options& baseOptions, + const SkPixmap& gainmap, + const SkJpegEncoder::Options& gainmapOptions, + const SkGainmapInfo& gainmapInfo); + + /** + * Write a Multi Picture Format containing the |imageCount| images specified by |images|. + */ + static bool MakeMPF(SkWStream* dst, const SkData** images, size_t imageCount); +}; + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h new file mode 100644 index 0000000000000..0b8f6ce1f7577 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h @@ -0,0 +1,61 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkJpegMetadataDecoder_DEFINED +#define SkJpegMetadataDecoder_DEFINED + +#include "include/core/SkData.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +#include +#include + +struct SkGainmapInfo; + +/** + * An interface that can be used to extract metadata from an encoded JPEG file. + * TODO(https://crbug.com/1404000): Add interface for ICC profile and EXIF extraction. + */ +class SK_API SkJpegMetadataDecoder { +public: + SkJpegMetadataDecoder() {} + virtual ~SkJpegMetadataDecoder() {} + + SkJpegMetadataDecoder(const SkJpegMetadataDecoder&) = delete; + SkJpegMetadataDecoder& operator=(const SkJpegMetadataDecoder&) = delete; + + /** + * A segment from a JPEG file. This is usually populated from a jpeg_marker_struct. + */ + struct SK_API Segment { + Segment(uint8_t marker, sk_sp data) : fMarker(marker), fData(std::move(data)) {} + + // The segment's marker. + uint8_t fMarker = 0; + + // The segment's parameters (not including the marker and parameter length). + sk_sp fData; + }; + + /** + * Create metadata for the specified segments from a JPEG file's header (defined as all segments + * before the first StartOfScan). This may return nullptr. + */ + static std::unique_ptr Make(std::vector headerSegments); + + /** + * Given a JPEG encoded image |baseImageData|, return in |outGainmapImageData| the JPEG encoded + * gainmap image and return in |outGainmapInfo| its gainmap rendering parameters. Return true if + * both output variables were successfully populated, otherwise return false. + */ + virtual bool findGainmapImage(sk_sp baseImageData, + sk_sp& outGainmapImagedata, + SkGainmapInfo& outGainmapInfo) = 0; +}; + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h index e57dc1433ff50..6e888b77c84c3 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h @@ -8,7 +8,9 @@ #ifndef SkOpts_spi_DEFINED #define SkOpts_spi_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" + +#include // These are exposed as SK_SPI (e.g. SkParagraph), the rest of SkOpts is // declared in src/core diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h index e72651dce7842..c0e0f08aa1bd9 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h @@ -8,36 +8,25 @@ #ifndef SkPathRef_DEFINED #define SkPathRef_DEFINED -#include "include/core/SkMatrix.h" #include "include/core/SkPoint.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" #include "include/private/SkIDChangeListener.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" -#include "include/private/SkTemplates.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkTo.h" #include -#include +#include +#include #include +#include -class SkRBuffer; -class SkWBuffer; +class SkMatrix; class SkRRect; -enum class SkPathConvexity { - kConvex, - kConcave, - kUnknown, -}; - -enum class SkPathFirstDirection { - kCW, // == SkPathDirection::kCW - kCCW, // == SkPathDirection::kCCW - kUnknown, -}; - // These are computed from a stream of verbs struct SkPathVerbAnalysis { bool valid; @@ -64,7 +53,13 @@ SkPathVerbAnalysis sk_path_analyze_verbs(const uint8_t verbs[], int count); class SK_API SkPathRef final : public SkNVRefCnt { public: - SkPathRef(SkTDArray points, SkTDArray verbs, SkTDArray weights, + // See https://bugs.chromium.org/p/skia/issues/detail?id=13817 for how these sizes were + // determined. + using PointsArray = skia_private::STArray<4, SkPoint>; + using VerbsArray = skia_private::STArray<4, uint8_t>; + using ConicWeightsArray = skia_private::STArray<2, SkScalar>; + + SkPathRef(PointsArray points, VerbsArray verbs, ConicWeightsArray weights, unsigned segmentMask) : fPoints(std::move(points)) , fVerbs(std::move(verbs)) @@ -320,24 +315,15 @@ class SK_API SkPathRef final : public SkNVRefCnt { bool operator== (const SkPathRef& ref) const; - /** - * Writes the path points and verbs to a buffer. - */ - void writeToBuffer(SkWBuffer* buffer) const; - - /** - * Gets the number of bytes that would be written in writeBuffer() - */ - uint32_t writeSize() const; - void interpolate(const SkPathRef& ending, SkScalar weight, SkPathRef* out) const; /** * Gets an ID that uniquely identifies the contents of the path ref. If two path refs have the * same ID then they have the same verbs and points. However, two path refs may have the same * contents but different genIDs. + * skbug.com/1762 for background on why fillType is necessary (for now). */ - uint32_t genID() const; + uint32_t genID(uint8_t fillType) const; void addGenIDChangeListener(sk_sp); // Threadsafe. int genIDChangeListenerCount(); // Threadsafe @@ -346,6 +332,15 @@ class SK_API SkPathRef final : public SkNVRefCnt { bool isValid() const; SkDEBUGCODE(void validate() const { SkASSERT(this->isValid()); } ) + /** + * Resets this SkPathRef to a clean state. + */ + void reset(); + + bool isInitialEmptyPathRef() const { + return fGenerationID == kEmptyGenID; + } + private: enum SerializationOffsets { kLegacyRRectOrOvalStartIdx_SerializationShift = 28, // requires 3 bits, ignored. @@ -356,7 +351,7 @@ class SK_API SkPathRef final : public SkNVRefCnt { kSegmentMask_SerializationShift = 0 // requires 4 bits (deprecated) }; - SkPathRef() { + SkPathRef(int numVerbs = 0, int numPoints = 0) { fBoundsIsDirty = true; // this also invalidates fIsFinite fGenerationID = kEmptyGenID; fSegmentMask = 0; @@ -365,6 +360,10 @@ class SK_API SkPathRef final : public SkNVRefCnt { // The next two values don't matter unless fIsOval or fIsRRect are true. fRRectOrOvalIsCCW = false; fRRectOrOvalStartIdx = 0xAC; + if (numPoints > 0) + fPoints.reserve_back(numPoints); + if (numVerbs > 0) + fVerbs.reserve_back(numVerbs); SkDEBUGCODE(fEditorsAttached.store(0);) SkDEBUGCODE(this->validate();) } @@ -397,15 +396,20 @@ class SK_API SkPathRef final : public SkNVRefCnt { /** Makes additional room but does not change the counts or change the genID */ void incReserve(int additionalVerbs, int additionalPoints) { SkDEBUGCODE(this->validate();) - fPoints.reserve(fPoints.size() + additionalPoints); - fVerbs.reserve(fVerbs.size() + additionalVerbs); + // Use reserve() so that if there is not enough space, the array will grow with some + // additional space. This ensures repeated calls to grow won't always allocate. + if (additionalPoints > 0) + fPoints.reserve(fPoints.size() + additionalPoints); + if (additionalVerbs > 0) + fVerbs.reserve(fVerbs.size() + additionalVerbs); SkDEBUGCODE(this->validate();) } - /** Resets the path ref with verbCount verbs and pointCount points, all uninitialized. Also - * allocates space for reserveVerb additional verbs and reservePoints additional points.*/ - void resetToSize(int verbCount, int pointCount, int conicCount, - int reserveVerbs = 0, int reservePoints = 0) { + /** + * Resets all state except that of the verbs, points, and conic-weights. + * Intended to be called from other functions that reset state. + */ + void commonReset() { SkDEBUGCODE(this->validate();) this->callGenIDChangeListeners(); fBoundsIsDirty = true; // this also invalidates fIsFinite @@ -414,12 +418,25 @@ class SK_API SkPathRef final : public SkNVRefCnt { fSegmentMask = 0; fIsOval = false; fIsRRect = false; + } - fPoints.reserve(pointCount + reservePoints); - fPoints.resize(pointCount); - fVerbs.reserve(verbCount + reserveVerbs); - fVerbs.resize(verbCount); - fConicWeights.resize(conicCount); + /** Resets the path ref with verbCount verbs and pointCount points, all uninitialized. Also + * allocates space for reserveVerb additional verbs and reservePoints additional points.*/ + void resetToSize(int verbCount, int pointCount, int conicCount, + int reserveVerbs = 0, int reservePoints = 0) { + commonReset(); + // Use reserve_back() so the arrays are sized to exactly fit the data. + const int pointDelta = pointCount + reservePoints - fPoints.size(); + if (pointDelta > 0) { + fPoints.reserve_back(pointDelta); + } + fPoints.resize_back(pointCount); + const int verbDelta = verbCount + reserveVerbs - fVerbs.size(); + if (verbDelta > 0) { + fVerbs.reserve_back(verbDelta); + } + fVerbs.resize_back(verbCount); + fConicWeights.resize_back(conicCount); SkDEBUGCODE(this->validate();) } @@ -489,9 +506,9 @@ class SK_API SkPathRef final : public SkNVRefCnt { mutable SkRect fBounds; - SkTDArray fPoints; - SkTDArray fVerbs; - SkTDArray fConicWeights; + PointsArray fPoints; + VerbsArray fVerbs; + ConicWeightsArray fConicWeights; enum { kEmptyGenID = 1, // GenID reserved for path ref with zero points and zero verbs. diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h index 6e50a5b262594..058b231b138a3 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h @@ -11,7 +11,7 @@ #include #include "include/core/SkTypes.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" using SKSL_INT = int64_t; using SKSL_FLOAT = float; @@ -21,17 +21,17 @@ namespace SkSL { class Expression; class Statement; -using ComponentArray = SkSTArray<4, int8_t>; // for Swizzles +using ComponentArray = skia_private::STArray<4, int8_t>; // for Swizzles -class ExpressionArray : public SkSTArray<2, std::unique_ptr> { +class ExpressionArray : public skia_private::STArray<2, std::unique_ptr> { public: - using SkSTArray::SkSTArray; + using STArray::STArray; /** Returns a new ExpressionArray containing a clone of every element. */ ExpressionArray clone() const; }; -using StatementArray = SkSTArray<2, std::unique_ptr>; +using StatementArray = skia_private::STArray<2, std::unique_ptr>; // Functions larger than this (measured in IR nodes) will not be inlined. This growth factor // accounts for the number of calls being inlined--i.e., a function called five times (that is, with diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h deleted file mode 100644 index c11a56614c42b..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_IRNODE -#define SKSL_IRNODE - -#include "include/private/SkSLString.h" -#include "include/private/SkTArray.h" -#include "include/sksl/SkSLPosition.h" -#include "src/sksl/SkSLLexer.h" -#include "src/sksl/SkSLModifiersPool.h" -#include "src/sksl/SkSLPool.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Expression; -class FunctionDeclaration; -class FunctionDefinition; -class Statement; -class Symbol; -class SymbolTable; -class Type; -class Variable; -class VariableReference; -enum class VariableRefKind : int8_t; -enum class VariableStorage : int8_t; - -/** - * Represents a node in the intermediate representation (IR) tree. The IR is a fully-resolved - * version of the program (all types determined, everything validated), ready for code generation. - */ -class IRNode : public Poolable { -public: - virtual ~IRNode() {} - - virtual std::string description() const = 0; - - // No copy construction or assignment - IRNode(const IRNode&) = delete; - IRNode& operator=(const IRNode&) = delete; - - // position of this element within the program being compiled, for error reporting purposes - Position fPosition; - -protected: - IRNode(Position position, int kind) - : fPosition(position) - , fKind(kind) {} - - int fKind; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h deleted file mode 100644 index 1b00f0e7c67ed..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_LAYOUT -#define SKSL_LAYOUT - -#include "include/private/SkSLString.h" - -namespace SkSL { - -/** - * Represents a layout block appearing before a variable declaration, as in: - * - * layout (location = 0) int x; - */ -struct Layout { - enum Flag { - kOriginUpperLeft_Flag = 1 << 0, - kPushConstant_Flag = 1 << 1, - kBlendSupportAllEquations_Flag = 1 << 2, - kColor_Flag = 1 << 3, - - // These flags indicate if the qualifier appeared, regardless of the accompanying value. - kLocation_Flag = 1 << 4, - kOffset_Flag = 1 << 5, - kBinding_Flag = 1 << 6, - kIndex_Flag = 1 << 7, - kSet_Flag = 1 << 8, - kBuiltin_Flag = 1 << 9, - kInputAttachmentIndex_Flag = 1 << 10, - }; - - Layout(int flags, int location, int offset, int binding, int index, int set, int builtin, - int inputAttachmentIndex) - : fFlags(flags) - , fLocation(location) - , fOffset(offset) - , fBinding(binding) - , fIndex(index) - , fSet(set) - , fBuiltin(builtin) - , fInputAttachmentIndex(inputAttachmentIndex) {} - - Layout() - : fFlags(0) - , fLocation(-1) - , fOffset(-1) - , fBinding(-1) - , fIndex(-1) - , fSet(-1) - , fBuiltin(-1) - , fInputAttachmentIndex(-1) {} - - static Layout builtin(int builtin) { - Layout result; - result.fBuiltin = builtin; - return result; - } - - std::string description() const { - std::string result; - auto separator = [firstSeparator = true]() mutable -> std::string { - if (firstSeparator) { - firstSeparator = false; - return ""; - } else { - return ", "; - }}; - if (fLocation >= 0) { - result += separator() + "location = " + std::to_string(fLocation); - } - if (fOffset >= 0) { - result += separator() + "offset = " + std::to_string(fOffset); - } - if (fBinding >= 0) { - result += separator() + "binding = " + std::to_string(fBinding); - } - if (fIndex >= 0) { - result += separator() + "index = " + std::to_string(fIndex); - } - if (fSet >= 0) { - result += separator() + "set = " + std::to_string(fSet); - } - if (fBuiltin >= 0) { - result += separator() + "builtin = " + std::to_string(fBuiltin); - } - if (fInputAttachmentIndex >= 0) { - result += separator() + "input_attachment_index = " + - std::to_string(fInputAttachmentIndex); - } - if (fFlags & kOriginUpperLeft_Flag) { - result += separator() + "origin_upper_left"; - } - if (fFlags & kBlendSupportAllEquations_Flag) { - result += separator() + "blend_support_all_equations"; - } - if (fFlags & kPushConstant_Flag) { - result += separator() + "push_constant"; - } - if (fFlags & kColor_Flag) { - result += separator() + "color"; - } - if (result.size() > 0) { - result = "layout (" + result + ")"; - } - return result; - } - - bool operator==(const Layout& other) const { - return fFlags == other.fFlags && - fLocation == other.fLocation && - fOffset == other.fOffset && - fBinding == other.fBinding && - fIndex == other.fIndex && - fSet == other.fSet && - fBuiltin == other.fBuiltin && - fInputAttachmentIndex == other.fInputAttachmentIndex; - } - - bool operator!=(const Layout& other) const { - return !(*this == other); - } - - int fFlags; - int fLocation; - int fOffset; - int fBinding; - int fIndex; - int fSet; - // builtin comes from SPIR-V and identifies which particular builtin value this object - // represents. - int fBuiltin; - // input_attachment_index comes from Vulkan/SPIR-V to connect a shader variable to the a - // corresponding attachment on the subpass in which the shader is being used. - int fInputAttachmentIndex; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h deleted file mode 100644 index 732810b7da71c..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_MODIFIERS -#define SKSL_MODIFIERS - -#include "include/private/SkSLLayout.h" - -#include -#include -#include - -namespace SkSL { - -class Context; -class Position; - -/** - * A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration. - */ -struct Modifiers { - /** - * OpenGL requires modifiers to be in a strict order: - * - invariant-qualifier: (invariant) - * - interpolation-qualifier: flat, noperspective, (smooth) - * - storage-qualifier: const, uniform - * - parameter-qualifier: in, out, inout - * - precision-qualifier: highp, mediump, lowp - * - * SkSL does not have `invariant` or `smooth`. - */ - - enum Flag { - kNo_Flag = 0, - // Real GLSL modifiers - kFlat_Flag = 1 << 0, - kNoPerspective_Flag = 1 << 1, - kConst_Flag = 1 << 2, - kUniform_Flag = 1 << 3, - kIn_Flag = 1 << 4, - kOut_Flag = 1 << 5, - kHighp_Flag = 1 << 6, - kMediump_Flag = 1 << 7, - kLowp_Flag = 1 << 8, - kReadOnly_Flag = 1 << 9, - kWriteOnly_Flag = 1 << 10, - kBuffer_Flag = 1 << 11, - // We use the Metal name for this one (corresponds to the GLSL 'shared' modifier) - kThreadgroup_Flag = 1 << 12, - // SkSL extensions, not present in GLSL - kExport_Flag = 1 << 13, - kES3_Flag = 1 << 14, - kPure_Flag = 1 << 15, - kInline_Flag = 1 << 16, - kNoInline_Flag = 1 << 17, - }; - - Modifiers() - : fLayout(Layout()) - , fFlags(0) {} - - Modifiers(const Layout& layout, int flags) - : fLayout(layout) - , fFlags(flags) {} - - std::string description() const { - return fLayout.description() + DescribeFlags(fFlags) + " "; - } - - static std::string DescribeFlags(int flags) { - // SkSL extensions - std::string result; - if (flags & kExport_Flag) { - result += "$export "; - } - if (flags & kES3_Flag) { - result += "$es3 "; - } - if (flags & kPure_Flag) { - result += "$pure "; - } - if (flags & kInline_Flag) { - result += "inline "; - } - if (flags & kNoInline_Flag) { - result += "noinline "; - } - - // Real GLSL qualifiers (must be specified in order in GLSL 4.1 and below) - if (flags & kFlat_Flag) { - result += "flat "; - } - if (flags & kNoPerspective_Flag) { - result += "noperspective "; - } - if (flags & kConst_Flag) { - result += "const "; - } - if (flags & kUniform_Flag) { - result += "uniform "; - } - if ((flags & kIn_Flag) && (flags & kOut_Flag)) { - result += "inout "; - } else if (flags & kIn_Flag) { - result += "in "; - } else if (flags & kOut_Flag) { - result += "out "; - } - if (flags & kHighp_Flag) { - result += "highp "; - } - if (flags & kMediump_Flag) { - result += "mediump "; - } - if (flags & kLowp_Flag) { - result += "lowp "; - } - if (flags & kReadOnly_Flag) { - result += "readonly "; - } - if (flags & kWriteOnly_Flag) { - result += "writeonly "; - } - if (flags & kBuffer_Flag) { - result += "buffer "; - } - - // We're using a non-GLSL name for this one; the GLSL equivalent is "shared" - if (flags & kThreadgroup_Flag) { - result += "threadgroup "; - } - - if (!result.empty()) { - result.pop_back(); - } - return result; - } - - bool operator==(const Modifiers& other) const { - return fLayout == other.fLayout && fFlags == other.fFlags; - } - - bool operator!=(const Modifiers& other) const { - return !(*this == other); - } - - /** - * Verifies that only permitted modifiers and layout flags are included. Reports errors and - * returns false in the event of a violation. - */ - bool checkPermitted(const Context& context, - Position pos, - int permittedModifierFlags, - int permittedLayoutFlags) const; - - Layout fLayout; - int fFlags; -}; - -} // namespace SkSL - -namespace std { - -template <> -struct hash { - size_t operator()(const SkSL::Modifiers& key) const { - return (size_t) key.fFlags ^ ((size_t) key.fLayout.fFlags << 8) ^ - ((size_t) key.fLayout.fBuiltin << 16); - } -}; - -} // namespace std - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h deleted file mode 100644 index 8eb0a31aadab6..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_PROGRAMELEMENT -#define SKSL_PROGRAMELEMENT - -#include "include/private/SkSLIRNode.h" - -#include - -namespace SkSL { - -/** - * Represents a top-level element (e.g. function or global variable) in a program. - */ -class ProgramElement : public IRNode { -public: - enum class Kind { - kExtension = 0, - kFunction, - kFunctionPrototype, - kGlobalVar, - kInterfaceBlock, - kModifiers, - kStructDefinition, - - kFirst = kExtension, - kLast = kStructDefinition - }; - - ProgramElement(Position pos, Kind kind) - : INHERITED(pos, (int) kind) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - Kind kind() const { - return (Kind) fKind; - } - - /** - * Use is to check the type of a program element. - * e.g. replace `el.kind() == ProgramElement::Kind::kExtension` with `el.is()`. - */ - template - bool is() const { - return this->kind() == T::kProgramElementKind; - } - - /** - * Use as to downcast program elements. e.g. replace `(Extension&) el` with - * `el.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - - virtual std::unique_ptr clone() const = 0; - -private: - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h deleted file mode 100644 index c240cb7376e60..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSLProgramKind_DEFINED -#define SkSLProgramKind_DEFINED - -#include - -namespace SkSL { - -/** - * SkSL supports several different program kinds. - */ -enum class ProgramKind : int8_t { - kFragment, - kVertex, - kCompute, - kGraphiteFragment, - kGraphiteVertex, - kRuntimeColorFilter, // Runtime effect only suitable as SkColorFilter - kRuntimeShader, // " " " " " SkShader - kRuntimeBlender, // " " " " " SkBlender - kPrivateRuntimeShader, // Runtime shader with public restrictions lifted - kMeshVertex, // Vertex portion of a custom mesh - kMeshFragment, // Fragment " " " " " - kGeneric, -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h index a8d67a025a82d..39d9e258180e8 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h @@ -10,8 +10,6 @@ #include "include/core/SkTypes.h" -#include - namespace SkSL { /** @@ -77,8 +75,6 @@ class SampleUsage { bool isUniformMatrix() const { return fKind == Kind::kUniformMatrix; } bool isFragCoord() const { return fKind == Kind::kFragCoord; } - std::string constructor() const; - private: Kind fKind = Kind::kNone; bool fHasPerspective = false; // Only valid if fKind is kUniformMatrix diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h deleted file mode 100644 index 43a1fdc8f3757..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_STATEMENT -#define SKSL_STATEMENT - -#include "include/private/SkSLIRNode.h" -#include "include/private/SkSLSymbol.h" - -namespace SkSL { - -/** - * Abstract supertype of all statements. - */ -class Statement : public IRNode { -public: - enum Kind { - kBlock = (int) Symbol::Kind::kLast + 1, - kBreak, - kContinue, - kDiscard, - kDo, - kExpression, - kFor, - kIf, - kNop, - kReturn, - kSwitch, - kSwitchCase, - kVarDeclaration, - - kFirst = kBlock, - kLast = kVarDeclaration, - }; - - Statement(Position pos, Kind kind) - : INHERITED(pos, (int) kind) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - Kind kind() const { - return (Kind) fKind; - } - - /** - * Use is to check the type of a statement. - * e.g. replace `s.kind() == Statement::Kind::kReturn` with `s.is()`. - */ - template - bool is() const { - return this->fKind == T::kStatementKind; - } - - /** - * Use as to downcast statements. - * e.g. replace `(ReturnStatement&) s` with `s.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - - virtual bool isEmpty() const { - return false; - } - - virtual std::unique_ptr clone() const = 0; - -private: - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h deleted file mode 100644 index 4458a2f0f5b45..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_STRING -#define SKSL_STRING - -#include "include/core/SkTypes.h" -#include "include/private/SkSLDefines.h" - -#include -#include -#include - -namespace SkSL { - -bool stod(std::string_view s, SKSL_FLOAT* value); -bool stoi(std::string_view s, SKSL_INT* value); - -namespace String { - -std::string printf(const char* fmt, ...) SK_PRINTF_LIKE(1, 2); -void appendf(std::string* str, const char* fmt, ...) SK_PRINTF_LIKE(2, 3); -void vappendf(std::string* str, const char* fmt, va_list va) SK_PRINTF_LIKE(2, 0); - -} // namespace String -} // namespace SkSL - -namespace skstd { - -// We use a custom to_string(float|double) which ignores locale settings and writes `1.0` instead -// of `1.00000`. -std::string to_string(float value); -std::string to_string(double value); - -} // namespace skstd - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h deleted file mode 100644 index d7b40c8d11ae7..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_SYMBOL -#define SKSL_SYMBOL - -#include "include/private/SkSLIRNode.h" -#include "include/private/SkSLProgramElement.h" - -namespace SkSL { - -/** - * Represents a symboltable entry. - */ -class Symbol : public IRNode { -public: - enum class Kind { - kExternal = (int) ProgramElement::Kind::kLast + 1, - kField, - kFunctionDeclaration, - kType, - kVariable, - - kFirst = kExternal, - kLast = kVariable - }; - - Symbol(Position pos, Kind kind, std::string_view name, const Type* type = nullptr) - : INHERITED(pos, (int) kind) - , fName(name) - , fType(type) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - ~Symbol() override {} - - const Type& type() const { - SkASSERT(fType); - return *fType; - } - - Kind kind() const { - return (Kind) fKind; - } - - std::string_view name() const { - return fName; - } - - /** - * Don't call this directly--use SymbolTable::renameSymbol instead! - */ - void setName(std::string_view newName) { - fName = newName; - } - - /** - * Use is to check the type of a symbol. - * e.g. replace `sym.kind() == Symbol::Kind::kVariable` with `sym.is()`. - */ - template - bool is() const { - return this->kind() == T::kSymbolKind; - } - - /** - * Use as to downcast symbols. e.g. replace `(Variable&) sym` with `sym.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - -private: - std::string_view fName; - const Type* fType; - - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h deleted file mode 100644 index 144b28a4a3b3a..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSafe_math_DEFINED -#define SkSafe_math_DEFINED - -// This file protects against known bugs in ucrt\math.h. -// Namely, that header defines inline methods without marking them static, -// which makes it very easy to cause ODR violations and ensuing chaos. -// -// TODO: other headers? Here are some potential problem headers: -// $ grep -R __inline * | grep -v static | cut -f 1 -d: | sort | uniq -// corecrt.h -// corecrt_stdio_config.h -// ctype.h -// fenv.h -// locale.h -// malloc.h -// math.h -// tchar.h -// wchar.h -// I took a quick look through other headers outside math.h. -// Nothing looks anywhere near as likely to be used by Skia as math.h. - -#if defined(_MSC_VER) && !defined(_INC_MATH) - // Our strategy here is to simply inject "static" into the headers - // where it should have been written, just before __inline. - // - // Most inline-but-not-static methods in math.h are 32-bit only, - // but not all of them (see frexpf, hypothf, ldexpf...). So to - // be safe, 32- and 64-bit builds both get this treatment. - - #define __inline static __inline - #include - #undef __inline - - #if !defined(_INC_MATH) - #error Hmm. Looks like math.h has changed its header guards. - #endif - - #define INC_MATH_IS_SAFE_NOW - -#else - #include - -#endif - -#endif//SkSafe_math_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h index e1d5011681e5f..3816dc9dff022 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h @@ -9,7 +9,7 @@ #define SkSpinlock_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkThreadAnnotations.h" #include class SK_CAPABILITY("mutex") SkSpinlock { diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h deleted file mode 100644 index bf2f3da25eb60..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkStringView_DEFINED -#define SkStringView_DEFINED - -#include -#include - -namespace skstd { - -// C++20 additions -inline constexpr bool starts_with(std::string_view str, std::string_view prefix) { - if (prefix.length() > str.length()) { - return false; - } - return prefix.length() == 0 || !memcmp(str.data(), prefix.data(), prefix.length()); -} - -inline constexpr bool starts_with(std::string_view str, std::string_view::value_type c) { - return !str.empty() && str.front() == c; -} - -inline constexpr bool ends_with(std::string_view str, std::string_view suffix) { - if (suffix.length() > str.length()) { - return false; - } - return suffix.length() == 0 || !memcmp(str.data() + str.length() - suffix.length(), - suffix.data(), suffix.length()); -} - -inline constexpr bool ends_with(std::string_view str, std::string_view::value_type c) { - return !str.empty() && str.back() == c; -} - -// C++23 additions -inline constexpr bool contains(std::string_view str, std::string_view needle) { - return str.find(needle) != std::string_view::npos; -} - -inline constexpr bool contains(std::string_view str, std::string_view::value_type c) { - return str.find(c) != std::string_view::npos; -} - -} // namespace skstd - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h deleted file mode 100644 index 5082669c4f3d6..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h +++ /dev/null @@ -1,655 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkTArray_DEFINED -#define SkTArray_DEFINED - -#include "include/core/SkMath.h" -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkSafe32.h" -#include "include/private/SkTLogic.h" -#include "include/private/SkTemplates.h" -#include "include/private/SkTo.h" - -#include -#include -#include -#include -#include -#include - -/** SkTArray implements a typical, mostly std::vector-like array. - Each T will be default-initialized on allocation, and ~T will be called on destruction. - - MEM_MOVE controls the behavior when a T needs to be moved (e.g. when the array is resized) - - true: T will be bit-copied via memcpy. - - false: T will be moved via move-constructors. - - Modern implementations of std::vector will generally provide similar performance - characteristics when used with appropriate care. Consider using std::vector in new code. -*/ -template ::value> class SkTArray { -private: - enum ReallocType { kExactFit, kGrowing, kShrinking }; - -public: - using value_type = T; - - /** - * Creates an empty array with no initial storage - */ - SkTArray() { this->init(0); } - - /** - * Creates an empty array that will preallocate space for reserveCount - * elements. - */ - explicit SkTArray(int reserveCount) : SkTArray() { this->reserve_back(reserveCount); } - - /** - * Copies one array to another. The new array will be heap allocated. - */ - SkTArray(const SkTArray& that) - : SkTArray(that.fItemArray, that.fCount) {} - - SkTArray(SkTArray&& that) { - if (that.fOwnMemory) { - fItemArray = that.fItemArray; - fCount = that.fCount; - fAllocCount = that.fAllocCount; - fOwnMemory = true; - fReserved = that.fReserved; - - that.fItemArray = nullptr; - that.fCount = 0; - that.fAllocCount = 0; - that.fOwnMemory = true; - that.fReserved = false; - } else { - this->init(that.fCount); - that.move(fItemArray); - that.fCount = 0; - } - } - - /** - * Creates a SkTArray by copying contents of a standard C array. The new - * array will be heap allocated. Be careful not to use this constructor - * when you really want the (void*, int) version. - */ - SkTArray(const T* array, int count) { - this->init(count); - this->copy(array); - } - /** - * Creates a SkTArray by copying contents of an initializer list. - */ - SkTArray(std::initializer_list data) - : SkTArray(data.begin(), data.size()) {} - - SkTArray& operator=(const SkTArray& that) { - if (this == &that) { - return *this; - } - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(that.count(), kExactFit); - fCount = that.fCount; - this->copy(that.fItemArray); - return *this; - } - SkTArray& operator=(SkTArray&& that) { - if (this == &that) { - return *this; - } - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(that.count(), kExactFit); - fCount = that.fCount; - that.move(fItemArray); - that.fCount = 0; - return *this; - } - - ~SkTArray() { - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - if (fOwnMemory) { - sk_free(fItemArray); - } - } - - /** - * Resets to count() == 0 and resets any reserve count. - */ - void reset() { - this->pop_back_n(fCount); - fReserved = false; - } - - /** - * Resets to count() = n newly constructed T objects and resets any reserve count. - */ - void reset(int n) { - SkASSERT(n >= 0); - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - // Set fCount to 0 before calling checkRealloc so that no elements are moved. - fCount = 0; - this->checkRealloc(n, kExactFit); - fCount = n; - for (int i = 0; i < this->count(); ++i) { - new (fItemArray + i) T; - } - fReserved = false; - } - - /** - * Resets to a copy of a C array and resets any reserve count. - */ - void reset(const T* array, int count) { - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(count, kExactFit); - fCount = count; - this->copy(array); - fReserved = false; - } - - /** - * Ensures there is enough reserved space for n additional elements. The is guaranteed at least - * until the array size grows above n and subsequently shrinks below n, any version of reset() - * is called, or reserve_back() is called again. - */ - void reserve_back(int n) { - SkASSERT(n >= 0); - if (n > 0) { - this->checkRealloc(n, kExactFit); - fReserved = fOwnMemory; - } else { - fReserved = false; - } - } - - void removeShuffle(int n) { - SkASSERT(n < this->count()); - int newCount = fCount - 1; - fCount = newCount; - fItemArray[n].~T(); - if (n != newCount) { - this->move(n, newCount); - } - } - - /** - * Number of elements in the array. - */ - int count() const { return fCount; } - - /** - * Is the array empty. - */ - bool empty() const { return !fCount; } - - /** - * Adds 1 new default-initialized T value and returns it by reference. Note - * the reference only remains valid until the next call that adds or removes - * elements. - */ - T& push_back() { - void* newT = this->push_back_raw(1); - return *new (newT) T; - } - - /** - * Version of above that uses a copy constructor to initialize the new item - */ - T& push_back(const T& t) { - void* newT = this->push_back_raw(1); - return *new (newT) T(t); - } - - /** - * Version of above that uses a move constructor to initialize the new item - */ - T& push_back(T&& t) { - void* newT = this->push_back_raw(1); - return *new (newT) T(std::move(t)); - } - - /** - * Construct a new T at the back of this array. - */ - template T& emplace_back(Args&&... args) { - void* newT = this->push_back_raw(1); - return *new (newT) T(std::forward(args)...); - } - - /** - * Allocates n more default-initialized T values, and returns the address of - * the start of that new range. Note: this address is only valid until the - * next API call made on the array that might add or remove elements. - */ - T* push_back_n(int n) { - SkASSERT(n >= 0); - void* newTs = this->push_back_raw(n); - for (int i = 0; i < n; ++i) { - new (static_cast(newTs) + i * sizeof(T)) T; - } - return static_cast(newTs); - } - - /** - * Version of above that uses a copy constructor to initialize all n items - * to the same T. - */ - T* push_back_n(int n, const T& t) { - SkASSERT(n >= 0); - void* newTs = this->push_back_raw(n); - for (int i = 0; i < n; ++i) { - new (static_cast(newTs) + i * sizeof(T)) T(t); - } - return static_cast(newTs); - } - - /** - * Version of above that uses a copy constructor to initialize the n items - * to separate T values. - */ - T* push_back_n(int n, const T t[]) { - SkASSERT(n >= 0); - this->checkRealloc(n, kGrowing); - for (int i = 0; i < n; ++i) { - new (fItemArray + fCount + i) T(t[i]); - } - fCount += n; - return fItemArray + fCount - n; - } - - /** - * Version of above that uses the move constructor to set n items. - */ - T* move_back_n(int n, T* t) { - SkASSERT(n >= 0); - this->checkRealloc(n, kGrowing); - for (int i = 0; i < n; ++i) { - new (fItemArray + fCount + i) T(std::move(t[i])); - } - fCount += n; - return fItemArray + fCount - n; - } - - /** - * Removes the last element. Not safe to call when count() == 0. - */ - void pop_back() { - SkASSERT(fCount > 0); - --fCount; - fItemArray[fCount].~T(); - this->checkRealloc(0, kShrinking); - } - - /** - * Removes the last n elements. Not safe to call when count() < n. - */ - void pop_back_n(int n) { - SkASSERT(n >= 0); - SkASSERT(this->count() >= n); - fCount -= n; - for (int i = 0; i < n; ++i) { - fItemArray[fCount + i].~T(); - } - this->checkRealloc(0, kShrinking); - } - - /** - * Pushes or pops from the back to resize. Pushes will be default - * initialized. - */ - void resize_back(int newCount) { - SkASSERT(newCount >= 0); - - if (newCount > this->count()) { - this->push_back_n(newCount - fCount); - } else if (newCount < this->count()) { - this->pop_back_n(fCount - newCount); - } - } - - /** Swaps the contents of this array with that array. Does a pointer swap if possible, - otherwise copies the T values. */ - void swap(SkTArray& that) { - using std::swap; - if (this == &that) { - return; - } - if (fOwnMemory && that.fOwnMemory) { - swap(fItemArray, that.fItemArray); - - auto count = fCount; - fCount = that.fCount; - that.fCount = count; - - auto allocCount = fAllocCount; - fAllocCount = that.fAllocCount; - that.fAllocCount = allocCount; - } else { - // This could be more optimal... - SkTArray copy(std::move(that)); - that = std::move(*this); - *this = std::move(copy); - } - } - - T* begin() { - return fItemArray; - } - const T* begin() const { - return fItemArray; - } - T* end() { - return fItemArray ? fItemArray + fCount : nullptr; - } - const T* end() const { - return fItemArray ? fItemArray + fCount : nullptr; - } - T* data() { return fItemArray; } - const T* data() const { return fItemArray; } - size_t size() const { return (size_t)fCount; } - void resize(size_t count) { this->resize_back((int)count); } - - /** - * Get the i^th element. - */ - T& operator[] (int i) { - SkASSERT(i < this->count()); - SkASSERT(i >= 0); - return fItemArray[i]; - } - - const T& operator[] (int i) const { - SkASSERT(i < this->count()); - SkASSERT(i >= 0); - return fItemArray[i]; - } - - T& at(int i) { return (*this)[i]; } - const T& at(int i) const { return (*this)[i]; } - - /** - * equivalent to operator[](0) - */ - T& front() { SkASSERT(fCount > 0); return fItemArray[0];} - - const T& front() const { SkASSERT(fCount > 0); return fItemArray[0];} - - /** - * equivalent to operator[](count() - 1) - */ - T& back() { SkASSERT(fCount); return fItemArray[fCount - 1];} - - const T& back() const { SkASSERT(fCount > 0); return fItemArray[fCount - 1];} - - /** - * equivalent to operator[](count()-1-i) - */ - T& fromBack(int i) { - SkASSERT(i >= 0); - SkASSERT(i < this->count()); - return fItemArray[fCount - i - 1]; - } - - const T& fromBack(int i) const { - SkASSERT(i >= 0); - SkASSERT(i < this->count()); - return fItemArray[fCount - i - 1]; - } - - bool operator==(const SkTArray& right) const { - int leftCount = this->count(); - if (leftCount != right.count()) { - return false; - } - for (int index = 0; index < leftCount; ++index) { - if (fItemArray[index] != right.fItemArray[index]) { - return false; - } - } - return true; - } - - bool operator!=(const SkTArray& right) const { - return !(*this == right); - } - - int capacity() const { - return fAllocCount; - } - -protected: - /** - * Creates an empty array that will use the passed storage block until it - * is insufficiently large to hold the entire array. - */ - template - SkTArray(SkAlignedSTStorage* storage) { - this->initWithPreallocatedStorage(0, storage->get(), N); - } - - /** - * Copy a C array, using preallocated storage if preAllocCount >= - * count. Otherwise storage will only be used when array shrinks - * to fit. - */ - template - SkTArray(const T* array, int count, SkAlignedSTStorage* storage) { - this->initWithPreallocatedStorage(count, storage->get(), N); - this->copy(array); - } - -private: - // We disable Control-Flow Integrity sanitization (go/cfi) when casting item-array buffers. - // CFI flags this code as dangerous because we are casting `buffer` to a T* while the buffer's - // contents might still be uninitialized memory. When T has a vtable, this is especially risky - // because we could hypothetically access a virtual method on fItemArray and jump to an - // unpredictable location in memory. Of course, SkTArray won't actually use fItemArray in this - // way, and we don't want to construct a T before the user requests one. There's no real risk - // here, so disable CFI when doing these casts. - SK_ATTRIBUTE(no_sanitize("cfi")) - static T* TCast(void* buffer) { - return (T*)buffer; - } - - void init(int count) { - fCount = SkToU32(count); - if (!count) { - fAllocCount = 0; - fItemArray = nullptr; - } else { - fAllocCount = SkToU32(std::max(count, kMinHeapAllocCount)); - fItemArray = TCast(sk_malloc_throw((size_t)fAllocCount, sizeof(T))); - } - fOwnMemory = true; - fReserved = false; - } - - void initWithPreallocatedStorage(int count, void* preallocStorage, int preallocCount) { - SkASSERT(count >= 0); - SkASSERT(preallocCount > 0); - SkASSERT(preallocStorage); - fCount = SkToU32(count); - fItemArray = nullptr; - fReserved = false; - if (count > preallocCount) { - fAllocCount = SkToU32(std::max(count, kMinHeapAllocCount)); - fItemArray = TCast(sk_malloc_throw(fAllocCount, sizeof(T))); - fOwnMemory = true; - } else { - fAllocCount = SkToU32(preallocCount); - fItemArray = TCast(preallocStorage); - fOwnMemory = false; - } - } - - /** In the following move and copy methods, 'dst' is assumed to be uninitialized raw storage. - * In the following move methods, 'src' is destroyed leaving behind uninitialized raw storage. - */ - void copy(const T* src) { - // Some types may be trivially copyable, in which case we *could* use memcopy; but - // MEM_MOVE == true implies that the type is trivially movable, and not necessarily - // trivially copyable (think sk_sp<>). So short of adding another template arg, we - // must be conservative and use copy construction. - for (int i = 0; i < this->count(); ++i) { - new (fItemArray + i) T(src[i]); - } - } - - template std::enable_if_t move(int dst, int src) { - memcpy(static_cast(&fItemArray[dst]), - static_cast(&fItemArray[src]), - sizeof(T)); - } - template std::enable_if_t move(void* dst) { - sk_careful_memcpy(dst, fItemArray, fCount * sizeof(T)); - } - - template std::enable_if_t move(int dst, int src) { - new (&fItemArray[dst]) T(std::move(fItemArray[src])); - fItemArray[src].~T(); - } - template std::enable_if_t move(void* dst) { - for (int i = 0; i < this->count(); ++i) { - new (static_cast(dst) + sizeof(T) * (size_t)i) T(std::move(fItemArray[i])); - fItemArray[i].~T(); - } - } - - static constexpr int kMinHeapAllocCount = 8; - - // Helper function that makes space for n objects, adjusts the count, but does not initialize - // the new objects. - void* push_back_raw(int n) { - this->checkRealloc(n, kGrowing); - void* ptr = fItemArray + fCount; - fCount += n; - return ptr; - } - - void checkRealloc(int delta, ReallocType reallocType) { - SkASSERT(fCount >= 0); - SkASSERT(fAllocCount >= 0); - SkASSERT(-delta <= this->count()); - - // Move into 64bit math temporarily, to avoid local overflows - int64_t newCount = fCount + delta; - - // We allow fAllocCount to be in the range [newCount, 3*newCount]. We also never shrink - // when we're currently using preallocated memory, would allocate less than - // kMinHeapAllocCount, or a reserve count was specified that has yet to be exceeded. - bool mustGrow = newCount > fAllocCount; - bool shouldShrink = fAllocCount > 3 * newCount && fOwnMemory && !fReserved; - if (!mustGrow && !shouldShrink) { - return; - } - - int64_t newAllocCount = newCount; - if (reallocType != kExactFit) { - // Whether we're growing or shrinking, leave at least 50% extra space for future growth. - newAllocCount += ((newCount + 1) >> 1); - // Align the new allocation count to kMinHeapAllocCount. - static_assert(SkIsPow2(kMinHeapAllocCount), "min alloc count not power of two."); - newAllocCount = (newAllocCount + (kMinHeapAllocCount - 1)) & ~(kMinHeapAllocCount - 1); - } - - // At small sizes the old and new alloc count can both be kMinHeapAllocCount. - if (newAllocCount == fAllocCount) { - return; - } - - fAllocCount = SkToU32(Sk64_pin_to_s32(newAllocCount)); - SkASSERT(fAllocCount >= newCount); - T* newItemArray = TCast(sk_malloc_throw((size_t)fAllocCount, sizeof(T))); - this->move(newItemArray); - if (fOwnMemory) { - sk_free(fItemArray); - } - fItemArray = newItemArray; - fOwnMemory = true; - fReserved = false; - } - - T* fItemArray; - uint32_t fOwnMemory : 1; - uint32_t fCount : 31; - uint32_t fReserved : 1; - uint32_t fAllocCount : 31; -}; - -template static inline void swap(SkTArray& a, SkTArray& b) { - a.swap(b); -} - -template constexpr int SkTArray::kMinHeapAllocCount; - -/** - * Subclass of SkTArray that contains a preallocated memory block for the array. - */ -template ::value> -class SkSTArray : private SkAlignedSTStorage, public SkTArray { -private: - using STORAGE = SkAlignedSTStorage; - using INHERITED = SkTArray; - -public: - SkSTArray() - : STORAGE{}, INHERITED(static_cast(this)) {} - - SkSTArray(const T* array, int count) - : STORAGE{}, INHERITED(array, count, static_cast(this)) {} - - SkSTArray(std::initializer_list data) - : SkSTArray(data.begin(), data.size()) {} - - explicit SkSTArray(int reserveCount) - : SkSTArray() { - this->reserve_back(reserveCount); - } - - SkSTArray (const SkSTArray& that) : SkSTArray() { *this = that; } - explicit SkSTArray(const INHERITED& that) : SkSTArray() { *this = that; } - SkSTArray ( SkSTArray&& that) : SkSTArray() { *this = std::move(that); } - explicit SkSTArray( INHERITED&& that) : SkSTArray() { *this = std::move(that); } - - SkSTArray& operator=(const SkSTArray& that) { - INHERITED::operator=(that); - return *this; - } - SkSTArray& operator=(const INHERITED& that) { - INHERITED::operator=(that); - return *this; - } - - SkSTArray& operator=(SkSTArray&& that) { - INHERITED::operator=(std::move(that)); - return *this; - } - SkSTArray& operator=(INHERITED&& that) { - INHERITED::operator=(std::move(that)); - return *this; - } -}; - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h deleted file mode 100644 index 2cd89fd2f4df5..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 SkUniquePaintParamsID_DEFINED -#define SkUniquePaintParamsID_DEFINED - -#include "include/core/SkTypes.h" - -// This class boils down to a unique uint that can be used instead of a variable length -// key derived from a PaintParams. -class SkUniquePaintParamsID { -public: - explicit SkUniquePaintParamsID(uint32_t id) : fID(id) { - SkASSERT(id != SK_InvalidUniqueID); - } - - static SkUniquePaintParamsID InvalidID() { return SkUniquePaintParamsID(); } - - SkUniquePaintParamsID() : fID(SK_InvalidUniqueID) {} - - bool operator==(const SkUniquePaintParamsID &that) const { return fID == that.fID; } - bool operator!=(const SkUniquePaintParamsID &that) const { return !(*this == that); } - - bool isValid() const { return fID != SK_InvalidUniqueID; } - uint32_t asUInt() const { return fID; } - -private: - uint32_t fID; -}; - -#endif // SkUniquePaintParamsID_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h deleted file mode 100644 index 74cdabffe2d0c..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h +++ /dev/null @@ -1,1026 +0,0 @@ -/* - * Copyright 2019 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKVX_DEFINED -#define SKVX_DEFINED - -// skvx::Vec are SIMD vectors of N T's, a v1.5 successor to SkNx. -// -// This time we're leaning a bit less on platform-specific intrinsics and a bit -// more on Clang/GCC vector extensions, but still keeping the option open to -// drop in platform-specific intrinsics, actually more easily than before. -// -// We've also fixed a few of the caveats that used to make SkNx awkward to work -// with across translation units. skvx::Vec always has N*sizeof(T) size -// and alignment and is safe to use across translation units freely. -// (Ideally we'd only align to T, but that tanks ARMv7 NEON codegen.) - -// Please try to keep this file independent of Skia headers. -#include // std::min, std::max -#include // assert() -#include // ceilf, floorf, truncf, roundf, sqrtf, etc. -#include // intXX_t -#include // memcpy() -#include // std::initializer_list -#include // std::index_sequence - -// Users may disable SIMD with SKNX_NO_SIMD, which may be set via compiler flags. -// The gn build has no option which sets SKNX_NO_SIMD. -// Use SKVX_USE_SIMD internally to avoid confusing double negation. -// Do not use 'defined' in a macro expansion. -#if !defined(SKNX_NO_SIMD) - #define SKVX_USE_SIMD 1 -#else - #define SKVX_USE_SIMD 0 -#endif - -#if SKVX_USE_SIMD - #if defined(__SSE__) || defined(__AVX__) || defined(__AVX2__) - #include - #elif defined(__ARM_NEON) - #include - #elif defined(__wasm_simd128__) - #include - #endif -#endif - -// To avoid ODR violations, all methods must be force-inlined... -#if defined(_MSC_VER) - #define SKVX_ALWAYS_INLINE __forceinline -#else - #define SKVX_ALWAYS_INLINE __attribute__((always_inline)) -#endif - -// ... and all standalone functions must be static. Please use these helpers: -#define SI static inline -#define SIT template < typename T> SI -#define SIN template SI -#define SINT template SI -#define SINTU template ::value>> SI - -namespace skvx { - -template -struct alignas(N*sizeof(T)) Vec; - -template -SI Vec shuffle(const Vec&); - -template -SI D bit_pun(const S&); - -// All Vec have the same simple memory layout, the same as `T vec[N]`. -template -struct alignas(N*sizeof(T)) VecStorage { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - - Vec lo, hi; -}; - -template -struct VecStorage<4,T> { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y, T z, T w) : lo(x,y), hi(z, w) {} - SKVX_ALWAYS_INLINE VecStorage(Vec<2,T> xy, T z, T w) : lo(xy), hi(z,w) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y, Vec<2,T> zw) : lo(x,y), hi(zw) {} - SKVX_ALWAYS_INLINE VecStorage(Vec<2,T> xy, Vec<2,T> zw) : lo(xy), hi(zw) {} - - SKVX_ALWAYS_INLINE Vec<2,T>& xy() { return lo; } - SKVX_ALWAYS_INLINE Vec<2,T>& zw() { return hi; } - SKVX_ALWAYS_INLINE T& x() { return lo.lo.val; } - SKVX_ALWAYS_INLINE T& y() { return lo.hi.val; } - SKVX_ALWAYS_INLINE T& z() { return hi.lo.val; } - SKVX_ALWAYS_INLINE T& w() { return hi.hi.val; } - - SKVX_ALWAYS_INLINE Vec<2,T> xy() const { return lo; } - SKVX_ALWAYS_INLINE Vec<2,T> zw() const { return hi; } - SKVX_ALWAYS_INLINE T x() const { return lo.lo.val; } - SKVX_ALWAYS_INLINE T y() const { return lo.hi.val; } - SKVX_ALWAYS_INLINE T z() const { return hi.lo.val; } - SKVX_ALWAYS_INLINE T w() const { return hi.hi.val; } - - // Exchange-based swizzles. These should take 1 cycle on NEON and 3 (pipelined) cycles on SSE. - SKVX_ALWAYS_INLINE Vec<4,T> yxwz() const { return shuffle<1,0,3,2>(bit_pun>(*this)); } - SKVX_ALWAYS_INLINE Vec<4,T> zwxy() const { return shuffle<2,3,0,1>(bit_pun>(*this)); } - - Vec<2,T> lo, hi; -}; - -template -struct VecStorage<2,T> { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y) : lo(x), hi(y) {} - - SKVX_ALWAYS_INLINE T& x() { return lo.val; } - SKVX_ALWAYS_INLINE T& y() { return hi.val; } - - SKVX_ALWAYS_INLINE T x() const { return lo.val; } - SKVX_ALWAYS_INLINE T y() const { return hi.val; } - - // This exchange-based swizzle should take 1 cycle on NEON and 3 (pipelined) cycles on SSE. - SKVX_ALWAYS_INLINE Vec<2,T> yx() const { return shuffle<1,0>(bit_pun>(*this)); } - - SKVX_ALWAYS_INLINE Vec<4,T> xyxy() const { - return Vec<4,T>(bit_pun>(*this), bit_pun>(*this)); - } - - Vec<1,T> lo, hi; -}; - -template -struct alignas(N*sizeof(T)) Vec : public VecStorage { - static_assert((N & (N-1)) == 0, "N must be a power of 2."); - static_assert(sizeof(T) >= alignof(T), "What kind of unusual T is this?"); - - // Methods belong here in the class declaration of Vec only if: - // - they must be here, like constructors or operator[]; - // - they'll definitely never want a specialized implementation. - // Other operations on Vec should be defined outside the type. - - SKVX_ALWAYS_INLINE Vec() = default; - - using VecStorage::VecStorage; - - // NOTE: Vec{x} produces x000..., whereas Vec(x) produces xxxx.... since this constructor fills - // unspecified lanes with 0s, whereas the single T constructor fills all lanes with the value. - SKVX_ALWAYS_INLINE Vec(std::initializer_list xs) { - T vals[N] = {0}; - memcpy(vals, xs.begin(), std::min(xs.size(), (size_t)N)*sizeof(T)); - - this->lo = Vec::Load(vals + 0); - this->hi = Vec::Load(vals + N/2); - } - - SKVX_ALWAYS_INLINE T operator[](int i) const { return ilo[i] : this->hi[i-N/2]; } - SKVX_ALWAYS_INLINE T& operator[](int i) { return ilo[i] : this->hi[i-N/2]; } - - SKVX_ALWAYS_INLINE static Vec Load(const void* ptr) { - Vec v; - memcpy(&v, ptr, sizeof(Vec)); - return v; - } - SKVX_ALWAYS_INLINE void store(void* ptr) const { - memcpy(ptr, this, sizeof(Vec)); - } -}; - -template -struct Vec<1,T> { - T val; - - SKVX_ALWAYS_INLINE Vec() = default; - - Vec(T s) : val(s) {} - - SKVX_ALWAYS_INLINE Vec(std::initializer_list xs) : val(xs.size() ? *xs.begin() : 0) {} - - SKVX_ALWAYS_INLINE T operator[](int) const { return val; } - SKVX_ALWAYS_INLINE T& operator[](int) { return val; } - - SKVX_ALWAYS_INLINE static Vec Load(const void* ptr) { - Vec v; - memcpy(&v, ptr, sizeof(Vec)); - return v; - } - SKVX_ALWAYS_INLINE void store(void* ptr) const { - memcpy(ptr, this, sizeof(Vec)); - } -}; - -template -SI D bit_pun(const S& s) { - static_assert(sizeof(D) == sizeof(S)); - D d; - memcpy(&d, &s, sizeof(D)); - return d; -} - -// Translate from a value type T to its corresponding Mask, the result of a comparison. -template struct Mask { using type = T; }; -template <> struct Mask { using type = int32_t; }; -template <> struct Mask { using type = int64_t; }; -template using M = typename Mask::type; - -// Join two Vec into one Vec<2N,T>. -SINT Vec<2*N,T> join(const Vec& lo, const Vec& hi) { - Vec<2*N,T> v; - v.lo = lo; - v.hi = hi; - return v; -} - -// We have three strategies for implementing Vec operations: -// 1) lean on Clang/GCC vector extensions when available; -// 2) use map() to apply a scalar function lane-wise; -// 3) recurse on lo/hi to scalar portable implementations. -// We can slot in platform-specific implementations as overloads for particular Vec, -// or often integrate them directly into the recursion of style 3), allowing fine control. - -#if SKVX_USE_SIMD && (defined(__clang__) || defined(__GNUC__)) - - // VExt types have the same size as Vec and support most operations directly. - #if defined(__clang__) - template - using VExt = T __attribute__((ext_vector_type(N))); - - #elif defined(__GNUC__) - template - struct VExtHelper { - typedef T __attribute__((vector_size(N*sizeof(T)))) type; - }; - - template - using VExt = typename VExtHelper::type; - - // For some reason some (new!) versions of GCC cannot seem to deduce N in the generic - // to_vec() below for N=4 and T=float. This workaround seems to help... - SI Vec<4,float> to_vec(VExt<4,float> v) { return bit_pun>(v); } - #endif - - SINT VExt to_vext(const Vec& v) { return bit_pun>(v); } - SINT Vec to_vec(const VExt& v) { return bit_pun>(v); } - - SINT Vec operator+(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) + to_vext(y)); - } - SINT Vec operator-(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) - to_vext(y)); - } - SINT Vec operator*(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) * to_vext(y)); - } - SINT Vec operator/(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) / to_vext(y)); - } - - SINT Vec operator^(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) ^ to_vext(y)); - } - SINT Vec operator&(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) & to_vext(y)); - } - SINT Vec operator|(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) | to_vext(y)); - } - - SINT Vec operator!(const Vec& x) { return to_vec(!to_vext(x)); } - SINT Vec operator-(const Vec& x) { return to_vec(-to_vext(x)); } - SINT Vec operator~(const Vec& x) { return to_vec(~to_vext(x)); } - - SINT Vec operator<<(const Vec& x, int k) { return to_vec(to_vext(x) << k); } - SINT Vec operator>>(const Vec& x, int k) { return to_vec(to_vext(x) >> k); } - - SINT Vec> operator==(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) == to_vext(y)); - } - SINT Vec> operator!=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) != to_vext(y)); - } - SINT Vec> operator<=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) <= to_vext(y)); - } - SINT Vec> operator>=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) >= to_vext(y)); - } - SINT Vec> operator< (const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) < to_vext(y)); - } - SINT Vec> operator> (const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) > to_vext(y)); - } - -#else - - // Either SKNX_NO_SIMD is defined, or Clang/GCC vector extensions are not available. - // We'll implement things portably with N==1 scalar implementations and recursion onto them. - - // N == 1 scalar implementations. - SIT Vec<1,T> operator+(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val + y.val; } - SIT Vec<1,T> operator-(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val - y.val; } - SIT Vec<1,T> operator*(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val * y.val; } - SIT Vec<1,T> operator/(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val / y.val; } - - SIT Vec<1,T> operator^(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val ^ y.val; } - SIT Vec<1,T> operator&(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val & y.val; } - SIT Vec<1,T> operator|(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val | y.val; } - - SIT Vec<1,T> operator!(const Vec<1,T>& x) { return !x.val; } - SIT Vec<1,T> operator-(const Vec<1,T>& x) { return -x.val; } - SIT Vec<1,T> operator~(const Vec<1,T>& x) { return ~x.val; } - - SIT Vec<1,T> operator<<(const Vec<1,T>& x, int k) { return x.val << k; } - SIT Vec<1,T> operator>>(const Vec<1,T>& x, int k) { return x.val >> k; } - - SIT Vec<1,M> operator==(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val == y.val ? ~0 : 0; - } - SIT Vec<1,M> operator!=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val != y.val ? ~0 : 0; - } - SIT Vec<1,M> operator<=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val <= y.val ? ~0 : 0; - } - SIT Vec<1,M> operator>=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val >= y.val ? ~0 : 0; - } - SIT Vec<1,M> operator< (const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val < y.val ? ~0 : 0; - } - SIT Vec<1,M> operator> (const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val > y.val ? ~0 : 0; - } - - // Recurse on lo/hi down to N==1 scalar implementations. - SINT Vec operator+(const Vec& x, const Vec& y) { - return join(x.lo + y.lo, x.hi + y.hi); - } - SINT Vec operator-(const Vec& x, const Vec& y) { - return join(x.lo - y.lo, x.hi - y.hi); - } - SINT Vec operator*(const Vec& x, const Vec& y) { - return join(x.lo * y.lo, x.hi * y.hi); - } - SINT Vec operator/(const Vec& x, const Vec& y) { - return join(x.lo / y.lo, x.hi / y.hi); - } - - SINT Vec operator^(const Vec& x, const Vec& y) { - return join(x.lo ^ y.lo, x.hi ^ y.hi); - } - SINT Vec operator&(const Vec& x, const Vec& y) { - return join(x.lo & y.lo, x.hi & y.hi); - } - SINT Vec operator|(const Vec& x, const Vec& y) { - return join(x.lo | y.lo, x.hi | y.hi); - } - - SINT Vec operator!(const Vec& x) { return join(!x.lo, !x.hi); } - SINT Vec operator-(const Vec& x) { return join(-x.lo, -x.hi); } - SINT Vec operator~(const Vec& x) { return join(~x.lo, ~x.hi); } - - SINT Vec operator<<(const Vec& x, int k) { return join(x.lo << k, x.hi << k); } - SINT Vec operator>>(const Vec& x, int k) { return join(x.lo >> k, x.hi >> k); } - - SINT Vec> operator==(const Vec& x, const Vec& y) { - return join(x.lo == y.lo, x.hi == y.hi); - } - SINT Vec> operator!=(const Vec& x, const Vec& y) { - return join(x.lo != y.lo, x.hi != y.hi); - } - SINT Vec> operator<=(const Vec& x, const Vec& y) { - return join(x.lo <= y.lo, x.hi <= y.hi); - } - SINT Vec> operator>=(const Vec& x, const Vec& y) { - return join(x.lo >= y.lo, x.hi >= y.hi); - } - SINT Vec> operator< (const Vec& x, const Vec& y) { - return join(x.lo < y.lo, x.hi < y.hi); - } - SINT Vec> operator> (const Vec& x, const Vec& y) { - return join(x.lo > y.lo, x.hi > y.hi); - } -#endif - -// Scalar/vector operations splat the scalar to a vector. -SINTU Vec operator+ (U x, const Vec& y) { return Vec(x) + y; } -SINTU Vec operator- (U x, const Vec& y) { return Vec(x) - y; } -SINTU Vec operator* (U x, const Vec& y) { return Vec(x) * y; } -SINTU Vec operator/ (U x, const Vec& y) { return Vec(x) / y; } -SINTU Vec operator^ (U x, const Vec& y) { return Vec(x) ^ y; } -SINTU Vec operator& (U x, const Vec& y) { return Vec(x) & y; } -SINTU Vec operator| (U x, const Vec& y) { return Vec(x) | y; } -SINTU Vec> operator==(U x, const Vec& y) { return Vec(x) == y; } -SINTU Vec> operator!=(U x, const Vec& y) { return Vec(x) != y; } -SINTU Vec> operator<=(U x, const Vec& y) { return Vec(x) <= y; } -SINTU Vec> operator>=(U x, const Vec& y) { return Vec(x) >= y; } -SINTU Vec> operator< (U x, const Vec& y) { return Vec(x) < y; } -SINTU Vec> operator> (U x, const Vec& y) { return Vec(x) > y; } - -SINTU Vec operator+ (const Vec& x, U y) { return x + Vec(y); } -SINTU Vec operator- (const Vec& x, U y) { return x - Vec(y); } -SINTU Vec operator* (const Vec& x, U y) { return x * Vec(y); } -SINTU Vec operator/ (const Vec& x, U y) { return x / Vec(y); } -SINTU Vec operator^ (const Vec& x, U y) { return x ^ Vec(y); } -SINTU Vec operator& (const Vec& x, U y) { return x & Vec(y); } -SINTU Vec operator| (const Vec& x, U y) { return x | Vec(y); } -SINTU Vec> operator==(const Vec& x, U y) { return x == Vec(y); } -SINTU Vec> operator!=(const Vec& x, U y) { return x != Vec(y); } -SINTU Vec> operator<=(const Vec& x, U y) { return x <= Vec(y); } -SINTU Vec> operator>=(const Vec& x, U y) { return x >= Vec(y); } -SINTU Vec> operator< (const Vec& x, U y) { return x < Vec(y); } -SINTU Vec> operator> (const Vec& x, U y) { return x > Vec(y); } - -SINT Vec& operator+=(Vec& x, const Vec& y) { return (x = x + y); } -SINT Vec& operator-=(Vec& x, const Vec& y) { return (x = x - y); } -SINT Vec& operator*=(Vec& x, const Vec& y) { return (x = x * y); } -SINT Vec& operator/=(Vec& x, const Vec& y) { return (x = x / y); } -SINT Vec& operator^=(Vec& x, const Vec& y) { return (x = x ^ y); } -SINT Vec& operator&=(Vec& x, const Vec& y) { return (x = x & y); } -SINT Vec& operator|=(Vec& x, const Vec& y) { return (x = x | y); } - -SINTU Vec& operator+=(Vec& x, U y) { return (x = x + Vec(y)); } -SINTU Vec& operator-=(Vec& x, U y) { return (x = x - Vec(y)); } -SINTU Vec& operator*=(Vec& x, U y) { return (x = x * Vec(y)); } -SINTU Vec& operator/=(Vec& x, U y) { return (x = x / Vec(y)); } -SINTU Vec& operator^=(Vec& x, U y) { return (x = x ^ Vec(y)); } -SINTU Vec& operator&=(Vec& x, U y) { return (x = x & Vec(y)); } -SINTU Vec& operator|=(Vec& x, U y) { return (x = x | Vec(y)); } - -SINT Vec& operator<<=(Vec& x, int bits) { return (x = x << bits); } -SINT Vec& operator>>=(Vec& x, int bits) { return (x = x >> bits); } - -// Some operations we want are not expressible with Clang/GCC vector extensions. - -// Clang can reason about naive_if_then_else() and optimize through it better -// than if_then_else(), so it's sometimes useful to call it directly when we -// think an entire expression should optimize away, e.g. min()/max(). -SINT Vec naive_if_then_else(const Vec>& cond, const Vec& t, const Vec& e) { - return bit_pun>(( cond & bit_pun>>(t)) | - (~cond & bit_pun>>(e)) ); -} - -SIT Vec<1,T> if_then_else(const Vec<1,M>& cond, const Vec<1,T>& t, const Vec<1,T>& e) { - // In practice this scalar implementation is unlikely to be used. See next if_then_else(). - return bit_pun>(( cond & bit_pun>>(t)) | - (~cond & bit_pun>>(e)) ); -} -SINT Vec if_then_else(const Vec>& cond, const Vec& t, const Vec& e) { - // Specializations inline here so they can generalize what types the apply to. -#if SKVX_USE_SIMD && defined(__AVX2__) - if constexpr (N*sizeof(T) == 32) { - return bit_pun>(_mm256_blendv_epi8(bit_pun<__m256i>(e), - bit_pun<__m256i>(t), - bit_pun<__m256i>(cond))); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE4_1__) - if constexpr (N*sizeof(T) == 16) { - return bit_pun>(_mm_blendv_epi8(bit_pun<__m128i>(e), - bit_pun<__m128i>(t), - bit_pun<__m128i>(cond))); - } -#endif -#if SKVX_USE_SIMD && defined(__ARM_NEON) - if constexpr (N*sizeof(T) == 16) { - return bit_pun>(vbslq_u8(bit_pun(cond), - bit_pun(t), - bit_pun(e))); - } -#endif - // Recurse for large vectors to try to hit the specializations above. - if constexpr (N*sizeof(T) > 16) { - return join(if_then_else(cond.lo, t.lo, e.lo), - if_then_else(cond.hi, t.hi, e.hi)); - } - // This default can lead to better code than the recursing onto scalars. - return naive_if_then_else(cond, t, e); -} - -SIT bool any(const Vec<1,T>& x) { return x.val != 0; } -SINT bool any(const Vec& x) { - // For any(), the _mm_testz intrinsics are correct and don't require comparing 'x' to 0, so it's - // lower latency compared to _mm_movemask + _mm_compneq on plain SSE. -#if SKVX_USE_SIMD && defined(__AVX2__) - if constexpr (N*sizeof(T) == 32) { - return !_mm256_testz_si256(bit_pun<__m256i>(x), _mm256_set1_epi32(-1)); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE_4_1__) - if constexpr (N*sizeof(T) == 16) { - return !_mm_testz_si128(bit_pun<__m128i>(x), _mm_set1_epi32(-1)); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE__) - if constexpr (N*sizeof(T) == 16) { - // On SSE, movemask checks only the MSB in each lane, which is fine if the lanes were set - // directly from a comparison op (which sets all bits to 1 when true), but skvx::Vec<> - // treats any non-zero value as true, so we have to compare 'x' to 0 before calling movemask - return _mm_movemask_ps(_mm_cmpneq_ps(bit_pun<__m128>(x), _mm_set1_ps(0))) != 0b0000; - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - // On 64-bit NEON, take the max across lanes, which will be non-zero if any lane was true. - // The specific lane-size doesn't really matter in this case since it's really any set bit - // that we're looking for. - if constexpr (N*sizeof(T) == 8 ) { return vmaxv_u8 (bit_pun (x)) > 0; } - if constexpr (N*sizeof(T) == 16) { return vmaxvq_u8(bit_pun(x)) > 0; } -#endif -#if SKVX_USE_SIMD && defined(__wasm_simd128__) - if constexpr (N == 4 && sizeof(T) == 4) { - return wasm_i32x4_any_true(bit_pun>(x)); - } -#endif - return any(x.lo) - || any(x.hi); -} - -SIT bool all(const Vec<1,T>& x) { return x.val != 0; } -SINT bool all(const Vec& x) { -// Unlike any(), we have to respect the lane layout, or we'll miss cases where a -// true lane has a mix of 0 and 1 bits. -#if SKVX_USE_SIMD && defined(__SSE__) - // Unfortunately, the _mm_testc intrinsics don't let us avoid the comparison to 0 for all()'s - // correctness, so always just use the plain SSE version. - if constexpr (N == 4 && sizeof(T) == 4) { - return _mm_movemask_ps(_mm_cmpneq_ps(bit_pun<__m128>(x), _mm_set1_ps(0))) == 0b1111; - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - // On 64-bit NEON, take the min across the lanes, which will be non-zero if all lanes are != 0. - if constexpr (sizeof(T)==1 && N==8) {return vminv_u8 (bit_pun (x)) > 0;} - if constexpr (sizeof(T)==1 && N==16) {return vminvq_u8 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==2 && N==4) {return vminv_u16 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==2 && N==8) {return vminvq_u16(bit_pun(x)) > 0;} - if constexpr (sizeof(T)==4 && N==2) {return vminv_u32 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==4 && N==4) {return vminvq_u32(bit_pun(x)) > 0;} -#endif -#if SKVX_USE_SIMD && defined(__wasm_simd128__) - if constexpr (N == 4 && sizeof(T) == 4) { - return wasm_i32x4_all_true(bit_pun>(x)); - } -#endif - return all(x.lo) - && all(x.hi); -} - -// cast() Vec to Vec, as if applying a C-cast to each lane. -// TODO: implement with map()? -template -SI Vec<1,D> cast(const Vec<1,S>& src) { return (D)src.val; } - -template -SI Vec cast(const Vec& src) { -#if SKVX_USE_SIMD && defined(__clang__) - return to_vec(__builtin_convertvector(to_vext(src), VExt)); -#else - return join(cast(src.lo), cast(src.hi)); -#endif -} - -// min/max match logic of std::min/std::max, which is important when NaN is involved. -SIT T min(const Vec<1,T>& x) { return x.val; } -SIT T max(const Vec<1,T>& x) { return x.val; } -SINT T min(const Vec& x) { return std::min(min(x.lo), min(x.hi)); } -SINT T max(const Vec& x) { return std::max(max(x.lo), max(x.hi)); } - -SINT Vec min(const Vec& x, const Vec& y) { return naive_if_then_else(y < x, y, x); } -SINT Vec max(const Vec& x, const Vec& y) { return naive_if_then_else(x < y, y, x); } - -SINTU Vec min(const Vec& x, U y) { return min(x, Vec(y)); } -SINTU Vec max(const Vec& x, U y) { return max(x, Vec(y)); } -SINTU Vec min(U x, const Vec& y) { return min(Vec(x), y); } -SINTU Vec max(U x, const Vec& y) { return max(Vec(x), y); } - -// pin matches the logic of SkTPin, which is important when NaN is involved. It always returns -// values in the range lo..hi, and if x is NaN, it returns lo. -SINT Vec pin(const Vec& x, const Vec& lo, const Vec& hi) { - return max(lo, min(x, hi)); -} - -// Shuffle values from a vector pretty arbitrarily: -// skvx::Vec<4,float> rgba = {R,G,B,A}; -// shuffle<2,1,0,3> (rgba) ~> {B,G,R,A} -// shuffle<2,1> (rgba) ~> {B,G} -// shuffle<2,1,2,1,2,1,2,1>(rgba) ~> {B,G,B,G,B,G,B,G} -// shuffle<3,3,3,3> (rgba) ~> {A,A,A,A} -// The only real restriction is that the output also be a legal N=power-of-two sknx::Vec. -template -SI Vec shuffle(const Vec& x) { -#if SKVX_USE_SIMD && defined(__clang__) - // TODO: can we just always use { x[Ix]... }? - return to_vec(__builtin_shufflevector(to_vext(x), to_vext(x), Ix...)); -#else - return { x[Ix]... }; -#endif -} - -// Call map(fn, x) for a vector with fn() applied to each lane of x, { fn(x[0]), fn(x[1]), ... }, -// or map(fn, x,y) for a vector of fn(x[i], y[i]), etc. - -template -SI auto map(std::index_sequence, - Fn&& fn, const Args&... args) -> skvx::Vec { - auto lane = [&](size_t i) -#if defined(__clang__) - // CFI, specifically -fsanitize=cfi-icall, seems to give a false positive here, - // with errors like "control flow integrity check for type 'float (float) - // noexcept' failed during indirect function call... note: sqrtf.cfi_jt defined - // here". But we can be quite sure fn is the right type: it's all inferred! - // So, stifle CFI in this function. - __attribute__((no_sanitize("cfi"))) -#endif - { return fn(args[i]...); }; - - return { lane(I)... }; -} - -template -auto map(Fn&& fn, const Vec& first, const Rest&... rest) { - // Derive an {0...N-1} index_sequence from the size of the first arg: N lanes in, N lanes out. - return map(std::make_index_sequence{}, fn, first,rest...); -} - -SIN Vec ceil(const Vec& x) { return map( ceilf, x); } -SIN Vec floor(const Vec& x) { return map(floorf, x); } -SIN Vec trunc(const Vec& x) { return map(truncf, x); } -SIN Vec round(const Vec& x) { return map(roundf, x); } -SIN Vec sqrt(const Vec& x) { return map( sqrtf, x); } -SIN Vec abs(const Vec& x) { return map( fabsf, x); } -SIN Vec fma(const Vec& x, - const Vec& y, - const Vec& z) { - // I don't understand why Clang's codegen is terrible if we write map(fmaf, x,y,z) directly. - auto fn = [](float x, float y, float z) { return fmaf(x,y,z); }; - return map(fn, x,y,z); -} - -SI Vec<1,int> lrint(const Vec<1,float>& x) { - return (int)lrintf(x.val); -} -SIN Vec lrint(const Vec& x) { -#if SKVX_USE_SIMD && defined(__AVX__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtps_epi32(bit_pun<__m256>(x))); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE__) - if constexpr (N == 4) { - return bit_pun>(_mm_cvtps_epi32(bit_pun<__m128>(x))); - } -#endif - return join(lrint(x.lo), - lrint(x.hi)); -} - -SIN Vec fract(const Vec& x) { return x - floor(x); } - -// Assumes inputs are finite and treat/flush denorm half floats as/to zero. -// Key constants to watch for: -// - a float is 32-bit, 1-8-23 sign-exponent-mantissa, with 127 exponent bias; -// - a half is 16-bit, 1-5-10 sign-exponent-mantissa, with 15 exponent bias. -SIN Vec to_half_finite_ftz(const Vec& x) { - Vec sem = bit_pun>(x), - s = sem & 0x8000'0000, - em = sem ^ s, - is_norm = em > 0x387f'd000, // halfway between largest f16 denorm and smallest norm - norm = (em>>13) - ((127-15)<<10); - return cast((s>>16) | (is_norm & norm)); -} -SIN Vec from_half_finite_ftz(const Vec& x) { - Vec wide = cast(x), - s = wide & 0x8000, - em = wide ^ s, - is_norm = em > 0x3ff, - norm = (em<<13) + ((127-15)<<23); - return bit_pun>((s<<16) | (is_norm & norm)); -} - -// Like if_then_else(), these N=1 base cases won't actually be used unless explicitly called. -SI Vec<1,uint16_t> to_half(const Vec<1,float>& x) { return to_half_finite_ftz(x); } -SI Vec<1,float> from_half(const Vec<1,uint16_t>& x) { return from_half_finite_ftz(x); } - -SIN Vec to_half(const Vec& x) { -#if SKVX_USE_SIMD && defined(__F16C__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtps_ph(bit_pun<__m256>(x), - _MM_FROUND_TO_NEAREST_INT)); - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - if constexpr (N == 4) { - return bit_pun>(vcvt_f16_f32(bit_pun(x))); - - } -#endif - if constexpr (N > 4) { - return join(to_half(x.lo), - to_half(x.hi)); - } - return to_half_finite_ftz(x); -} - -SIN Vec from_half(const Vec& x) { -#if SKVX_USE_SIMD && defined(__F16C__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtph_ps(bit_pun<__m128i>(x))); - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - if constexpr (N == 4) { - return bit_pun>(vcvt_f32_f16(bit_pun(x))); - } -#endif - if constexpr (N > 4) { - return join(from_half(x.lo), - from_half(x.hi)); - } - return from_half_finite_ftz(x); -} - -// div255(x) = (x + 127) / 255 is a bit-exact rounding divide-by-255, packing down to 8-bit. -SIN Vec div255(const Vec& x) { - return cast( (x+127)/255 ); -} - -// approx_scale(x,y) approximates div255(cast(x)*cast(y)) within a bit, -// and is always perfect when x or y is 0 or 255. -SIN Vec approx_scale(const Vec& x, const Vec& y) { - // All of (x*y+x)/256, (x*y+y)/256, and (x*y+255)/256 meet the criteria above. - // We happen to have historically picked (x*y+x)/256. - auto X = cast(x), - Y = cast(y); - return cast( (X*Y+X)/256 ); -} - -// saturated_add(x,y) sums values and clamps to the maximum value instead of overflowing. -SINT std::enable_if_t, Vec> saturated_add(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && (defined(__SSE__) || defined(__ARM_NEON)) - // Both SSE and ARM have 16-lane saturated adds, so use intrinsics for those and recurse down - // or join up to take advantage. - if constexpr (N == 16 && sizeof(T) == 1) { - #if defined(__SSE__) - return bit_pun>(_mm_adds_epu8(bit_pun<__m128i>(x), bit_pun<__m128i>(y))); - #else // __ARM_NEON - return bit_pun>(vqaddq_u8(bit_pun(x), bit_pun(y))); - #endif - } else if constexpr (N < 16 && sizeof(T) == 1) { - return saturated_add(join(x,x), join(y,y)).lo; - } else if constexpr (sizeof(T) == 1) { - return join(saturated_add(x.lo, y.lo), saturated_add(x.hi, y.hi)); - } -#endif - // Otherwise saturate manually - auto sum = x + y; - return if_then_else(sum < x, Vec(std::numeric_limits::max()), sum); -} - -// The ScaledDividerU32 takes a divisor > 1, and creates a function divide(numerator) that -// calculates a numerator / denominator. For this to be rounded properly, numerator should have -// half added in: -// divide(numerator + half) == floor(numerator/denominator + 1/2). -// -// This gives an answer within +/- 1 from the true value. -// -// Derivation of half: -// numerator/denominator + 1/2 = (numerator + half) / d -// numerator + denominator / 2 = numerator + half -// half = denominator / 2. -// -// Because half is divided by 2, that division must also be rounded. -// half == denominator / 2 = (denominator + 1) / 2. -// -// The divisorFactor is just a scaled value: -// divisorFactor = (1 / divisor) * 2 ^ 32. -// The maximum that can be divided and rounded is UINT_MAX - half. -class ScaledDividerU32 { -public: - explicit ScaledDividerU32(uint32_t divisor) - : fDivisorFactor{(uint32_t)(std::round((1.0 / divisor) * (1ull << 32)))} - , fHalf{(divisor + 1) >> 1} { - assert(divisor > 1); - } - - Vec<4, uint32_t> divide(const Vec<4, uint32_t>& numerator) const { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - uint64x2_t hi = vmull_n_u32(vget_high_u32(to_vext(numerator)), fDivisorFactor); - uint64x2_t lo = vmull_n_u32(vget_low_u32(to_vext(numerator)), fDivisorFactor); - - return to_vec<4, uint32_t>(vcombine_u32(vshrn_n_u64(lo,32), vshrn_n_u64(hi,32))); -#else - return cast((cast(numerator) * fDivisorFactor) >> 32); -#endif - } - - uint32_t half() const { return fHalf; } - -private: - const uint32_t fDivisorFactor; - const uint32_t fHalf; -}; - - -SIN Vec mull(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - // With NEON we can do eight u8*u8 -> u16 in one instruction, vmull_u8 (read, mul-long). - if constexpr (N == 8) { - return to_vec<8,uint16_t>(vmull_u8(to_vext(x), to_vext(y))); - } else if constexpr (N < 8) { - return mull(join(x,x), join(y,y)).lo; - } else { // N > 8 - return join(mull(x.lo, y.lo), mull(x.hi, y.hi)); - } -#else - return cast(x) * cast(y); -#endif -} - -SIN Vec mull(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - // NEON can do four u16*u16 -> u32 in one instruction, vmull_u16 - if constexpr (N == 4) { - return to_vec<4,uint32_t>(vmull_u16(to_vext(x), to_vext(y))); - } else if constexpr (N < 4) { - return mull(join(x,x), join(y,y)).lo; - } else { // N > 4 - return join(mull(x.lo, y.lo), mull(x.hi, y.hi)); - } -#else - return cast(x) * cast(y); -#endif -} - -SIN Vec mulhi(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__SSE__) - // Use _mm_mulhi_epu16 for 8xuint16_t and join or split to get there. - if constexpr (N == 8) { - return bit_pun>(_mm_mulhi_epu16(bit_pun<__m128i>(x), bit_pun<__m128i>(y))); - } else if constexpr (N < 8) { - return mulhi(join(x,x), join(y,y)).lo; - } else { // N > 8 - return join(mulhi(x.lo, y.lo), mulhi(x.hi, y.hi)); - } -#else - return skvx::cast(mull(x, y) >> 16); -#endif -} - -SINT T dot(const Vec& a, const Vec& b) { - auto ab = a*b; - if constexpr (N == 2) { - return ab[0] + ab[1]; - } else if constexpr (N == 4) { - return ab[0] + ab[1] + ab[2] + ab[3]; - } else { - T sum = ab[0]; - for (int i = 1; i < N; ++i) { - sum += ab[i]; - } - return sum; - } -} - -SI float cross(const Vec<2, float>& a, const Vec<2, float>& b) { - auto x = a * shuffle<1,0>(b); - return x[0] - x[1]; -} - -// De-interleaving load of 4 vectors. -// -// WARNING: These are really only supported well on NEON. Consider restructuring your data before -// resorting to these methods. -SIT void strided_load4(const T* v, - Vec<1,T>& a, - Vec<1,T>& b, - Vec<1,T>& c, - Vec<1,T>& d) { - a.val = v[0]; - b.val = v[1]; - c.val = v[2]; - d.val = v[3]; -} -SINT void strided_load4(const T* v, - Vec& a, - Vec& b, - Vec& c, - Vec& d) { - strided_load4(v, a.lo, b.lo, c.lo, d.lo); - strided_load4(v + 4*(N/2), a.hi, b.hi, c.hi, d.hi); -} -#if SKVX_USE_SIMD && defined(__ARM_NEON) -#define IMPL_LOAD4_TRANSPOSED(N, T, VLD) \ -SI void strided_load4(const T* v, \ - Vec& a, \ - Vec& b, \ - Vec& c, \ - Vec& d) { \ - auto mat = VLD(v); \ - a = bit_pun>(mat.val[0]); \ - b = bit_pun>(mat.val[1]); \ - c = bit_pun>(mat.val[2]); \ - d = bit_pun>(mat.val[3]); \ -} -IMPL_LOAD4_TRANSPOSED(2, uint32_t, vld4_u32) -IMPL_LOAD4_TRANSPOSED(4, uint16_t, vld4_u16) -IMPL_LOAD4_TRANSPOSED(8, uint8_t, vld4_u8) -IMPL_LOAD4_TRANSPOSED(2, int32_t, vld4_s32) -IMPL_LOAD4_TRANSPOSED(4, int16_t, vld4_s16) -IMPL_LOAD4_TRANSPOSED(8, int8_t, vld4_s8) -IMPL_LOAD4_TRANSPOSED(2, float, vld4_f32) -IMPL_LOAD4_TRANSPOSED(4, uint32_t, vld4q_u32) -IMPL_LOAD4_TRANSPOSED(8, uint16_t, vld4q_u16) -IMPL_LOAD4_TRANSPOSED(16, uint8_t, vld4q_u8) -IMPL_LOAD4_TRANSPOSED(4, int32_t, vld4q_s32) -IMPL_LOAD4_TRANSPOSED(8, int16_t, vld4q_s16) -IMPL_LOAD4_TRANSPOSED(16, int8_t, vld4q_s8) -IMPL_LOAD4_TRANSPOSED(4, float, vld4q_f32) -#undef IMPL_LOAD4_TRANSPOSED - -#elif SKVX_USE_SIMD && defined(__SSE__) - -SI void strided_load4(const float* v, - Vec<4,float>& a, - Vec<4,float>& b, - Vec<4,float>& c, - Vec<4,float>& d) { - __m128 a_ = _mm_loadu_ps(v); - __m128 b_ = _mm_loadu_ps(v+4); - __m128 c_ = _mm_loadu_ps(v+8); - __m128 d_ = _mm_loadu_ps(v+12); - _MM_TRANSPOSE4_PS(a_, b_, c_, d_); - a = bit_pun>(a_); - b = bit_pun>(b_); - c = bit_pun>(c_); - d = bit_pun>(d_); -} -#endif - -// De-interleaving load of 2 vectors. -// -// WARNING: These are really only supported well on NEON. Consider restructuring your data before -// resorting to these methods. -SIT void strided_load2(const T* v, Vec<1,T>& a, Vec<1,T>& b) { - a.val = v[0]; - b.val = v[1]; -} -SINT void strided_load2(const T* v, Vec& a, Vec& b) { - strided_load2(v, a.lo, b.lo); - strided_load2(v + 2*(N/2), a.hi, b.hi); -} -#if SKVX_USE_SIMD && defined(__ARM_NEON) -#define IMPL_LOAD2_TRANSPOSED(N, T, VLD) \ -SI void strided_load2(const T* v, Vec& a, Vec& b) { \ - auto mat = VLD(v); \ - a = bit_pun>(mat.val[0]); \ - b = bit_pun>(mat.val[1]); \ -} -IMPL_LOAD2_TRANSPOSED(2, uint32_t, vld2_u32) -IMPL_LOAD2_TRANSPOSED(4, uint16_t, vld2_u16) -IMPL_LOAD2_TRANSPOSED(8, uint8_t, vld2_u8) -IMPL_LOAD2_TRANSPOSED(2, int32_t, vld2_s32) -IMPL_LOAD2_TRANSPOSED(4, int16_t, vld2_s16) -IMPL_LOAD2_TRANSPOSED(8, int8_t, vld2_s8) -IMPL_LOAD2_TRANSPOSED(2, float, vld2_f32) -IMPL_LOAD2_TRANSPOSED(4, uint32_t, vld2q_u32) -IMPL_LOAD2_TRANSPOSED(8, uint16_t, vld2q_u16) -IMPL_LOAD2_TRANSPOSED(16, uint8_t, vld2q_u8) -IMPL_LOAD2_TRANSPOSED(4, int32_t, vld2q_s32) -IMPL_LOAD2_TRANSPOSED(8, int16_t, vld2q_s16) -IMPL_LOAD2_TRANSPOSED(16, int8_t, vld2q_s8) -IMPL_LOAD2_TRANSPOSED(4, float, vld2q_f32) -#undef IMPL_LOAD2_TRANSPOSED -#endif - -// Define commonly used aliases -using float2 = Vec< 2, float>; -using float4 = Vec< 4, float>; -using float8 = Vec< 8, float>; - -using double2 = Vec< 2, double>; -using double4 = Vec< 4, double>; -using double8 = Vec< 8, double>; - -using byte2 = Vec< 2, uint8_t>; -using byte4 = Vec< 4, uint8_t>; -using byte8 = Vec< 8, uint8_t>; -using byte16 = Vec<16, uint8_t>; - -using int2 = Vec< 2, int32_t>; -using int4 = Vec< 4, int32_t>; -using int8 = Vec< 8, int32_t>; - -using uint2 = Vec< 2, uint32_t>; -using uint4 = Vec< 4, uint32_t>; -using uint8 = Vec< 8, uint32_t>; - -using long2 = Vec< 2, int64_t>; -using long4 = Vec< 4, int64_t>; -using long8 = Vec< 8, int64_t>; - -// Use with from_half and to_half to convert between floatX, and use these for storage. -using half2 = Vec< 2, uint16_t>; -using half4 = Vec< 4, uint16_t>; -using half8 = Vec< 8, uint16_t>; - -} // namespace skvx - -#undef SINTU -#undef SINT -#undef SIN -#undef SIT -#undef SI -#undef SKVX_ALWAYS_INLINE -#undef SKVX_USE_SIMD - -#endif//SKVX_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h index 2b577342f4cd2..058a18652ba51 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h @@ -9,7 +9,10 @@ #define SkWeakRefCnt_DEFINED #include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + #include +#include /** \class SkWeakRefCnt diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h similarity index 86% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h index f60f7c83b969c..473981e1fb83f 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h @@ -8,16 +8,19 @@ #ifndef skgpu_SingleOwner_DEFINED #define skgpu_SingleOwner_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkDebug.h" // IWYU pragma: keep + +#if defined(SK_DEBUG) +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkThreadAnnotations.h" +#include "include/private/base/SkThreadID.h" -#ifdef SK_DEBUG -#include "include/private/SkMutex.h" -#include "include/private/SkThreadID.h" #endif namespace skgpu { -#ifdef SK_DEBUG +#if defined(SK_DEBUG) #define SKGPU_ASSERT_SINGLE_OWNER(obj) \ skgpu::SingleOwner::AutoEnforce debug_SingleOwner(obj, __FILE__, __LINE__); diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h new file mode 100644 index 0000000000000..4028f95d87d2b --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h @@ -0,0 +1,52 @@ +/* + * 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 SkAPI_DEFINED +#define SkAPI_DEFINED + +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +// If SKIA_IMPLEMENTATION is defined as 1, that signals we are building Skia and should +// export our symbols. If it is not set (or set to 0), then Skia is being used by a client +// and we should not export our symbols. +#if !defined(SKIA_IMPLEMENTATION) + #define SKIA_IMPLEMENTATION 0 +#endif + +// If we are compiling Skia is being as a DLL, we need to be sure to export all of our public +// APIs to that DLL. If a client is using Skia which was compiled as a DLL, we need to instruct +// the linker to use the symbols from that DLL. This is the goal of the SK_API define. +#if !defined(SK_API) + #if defined(SKIA_DLL) + #if defined(_MSC_VER) + #if SKIA_IMPLEMENTATION + #define SK_API __declspec(dllexport) + #else + #define SK_API __declspec(dllimport) + #endif + #else + #define SK_API __attribute__((visibility("default"))) + #endif + #else + #define SK_API + #endif +#endif + +// SK_SPI is functionally identical to SK_API, but used within src to clarify that it's less stable +#if !defined(SK_SPI) + #define SK_SPI SK_API +#endif + +// See https://clang.llvm.org/docs/AttributeReference.html#availability +// The API_AVAILABLE macro comes from on MacOS +#if defined(SK_ENABLE_API_AVAILABLE) +# define SK_API_AVAILABLE API_AVAILABLE +#else +# define SK_API_AVAILABLE(...) +#endif + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h new file mode 100644 index 0000000000000..2b2138ddd49c2 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h @@ -0,0 +1,39 @@ +/* + * 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 SkAlign_DEFINED +#define SkAlign_DEFINED + +#include "include/private/base/SkAssert.h" + +#include + +template static constexpr T SkAlign2(T x) { return (x + 1) >> 1 << 1; } +template static constexpr T SkAlign4(T x) { return (x + 3) >> 2 << 2; } +template static constexpr T SkAlign8(T x) { return (x + 7) >> 3 << 3; } + +template static constexpr bool SkIsAlign2(T x) { return 0 == (x & 1); } +template static constexpr bool SkIsAlign4(T x) { return 0 == (x & 3); } +template static constexpr bool SkIsAlign8(T x) { return 0 == (x & 7); } + +template static constexpr T SkAlignPtr(T x) { + return sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x); +} +template static constexpr bool SkIsAlignPtr(T x) { + return sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x); +} + +/** + * align up to a power of 2 + */ +static inline constexpr size_t SkAlignTo(size_t x, size_t alignment) { + // The same as alignment && SkIsPow2(value), w/o a dependency cycle. + SkASSERT(alignment && (alignment & (alignment - 1)) == 0); + return (x + alignment - 1) & ~(alignment - 1); +} + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h new file mode 100644 index 0000000000000..532ad03978fac --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h @@ -0,0 +1,32 @@ +// 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 SkAlignedStorage_DEFINED +#define SkAlignedStorage_DEFINED + +#include +#include + +template class SkAlignedSTStorage { +public: + SkAlignedSTStorage() {} + SkAlignedSTStorage(SkAlignedSTStorage&&) = delete; + SkAlignedSTStorage(const SkAlignedSTStorage&) = delete; + SkAlignedSTStorage& operator=(SkAlignedSTStorage&&) = delete; + SkAlignedSTStorage& operator=(const SkAlignedSTStorage&) = delete; + + // Returns void* because this object does not initialize the + // memory. Use placement new for types that require a constructor. + void* get() { return fStorage; } + const void* get() const { return fStorage; } + + // Act as a container of bytes because the storage is uninitialized. + std::byte* data() { return fStorage; } + const std::byte* data() const { return fStorage; } + size_t size() const { return std::size(fStorage); } + +private: + alignas(T) std::byte fStorage[sizeof(T) * N]; +}; + +#endif // SkAlignedStorage_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h new file mode 100644 index 0000000000000..97d43d4f64ff4 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h @@ -0,0 +1,92 @@ +/* + * 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 SkAssert_DEFINED +#define SkAssert_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" // IWYU pragma: keep + +/** Called internally if we hit an unrecoverable error. + The platform implementation must not return, but should either throw + an exception or otherwise exit. +*/ +[[noreturn]] SK_API extern void sk_abort_no_print(void); + +#if defined(SK_BUILD_FOR_GOOGLE3) + void SkDebugfForDumpStackTrace(const char* data, void* unused); + namespace base { + void DumpStackTrace(int skip_count, void w(const char*, void*), void* arg); + } +# define SK_DUMP_GOOGLE3_STACK() ::base::DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr) +#else +# define SK_DUMP_GOOGLE3_STACK() +#endif + +#if !defined(SK_ABORT) +# if defined(SK_BUILD_FOR_WIN) + // This style lets Visual Studio follow errors back to the source file. +# define SK_DUMP_LINE_FORMAT "%s(%d)" +# else +# define SK_DUMP_LINE_FORMAT "%s:%d" +# endif +# define SK_ABORT(message, ...) \ + do { \ + SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \ + __FILE__, __LINE__, ##__VA_ARGS__); \ + SK_DUMP_GOOGLE3_STACK(); \ + sk_abort_no_print(); \ + } while (false) +#endif + +// SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g. +// uint32_t foo(int x) { +// SkASSERT(x > 4); +// return x - 4; +// } +// and are also written to be compatible with constexpr functions: +// constexpr uint32_t foo(int x) { +// return SkASSERT(x > 4), +// x - 4; +// } +#define SkASSERT_RELEASE(cond) \ + static_cast( (cond) ? (void)0 : []{ SK_ABORT("assert(%s)", #cond); }() ) + +#if defined(SK_DEBUG) + #define SkASSERT(cond) SkASSERT_RELEASE(cond) + #define SkASSERTF(cond, fmt, ...) static_cast( (cond) ? (void)0 : [&]{ \ + SkDebugf(fmt"\n", ##__VA_ARGS__); \ + SK_ABORT("assert(%s)", #cond); \ + }() ) + #define SkDEBUGFAIL(message) SK_ABORT("%s", message) + #define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__) + #define SkAssertResult(cond) SkASSERT(cond) +#else + #define SkASSERT(cond) static_cast(0) + #define SkASSERTF(cond, fmt, ...) static_cast(0) + #define SkDEBUGFAIL(message) + #define SkDEBUGFAILF(fmt, ...) + + // unlike SkASSERT, this macro executes its condition in the non-debug build. + // The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT. + #define SkAssertResult(cond) if (cond) {} do {} while(false) +#endif + +#if !defined(SkUNREACHABLE) +# if defined(_MSC_VER) && !defined(__clang__) +# include +# define FAST_FAIL_INVALID_ARG 5 +// See https://developercommunity.visualstudio.com/content/problem/1128631/code-flow-doesnt-see-noreturn-with-extern-c.html +// for why this is wrapped. Hopefully removable after msvc++ 19.27 is no longer supported. +[[noreturn]] static inline void sk_fast_fail() { __fastfail(FAST_FAIL_INVALID_ARG); } +# define SkUNREACHABLE sk_fast_fail() +# else +# define SkUNREACHABLE __builtin_trap() +# endif +#endif + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h new file mode 100644 index 0000000000000..34fdf0e09c92e --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h @@ -0,0 +1,102 @@ +/* + * 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 SkAttributes_DEFINED +#define SkAttributes_DEFINED + +#include "include/private/base/SkFeatures.h" // IWYU pragma: keep +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +#if defined(__clang__) || defined(__GNUC__) +# define SK_ATTRIBUTE(attr) __attribute__((attr)) +#else +# define SK_ATTRIBUTE(attr) +#endif + +#if !defined(SK_UNUSED) +# if !defined(__clang__) && defined(_MSC_VER) +# define SK_UNUSED __pragma(warning(suppress:4189)) +# else +# define SK_UNUSED SK_ATTRIBUTE(unused) +# endif +#endif + +#if !defined(SK_WARN_UNUSED_RESULT) + #define SK_WARN_UNUSED_RESULT SK_ATTRIBUTE(warn_unused_result) +#endif + +/** + * If your judgment is better than the compiler's (i.e. you've profiled it), + * you can use SK_ALWAYS_INLINE to force inlining. E.g. + * inline void someMethod() { ... } // may not be inlined + * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined + */ +#if !defined(SK_ALWAYS_INLINE) +# if defined(SK_BUILD_FOR_WIN) +# define SK_ALWAYS_INLINE __forceinline +# else +# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline +# endif +#endif + +/** + * If your judgment is better than the compiler's (i.e. you've profiled it), + * you can use SK_NEVER_INLINE to prevent inlining. + */ +#if !defined(SK_NEVER_INLINE) +# if defined(SK_BUILD_FOR_WIN) +# define SK_NEVER_INLINE __declspec(noinline) +# else +# define SK_NEVER_INLINE SK_ATTRIBUTE(noinline) +# endif +#endif + +/** + * Used to annotate a function as taking printf style arguments. + * `A` is the (1 based) index of the format string argument. + * `B` is the (1 based) index of the first argument used by the format string. + */ +#if !defined(SK_PRINTF_LIKE) +# define SK_PRINTF_LIKE(A, B) SK_ATTRIBUTE(format(printf, (A), (B))) +#endif + +/** + * Used to ignore sanitizer warnings. + */ +#if !defined(SK_NO_SANITIZE) +# define SK_NO_SANITIZE(A) SK_ATTRIBUTE(no_sanitize(A)) +#endif + +/** + * Helper macro to define no_sanitize attributes only with clang. + */ +#if defined(__clang__) && defined(__has_attribute) + #if __has_attribute(no_sanitize) + #define SK_CLANG_NO_SANITIZE(A) SK_NO_SANITIZE(A) + #endif +#endif + +#if !defined(SK_CLANG_NO_SANITIZE) + #define SK_CLANG_NO_SANITIZE(A) +#endif + +/** + * Annotates a class' non-trivial special functions as trivial for the purposes of calls. + * Allows a class with a non-trivial destructor to be __is_trivially_relocatable. + * Use of this attribute on a public API breaks platform ABI. + * Annotated classes may not hold pointers derived from `this`. + * Annotated classes must implement move+delete as equivalent to memcpy+free. + * Use may require more complete types, as callee destroys. + * + * https://clang.llvm.org/docs/AttributeReference.html#trivial-abi + * https://libcxx.llvm.org/DesignDocs/UniquePtrTrivialAbi.html + */ +#if !defined(SK_TRIVIAL_ABI) +# define SK_TRIVIAL_ABI +#endif + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h new file mode 100644 index 0000000000000..a5f60fd3ef191 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h @@ -0,0 +1,25 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkCPUTypes_DEFINED +#define SkCPUTypes_DEFINED + +// TODO(bungeman,kjlubick) There are a lot of assumptions throughout the codebase that +// these types are 32 bits, when they could be more or less. Public APIs should stop +// using these. Internally, we could use uint_fast8_t and uint_fast16_t, but not in +// public APIs due to ABI incompatibilities. + +/** Fast type for unsigned 8 bits. Use for parameter passing and local + variables, not for storage +*/ +typedef unsigned U8CPU; + +/** Fast type for unsigned 16 bits. Use for parameter passing and local + variables, not for storage +*/ +typedef unsigned U16CPU; + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h new file mode 100644 index 0000000000000..2ece73e28761b --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h @@ -0,0 +1,46 @@ +// 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 SkContainers_DEFINED +#define SkContainers_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkSpan_impl.h" + +#include +#include + +class SK_SPI SkContainerAllocator { +public: + SkContainerAllocator(size_t sizeOfT, int maxCapacity) + : fSizeOfT{sizeOfT} + , fMaxCapacity{maxCapacity} {} + + // allocate will abort on failure. Given a capacity of 0, it will return the empty span. + // The bytes allocated are freed using sk_free(). + SkSpan allocate(int capacity, double growthFactor = 1.0); + +private: + friend struct SkContainerAllocatorTestingPeer; + // All capacity counts will be rounded up to kCapacityMultiple. + // TODO: this is a constant from the original SkTArray code. This should be checked some how. + static constexpr int64_t kCapacityMultiple = 8; + + // Rounds up capacity to next multiple of kCapacityMultiple and pin to fMaxCapacity. + size_t roundUpCapacity(int64_t capacity) const; + + // Grows the capacity by growthFactor being sure to stay with in kMinBytes and fMaxCapacity. + size_t growthFactorCapacity(int capacity, double growthFactor) const; + + const size_t fSizeOfT; + const int64_t fMaxCapacity; +}; + +// sk_allocate_canfail returns the empty span on failure. Parameter size must be > 0. +SkSpan sk_allocate_canfail(size_t size); + +// Returns the empty span if size is 0. sk_allocate_throw aborts on failure. +SkSpan sk_allocate_throw(size_t size); + +SK_SPI void sk_report_container_overflow_and_die(); +#endif // SkContainers_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h new file mode 100644 index 0000000000000..2e4810fc1c961 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.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 SkDebug_DEFINED +#define SkDebug_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +#if !defined(SkDebugf) + void SK_SPI SkDebugf(const char format[], ...) SK_PRINTF_LIKE(1, 2); +#endif + +#if defined(SK_DEBUG) + #define SkDEBUGCODE(...) __VA_ARGS__ + #define SkDEBUGF(...) SkDebugf(__VA_ARGS__) +#else + #define SkDEBUGCODE(...) + #define SkDEBUGF(...) +#endif + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h similarity index 98% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h index 8adc39c1c71f2..fbc61673131b4 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h @@ -10,7 +10,9 @@ #ifndef SkDeque_DEFINED #define SkDeque_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" + +#include /* * The deque class works by blindly creating memory space of a specified element diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h new file mode 100644 index 0000000000000..662bf0321161e --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h @@ -0,0 +1,151 @@ +/* + * 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 SkFeatures_DEFINED +#define SkFeatures_DEFINED + +#if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && \ + !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) + + #ifdef __APPLE__ + #include + #endif + + #if defined(_WIN32) || defined(__SYMBIAN32__) + #define SK_BUILD_FOR_WIN + #elif defined(ANDROID) || defined(__ANDROID__) + #define SK_BUILD_FOR_ANDROID + #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || \ + defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || \ + defined(__DragonFly__) || defined(__Fuchsia__) || \ + defined(__GLIBC__) || defined(__GNU__) || defined(__unix__) + #define SK_BUILD_FOR_UNIX + #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR + #define SK_BUILD_FOR_IOS + #else + #define SK_BUILD_FOR_MAC + #endif +#endif // end SK_BUILD_FOR_* + + +#if defined(SK_BUILD_FOR_WIN) && !defined(__clang__) + #if !defined(SK_RESTRICT) + #define SK_RESTRICT __restrict + #endif + #if !defined(SK_WARN_UNUSED_RESULT) + #define SK_WARN_UNUSED_RESULT + #endif +#endif + +#if !defined(SK_RESTRICT) + #define SK_RESTRICT __restrict__ +#endif + +#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) + #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) + #define SK_CPU_BENDIAN + #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) + #define SK_CPU_LENDIAN + #elif defined(__sparc) || defined(__sparc__) || \ + defined(_POWER) || defined(__powerpc__) || \ + defined(__ppc__) || defined(__hppa) || \ + defined(__PPC__) || defined(__PPC64__) || \ + defined(_MIPSEB) || defined(__ARMEB__) || \ + defined(__s390__) || \ + (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ + (defined(__ia64) && defined(__BIG_ENDIAN__)) + #define SK_CPU_BENDIAN + #else + #define SK_CPU_LENDIAN + #endif +#endif + +#if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) + #define SK_CPU_X86 1 +#endif + +/** + * SK_CPU_SSE_LEVEL + * + * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. + * On non-intel CPU this should be undefined. + */ +#define SK_CPU_SSE_LEVEL_SSE1 10 +#define SK_CPU_SSE_LEVEL_SSE2 20 +#define SK_CPU_SSE_LEVEL_SSE3 30 +#define SK_CPU_SSE_LEVEL_SSSE3 31 +#define SK_CPU_SSE_LEVEL_SSE41 41 +#define SK_CPU_SSE_LEVEL_SSE42 42 +#define SK_CPU_SSE_LEVEL_AVX 51 +#define SK_CPU_SSE_LEVEL_AVX2 52 +#define SK_CPU_SSE_LEVEL_SKX 60 + +// TODO(brianosman,kjlubick) clean up these checks + +// Are we in GCC/Clang? +#ifndef SK_CPU_SSE_LEVEL + // These checks must be done in descending order to ensure we set the highest + // available SSE level. + #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ + defined(__AVX512BW__) && defined(__AVX512VL__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX + #elif defined(__AVX2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 + #elif defined(__AVX__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX + #elif defined(__SSE4_2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42 + #elif defined(__SSE4_1__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41 + #elif defined(__SSSE3__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 + #elif defined(__SSE3__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 + #elif defined(__SSE2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #endif +#endif + +// Are we in VisualStudio? +#ifndef SK_CPU_SSE_LEVEL + // These checks must be done in descending order to ensure we set the highest + // available SSE level. 64-bit intel guarantees at least SSE2 support. + #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ + defined(__AVX512BW__) && defined(__AVX512VL__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX + #elif defined(__AVX2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 + #elif defined(__AVX__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX + #elif defined(_M_X64) || defined(_M_AMD64) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #elif defined(_M_IX86_FP) + #if _M_IX86_FP >= 2 + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #elif _M_IX86_FP == 1 + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 + #endif + #endif +#endif + +// ARM defines +#if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) + #define SK_CPU_ARM32 +#elif defined(__aarch64__) + #define SK_CPU_ARM64 +#endif + +// All 64-bit ARM chips have NEON. Many 32-bit ARM chips do too. +#if !defined(SK_ARM_HAS_NEON) && defined(__ARM_NEON) + #define SK_ARM_HAS_NEON +#endif + +#if defined(__ARM_FEATURE_CRC32) + #define SK_ARM_HAS_CRC32 +#endif + +#endif // SkFeatures_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h similarity index 94% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h index e34c19f2ac867..2c8f2fb56c188 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h @@ -8,11 +8,12 @@ #ifndef SkFixed_DEFINED #define SkFixed_DEFINED -#include "include/core/SkScalar.h" -#include "include/core/SkTypes.h" -#include "include/private/SkSafe_math.h" -#include "include/private/SkTPin.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMath.h" // IWYU pragma: keep +#include "include/private/base/SkTPin.h" // IWYU pragma: keep + +#include /** \file SkFixed.h @@ -86,7 +87,6 @@ static inline SkFixed SkFixedFloorToFixed(SkFixed x) { return (SkFixed)( (uint32_t)x & 0xFFFF0000 ); } -#define SkFixedAbs(x) SkAbs32(x) #define SkFixedAve(a, b) (((a) + (b)) >> 1) // The divide may exceed 32 bits. Clamp to a signed 32 bit result. @@ -102,6 +102,8 @@ static inline SkFixed SkFixedMul(SkFixed a, SkFixed b) { // The VCVT float-to-fixed instruction is part of the VFPv3 instruction set. #if defined(__ARM_VFPV3__) + #include + /* This does not handle NaN or other obscurities, but is faster than than (int)(x*65536). When built on Android with -Os, needs forcing to inline or we lose the speed benefit. @@ -110,7 +112,7 @@ static inline SkFixed SkFixedMul(SkFixed a, SkFixed b) { { int32_t y; asm("vcvt.s32.f32 %0, %0, #16": "+w"(x)); - memcpy(&y, &x, sizeof(y)); + std::memcpy(&y, &x, sizeof(y)); return y; } #undef SkFloatToFixed diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h similarity index 96% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h index 89eea4b9e3495..37a7b271aee12 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h @@ -8,10 +8,9 @@ #ifndef SkFloatBits_DEFINED #define SkFloatBits_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkSafe_math.h" +#include "include/private/base/SkMath.h" -#include +#include /** Convert a sign-bit int (i.e. float interpreted as int) into a 2s compliement int. This also converts -0 (0x80000000) to 0. Doing this to a float allows diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h similarity index 89% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h index 8135abbfe1952..7aa8909f3a5eb 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h @@ -8,14 +8,14 @@ #ifndef SkFloatingPoint_DEFINED #define SkFloatingPoint_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkFloatBits.h" -#include "include/private/SkSafe_math.h" -#include -#include +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkFloatBits.h" +#include "include/private/base/SkMath.h" + +#include #include +#include #include -#include constexpr float SK_FloatSqrt2 = 1.41421356f; constexpr float SK_FloatPI = 3.14159265f; @@ -150,7 +150,7 @@ static inline int64_t sk_float_saturate2int64(float x) { // Cast double to float, ignoring any warning about too-large finite values being cast to float. // Clang thinks this is undefined, but it's actually implementation defined to return either // the largest float or infinity (one of the two bracketing representable floats). Good enough! -SK_ATTRIBUTE(no_sanitize("float-cast-overflow")) +SK_NO_SANITIZE("float-cast-overflow") static inline float sk_double_to_float(double x) { return static_cast(x); } @@ -196,12 +196,12 @@ static inline int sk_float_nextlog2(float x) { // IEEE defines how float divide behaves for non-finite values and zero-denoms, but C does not // so we have a helper that suppresses the possible undefined-behavior warnings. -SK_ATTRIBUTE(no_sanitize("float-divide-by-zero")) +SK_NO_SANITIZE("float-divide-by-zero") static inline float sk_ieee_float_divide(float numer, float denom) { return numer / denom; } -SK_ATTRIBUTE(no_sanitize("float-divide-by-zero")) +SK_NO_SANITIZE("float-divide-by-zero") static inline double sk_ieee_double_divide(double numer, double denom) { return numer / denom; } @@ -219,4 +219,13 @@ static inline float sk_fmaf(float f, float m, float a) { #endif } +// Returns true iff the provided number is within a small epsilon of 0. +bool sk_double_nearly_zero(double a); + +// Comparing floating point numbers is complicated. This helper only works if one or none +// of the two inputs is not very close to zero. It also does not work if both inputs could be NaN. +// The term "ulps" stands for "units of least precision". Read the following for more nuance: +// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ +bool sk_doubles_nearly_equal_ulps(double a, double b, uint8_t max_ulps_diff=16); + #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h new file mode 100644 index 0000000000000..b212ada86b0e5 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h @@ -0,0 +1,63 @@ +/* + * 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 SK_USER_CONFIG_WAS_LOADED + +// Include this to set reasonable defaults (e.g. for SK_CPU_LENDIAN) +#include "include/private/base/SkFeatures.h" + +// Allows embedders that want to disable macros that take arguments to just +// define that symbol to be one of these +#define SK_NOTHING_ARG1(arg1) +#define SK_NOTHING_ARG2(arg1, arg2) +#define SK_NOTHING_ARG3(arg1, arg2, arg3) + +// IWYU pragma: begin_exports + +// Note: SK_USER_CONFIG_HEADER will not work with Bazel builds and some C++ compilers. +#if defined(SK_USER_CONFIG_HEADER) + #include SK_USER_CONFIG_HEADER +#elif defined(SK_USE_BAZEL_CONFIG_HEADER) + // The Bazel config file is presumed to be in the root directory of its Bazel Workspace. + // This is achieved in Skia by having a nested WORKSPACE in include/config and a cc_library + // defined in that folder. As a result, we do not try to include SkUserConfig.h from the + // top of Skia because Bazel sandboxing will move it to a different location. + #include "SkUserConfig.h" +#else + #include "include/config/SkUserConfig.h" +#endif +// IWYU pragma: end_exports + +// Checks to make sure the SkUserConfig options do not conflict. +#if !defined(SK_DEBUG) && !defined(SK_RELEASE) + #ifdef NDEBUG + #define SK_RELEASE + #else + #define SK_DEBUG + #endif +#endif + +#if defined(SK_DEBUG) && defined(SK_RELEASE) +# error "cannot define both SK_DEBUG and SK_RELEASE" +#elif !defined(SK_DEBUG) && !defined(SK_RELEASE) +# error "must define either SK_DEBUG or SK_RELEASE" +#endif + +#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) +# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" +#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) +# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" +#endif + +#if defined(SK_CPU_BENDIAN) && !defined(I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN) + #error "The Skia team is not endian-savvy enough to support big-endian CPUs." + #error "If you still want to use Skia," + #error "please define I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN." +#endif + +#define SK_USER_CONFIG_WAS_LOADED +#endif // SK_USER_CONFIG_WAS_LOADED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h similarity index 77% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h index 308c5d05fd4a7..5d1835d013096 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h @@ -7,8 +7,6 @@ #ifndef SkMacros_DEFINED #define SkMacros_DEFINED -#include - /* * Usage: SK_MACRO_CONCAT(a, b) to construct the symbol ab * @@ -40,6 +38,23 @@ #define SK_END_REQUIRE_DENSE #endif +#if defined(__clang__) && defined(__has_feature) + // Some compilers have a preprocessor that does not appear to do short-circuit + // evaluation as expected + #if __has_feature(leak_sanitizer) || __has_feature(address_sanitizer) + // Chrome had issues if we tried to include lsan_interface.h ourselves. + // https://github.com/llvm/llvm-project/blob/10a35632d55bb05004fe3d0c2d4432bb74897ee7/compiler-rt/include/sanitizer/lsan_interface.h#L26 +extern "C" { + void __lsan_ignore_object(const void *p); +} + #define SK_INTENTIONALLY_LEAKED(X) __lsan_ignore_object(X) + #else + #define SK_INTENTIONALLY_LEAKED(X) ((void)0) + #endif +#else + #define SK_INTENTIONALLY_LEAKED(X) ((void)0) +#endif + #define SK_INIT_TO_AVOID_WARNING = 0 //////////////////////////////////////////////////////////////////////////////// diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h similarity index 94% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h index 206bf14e2f877..1c0c2e73da625 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h @@ -8,10 +8,9 @@ #ifndef SkMalloc_DEFINED #define SkMalloc_DEFINED -#include #include -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" /* memory wrappers to be implemented by the porting layer (platform) @@ -51,7 +50,9 @@ enum { SK_API extern void* sk_malloc_flags(size_t size, unsigned flags); /** Same as standard realloc(), but this one never returns null on failure. It will throw - * an exception if it fails. + * if it fails. + * If size is 0, it will call sk_free on buffer and return null. (This behavior is implementation- + * defined for normal realloc. We follow what glibc does.) */ SK_API extern void* sk_realloc_throw(void* buffer, size_t size); @@ -78,10 +79,6 @@ SK_API extern void* sk_calloc_throw(size_t count, size_t elemSize); SK_API extern void* sk_malloc_throw(size_t count, size_t elemSize); SK_API extern void* sk_realloc_throw(void* buffer, size_t count, size_t elemSize); -// Returns the true usable size provided by the underlying allocator, or 0 if -// querying the allocation size is not supported. -SK_API extern size_t sk_malloc_usable_size(void* buffer); - /** * These variants return nullptr on failure */ diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h similarity index 64% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h index 97352afab9d6f..34bfa739f7a97 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h @@ -8,7 +8,22 @@ #ifndef SkMath_DEFINED #define SkMath_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkCPUTypes.h" + +#include +#include + +// Max Signed 16 bit value +static constexpr int16_t SK_MaxS16 = INT16_MAX; +static constexpr int16_t SK_MinS16 = -SK_MaxS16; + +static constexpr int32_t SK_MaxS32 = INT32_MAX; +static constexpr int32_t SK_MinS32 = -SK_MaxS32; +static constexpr int32_t SK_NaN32 = INT32_MIN; + +static constexpr int64_t SK_MaxS64 = INT64_MAX; +static constexpr int64_t SK_MinS64 = -SK_MaxS64; // 64bit -> 32bit utilities @@ -19,6 +34,14 @@ static inline int64_t sk_64_mul(int64_t a, int64_t b) { return a * b; } +static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { + return (int32_t) ((uint32_t) value << shift); +} + +static inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) { + return (int64_t) ((uint64_t) value << shift); +} + /////////////////////////////////////////////////////////////////////////////// /** @@ -48,7 +71,7 @@ static inline unsigned SkMul16ShiftRound(U16CPU a, U16CPU b, int shift) { * Only valid if a and b are unsigned and <= 32767. */ static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { - return SkMul16ShiftRound(a,b,8); + return SkMul16ShiftRound(a, b, 8); } #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h similarity index 86% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h index b7cdceb1e1d8d..4452beb912f56 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h @@ -8,11 +8,11 @@ #ifndef SkMutex_DEFINED #define SkMutex_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMacros.h" -#include "include/private/SkSemaphore.h" -#include "include/private/SkThreadAnnotations.h" -#include "include/private/SkThreadID.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkSemaphore.h" +#include "include/private/base/SkThreadAnnotations.h" +#include "include/private/base/SkThreadID.h" class SK_CAPABILITY("mutex") SkMutex { public: diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h similarity index 89% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h index bda5d50bb6804..ec4a4e5161199 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h @@ -8,9 +8,9 @@ #ifndef SkNoncopyable_DEFINED #define SkNoncopyable_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" -/** \class SkNoncopyable +/** \class SkNoncopyable (DEPRECATED) SkNoncopyable is the base class for objects that do not want to be copied. It hides its copy-constructor and its assignment-operator. diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h similarity index 96% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h index edf3e833582b5..97ce6b6311e0b 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h @@ -8,8 +8,10 @@ #ifndef SkOnce_DEFINED #define SkOnce_DEFINED -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkThreadAnnotations.h" + #include +#include #include // SkOnce provides call-once guarantees for Skia, much like std::once_flag/std::call_once(). diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h new file mode 100644 index 0000000000000..642bbb3489f7e --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h @@ -0,0 +1,25 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * This file contains private enums related to paths. See also skbug.com/10670 + */ + +#ifndef SkPathEnums_DEFINED +#define SkPathEnums_DEFINED + +enum class SkPathConvexity { + kConvex, + kConcave, + kUnknown, +}; + +enum class SkPathFirstDirection { + kCW, // == SkPathDirection::kCW + kCCW, // == SkPathDirection::kCCW + kUnknown, +}; + +#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h similarity index 64% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h index 7e59f2b0040ad..5ba4c2f9a48e2 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h @@ -8,7 +8,10 @@ #ifndef SkSafe32_DEFINED #define SkSafe32_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkMath.h" + +#include static constexpr int32_t Sk64_pin_to_s32(int64_t x) { return x < SK_MinS32 ? SK_MinS32 : (x > SK_MaxS32 ? SK_MaxS32 : (int32_t)x); @@ -31,4 +34,16 @@ static constexpr int32_t Sk32_can_overflow_sub(int32_t a, int32_t b) { return (int32_t)((uint32_t)a - (uint32_t)b); } +/** + * This is a 'safe' abs for 32-bit integers that asserts when undefined behavior would occur. + * SkTAbs (in SkTemplates.h) is a general purpose absolute-value function. + */ +static inline int32_t SkAbs32(int32_t value) { + SkASSERT(value != SK_NaN32); // The most negative int32_t can't be negated. + if (value < 0) { + value = -value; + } + return value; +} + #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h similarity index 95% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h index d7318be577919..f78ee86625a42 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h @@ -8,9 +8,10 @@ #ifndef SkSemaphore_DEFINED #define SkSemaphore_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkOnce.h" -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkThreadAnnotations.h" + #include #include diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h new file mode 100644 index 0000000000000..5f31a651bb375 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h @@ -0,0 +1,129 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkSpan_DEFINED +#define SkSpan_DEFINED + +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTo.h" + +#include +#include +#include +#include +#include + +// Having this be an export works around IWYU churn related to +// https://github.com/include-what-you-use/include-what-you-use/issues/1121 +#include // IWYU pragma: export + +// Add macro to check the lifetime of initializer_list arguments. initializer_list has a very +// short life span, and can only be used as a parameter, and not as a variable. +#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::lifetimebound) +#define SK_CHECK_IL_LIFETIME [[clang::lifetimebound]] +#else +#define SK_CHECK_IL_LIFETIME +#endif + +/** + * SkSpan holds a reference to contiguous data of type T along with a count. SkSpan does not own + * the data itself but is merely a reference, therefore you must take care with the lifetime of + * the underlying data. + * + * SkSpan is a count and a pointer into existing array or data type that stores its data in + * contiguous memory like std::vector. Any container that works with std::size() and std::data() + * can be used. + * + * SkSpan makes a convenient parameter for a routine to accept array like things. This allows you to + * write the routine without overloads for all different container types. + * + * Example: + * void routine(SkSpan a) { ... } + * + * std::vector v = {1, 2, 3, 4, 5}; + * + * routine(a); + * + * A word of caution when working with initializer_list, initializer_lists have a lifetime that is + * limited to the current statement. The following is correct and safe: + * + * Example: + * routine({1,2,3,4,5}); + * + * The following is undefined, and will result in erratic execution: + * + * Bad Example: + * initializer_list l = {1, 2, 3, 4, 5}; // The data behind l dies at the ;. + * routine(l); + */ +template +class SkSpan { +public: + constexpr SkSpan() : fPtr{nullptr}, fSize{0} {} + + template , bool> = true> + constexpr SkSpan(T* ptr, Integer size) : fPtr{ptr}, fSize{SkToSizeT(size)} { + SkASSERT(ptr || fSize == 0); // disallow nullptr + a nonzero size + SkASSERT(fSize < kMaxSize); + } + template >> + constexpr SkSpan(const SkSpan& that) : fPtr(std::data(that)), fSize(std::size(that)) {} + constexpr SkSpan(const SkSpan& o) = default; + template constexpr SkSpan(T(&a)[N]) : SkSpan(a, N) { } + template + constexpr SkSpan(Container& c) : SkSpan(std::data(c), std::size(c)) { } + SkSpan(std::initializer_list il SK_CHECK_IL_LIFETIME) + : SkSpan(std::data(il), std::size(il)) {} + + constexpr SkSpan& operator=(const SkSpan& that) = default; + + constexpr T& operator [] (size_t i) const { + SkASSERT(i < this->size()); + return fPtr[i]; + } + constexpr T& front() const { return fPtr[0]; } + constexpr T& back() const { return fPtr[fSize - 1]; } + constexpr T* begin() const { return fPtr; } + constexpr T* end() const { return fPtr + fSize; } + constexpr auto rbegin() const { return std::make_reverse_iterator(this->end()); } + constexpr auto rend() const { return std::make_reverse_iterator(this->begin()); } + constexpr T* data() const { return this->begin(); } + constexpr size_t size() const { return fSize; } + constexpr bool empty() const { return fSize == 0; } + constexpr size_t size_bytes() const { return fSize * sizeof(T); } + constexpr SkSpan first(size_t prefixLen) const { + SkASSERT(prefixLen <= this->size()); + return SkSpan{fPtr, prefixLen}; + } + constexpr SkSpan last(size_t postfixLen) const { + SkASSERT(postfixLen <= this->size()); + return SkSpan{fPtr + (this->size() - postfixLen), postfixLen}; + } + constexpr SkSpan subspan(size_t offset) const { + return this->subspan(offset, this->size() - offset); + } + constexpr SkSpan subspan(size_t offset, size_t count) const { + SkASSERT(offset <= this->size()); + SkASSERT(count <= this->size() - offset); + return SkSpan{fPtr + offset, count}; + } + +private: + static const constexpr size_t kMaxSize = std::numeric_limits::max() / sizeof(T); + T* fPtr; + size_t fSize; +}; + +template +SkSpan(Container&) -> + SkSpan()))>>; + +template +SkSpan(std::initializer_list) -> + SkSpan>()))>>; + +#endif // SkSpan_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h new file mode 100644 index 0000000000000..de8e276513b2e --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h @@ -0,0 +1,694 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkTArray_DEFINED +#define SkTArray_DEFINED + +#include "include/private/base/SkAlignedStorage.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkContainers.h" +#include "include/private/base/SkMalloc.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkSpan_impl.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" // IWYU pragma: keep + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace skia_private { +/** TArray implements a typical, mostly std::vector-like array. + Each T will be default-initialized on allocation, and ~T will be called on destruction. + + MEM_MOVE controls the behavior when a T needs to be moved (e.g. when the array is resized) + - true: T will be bit-copied via memcpy. + - false: T will be moved via move-constructors. +*/ +template > class TArray { +public: + using value_type = T; + + /** + * Creates an empty array with no initial storage + */ + TArray() : fOwnMemory(true), fCapacity{0} {} + + /** + * Creates an empty array that will preallocate space for reserveCount + * elements. + */ + explicit TArray(int reserveCount) : TArray() { this->reserve_back(reserveCount); } + + /** + * Copies one array to another. The new array will be heap allocated. + */ + TArray(const TArray& that) : TArray(that.fData, that.fSize) {} + + TArray(TArray&& that) { + if (that.fOwnMemory) { + this->setData(that); + that.setData({}); + } else { + this->initData(that.fSize); + that.move(fData); + } + fSize = std::exchange(that.fSize, 0); + } + + /** + * Creates a TArray by copying contents of a standard C array. The new + * array will be heap allocated. Be careful not to use this constructor + * when you really want the (void*, int) version. + */ + TArray(const T* array, int count) { + this->initData(count); + this->copy(array); + } + + /** + * Creates a TArray by copying contents of an initializer list. + */ + TArray(std::initializer_list data) : TArray(data.begin(), data.size()) {} + + TArray& operator=(const TArray& that) { + if (this == &that) { + return *this; + } + this->clear(); + this->checkRealloc(that.size(), kExactFit); + fSize = that.fSize; + this->copy(that.fData); + return *this; + } + TArray& operator=(TArray&& that) { + if (this != &that) { + this->clear(); + if (that.fOwnMemory) { + // The storage is on the heap, so move the data pointer. + if (fOwnMemory) { + sk_free(fData); + } + + fData = std::exchange(that.fData, nullptr); + + // Can't use exchange with bitfields. + fCapacity = that.fCapacity; + that.fCapacity = 0; + + fOwnMemory = true; + } else { + // The data is stored inline in that, so move it element-by-element. + this->checkRealloc(that.size(), kExactFit); + that.move(fData); + } + fSize = std::exchange(that.fSize, 0); + } + return *this; + } + + ~TArray() { + this->destroyAll(); + if (fOwnMemory) { + sk_free(fData); + } + } + + /** + * Resets to size() = n newly constructed T objects and resets any reserve count. + */ + void reset(int n) { + SkASSERT(n >= 0); + this->clear(); + this->checkRealloc(n, kExactFit); + fSize = n; + for (int i = 0; i < this->size(); ++i) { + new (fData + i) T; + } + } + + /** + * Resets to a copy of a C array and resets any reserve count. + */ + void reset(const T* array, int count) { + SkASSERT(count >= 0); + this->clear(); + this->checkRealloc(count, kExactFit); + fSize = count; + this->copy(array); + } + + /** + * Ensures there is enough reserved space for n elements. + */ + void reserve(int n) { + SkASSERT(n >= 0); + if (n > this->size()) { + this->checkRealloc(n - this->size(), kGrowing); + } + } + + /** + * Ensures there is enough reserved space for n additional elements. The is guaranteed at least + * until the array size grows above n and subsequently shrinks below n, any version of reset() + * is called, or reserve_back() is called again. + */ + void reserve_back(int n) { + SkASSERT(n >= 0); + if (n > 0) { + this->checkRealloc(n, kExactFit); + } + } + + void removeShuffle(int n) { + SkASSERT(n < this->size()); + int newCount = fSize - 1; + fSize = newCount; + fData[n].~T(); + if (n != newCount) { + this->move(n, newCount); + } + } + + // Is the array empty. + bool empty() const { return fSize == 0; } + + /** + * Adds 1 new default-initialized T value and returns it by reference. Note + * the reference only remains valid until the next call that adds or removes + * elements. + */ + T& push_back() { + void* newT = this->push_back_raw(1); + return *new (newT) T; + } + + /** + * Version of above that uses a copy constructor to initialize the new item + */ + T& push_back(const T& t) { + void* newT = this->push_back_raw(1); + return *new (newT) T(t); + } + + /** + * Version of above that uses a move constructor to initialize the new item + */ + T& push_back(T&& t) { + void* newT = this->push_back_raw(1); + return *new (newT) T(std::move(t)); + } + + /** + * Construct a new T at the back of this array. + */ + template T& emplace_back(Args&&... args) { + void* newT = this->push_back_raw(1); + return *new (newT) T(std::forward(args)...); + } + + /** + * Allocates n more default-initialized T values, and returns the address of + * the start of that new range. Note: this address is only valid until the + * next API call made on the array that might add or remove elements. + */ + T* push_back_n(int n) { + SkASSERT(n >= 0); + T* newTs = TCast(this->push_back_raw(n)); + for (int i = 0; i < n; ++i) { + new (&newTs[i]) T; + } + return newTs; + } + + /** + * Version of above that uses a copy constructor to initialize all n items + * to the same T. + */ + T* push_back_n(int n, const T& t) { + SkASSERT(n >= 0); + T* newTs = TCast(this->push_back_raw(n)); + for (int i = 0; i < n; ++i) { + new (&newTs[i]) T(t); + } + return static_cast(newTs); + } + + /** + * Version of above that uses a copy constructor to initialize the n items + * to separate T values. + */ + T* push_back_n(int n, const T t[]) { + SkASSERT(n >= 0); + this->checkRealloc(n, kGrowing); + T* end = this->end(); + for (int i = 0; i < n; ++i) { + new (end + i) T(t[i]); + } + fSize += n; + return end; + } + + /** + * Version of above that uses the move constructor to set n items. + */ + T* move_back_n(int n, T* t) { + SkASSERT(n >= 0); + this->checkRealloc(n, kGrowing); + T* end = this->end(); + for (int i = 0; i < n; ++i) { + new (end + i) T(std::move(t[i])); + } + fSize += n; + return end; + } + + /** + * Removes the last element. Not safe to call when size() == 0. + */ + void pop_back() { + SkASSERT(fSize > 0); + --fSize; + fData[fSize].~T(); + } + + /** + * Removes the last n elements. Not safe to call when size() < n. + */ + void pop_back_n(int n) { + SkASSERT(n >= 0); + SkASSERT(this->size() >= n); + int i = fSize; + while (i-- > fSize - n) { + (*this)[i].~T(); + } + fSize -= n; + } + + /** + * Pushes or pops from the back to resize. Pushes will be default + * initialized. + */ + void resize_back(int newCount) { + SkASSERT(newCount >= 0); + + if (newCount > this->size()) { + this->push_back_n(newCount - fSize); + } else if (newCount < this->size()) { + this->pop_back_n(fSize - newCount); + } + } + + /** Swaps the contents of this array with that array. Does a pointer swap if possible, + otherwise copies the T values. */ + void swap(TArray& that) { + using std::swap; + if (this == &that) { + return; + } + if (fOwnMemory && that.fOwnMemory) { + swap(fData, that.fData); + swap(fSize, that.fSize); + + // Can't use swap because fCapacity is a bit field. + auto allocCount = fCapacity; + fCapacity = that.fCapacity; + that.fCapacity = allocCount; + } else { + // This could be more optimal... + TArray copy(std::move(that)); + that = std::move(*this); + *this = std::move(copy); + } + } + + T* begin() { + return fData; + } + const T* begin() const { + return fData; + } + + // It's safe to use fItemArray + fSize because if fItemArray is nullptr then adding 0 is + // valid and returns nullptr. See [expr.add] in the C++ standard. + T* end() { + if (fData == nullptr) { + SkASSERT(fSize == 0); + } + return fData + fSize; + } + const T* end() const { + if (fData == nullptr) { + SkASSERT(fSize == 0); + } + return fData + fSize; + } + T* data() { return fData; } + const T* data() const { return fData; } + int size() const { return fSize; } + size_t size_bytes() const { return this->bytes(fSize); } + void resize(size_t count) { this->resize_back((int)count); } + + void clear() { + this->destroyAll(); + fSize = 0; + } + + void shrink_to_fit() { + if (!fOwnMemory || fSize == fCapacity) { + return; + } + if (fSize == 0) { + sk_free(fData); + fData = nullptr; + fCapacity = 0; + } else { + SkSpan allocation = Allocate(fSize); + this->move(TCast(allocation.data())); + if (fOwnMemory) { + sk_free(fData); + } + this->setDataFromBytes(allocation); + } + } + + /** + * Get the i^th element. + */ + T& operator[] (int i) { + SkASSERT(i < this->size()); + SkASSERT(i >= 0); + return fData[i]; + } + + const T& operator[] (int i) const { + SkASSERT(i < this->size()); + SkASSERT(i >= 0); + return fData[i]; + } + + T& at(int i) { return (*this)[i]; } + const T& at(int i) const { return (*this)[i]; } + + /** + * equivalent to operator[](0) + */ + T& front() { SkASSERT(fSize > 0); return fData[0];} + + const T& front() const { SkASSERT(fSize > 0); return fData[0];} + + /** + * equivalent to operator[](size() - 1) + */ + T& back() { SkASSERT(fSize); return fData[fSize - 1];} + + const T& back() const { SkASSERT(fSize > 0); return fData[fSize - 1];} + + /** + * equivalent to operator[](size()-1-i) + */ + T& fromBack(int i) { + SkASSERT(i >= 0); + SkASSERT(i < this->size()); + return fData[fSize - i - 1]; + } + + const T& fromBack(int i) const { + SkASSERT(i >= 0); + SkASSERT(i < this->size()); + return fData[fSize - i - 1]; + } + + bool operator==(const TArray& right) const { + int leftCount = this->size(); + if (leftCount != right.size()) { + return false; + } + for (int index = 0; index < leftCount; ++index) { + if (fData[index] != right.fData[index]) { + return false; + } + } + return true; + } + + bool operator!=(const TArray& right) const { + return !(*this == right); + } + + int capacity() const { + return fCapacity; + } + +protected: + // Creates an empty array that will use the passed storage block until it is insufficiently + // large to hold the entire array. + template + TArray(SkAlignedSTStorage* storage, int size = 0) { + static_assert(InitialCapacity >= 0); + SkASSERT(size >= 0); + SkASSERT(storage->get() != nullptr); + if (size > InitialCapacity) { + this->initData(size); + } else { + this->setDataFromBytes(*storage); + fSize = size; + + // setDataFromBytes always sets fOwnMemory to true, but we are actually using static + // storage here, which shouldn't ever be freed. + fOwnMemory = false; + } + } + + // Copy a C array, using pre-allocated storage if preAllocCount >= count. Otherwise, storage + // will only be used when array shrinks to fit. + template + TArray(const T* array, int size, SkAlignedSTStorage* storage) + : TArray{storage, size} + { + this->copy(array); + } + +private: + // Growth factors for checkRealloc. + static constexpr double kExactFit = 1.0; + static constexpr double kGrowing = 1.5; + + static constexpr int kMinHeapAllocCount = 8; + static_assert(SkIsPow2(kMinHeapAllocCount), "min alloc count not power of two."); + + // Note for 32-bit machines kMaxCapacity will be <= SIZE_MAX. For 64-bit machines it will + // just be INT_MAX if the sizeof(T) < 2^32. + static constexpr int kMaxCapacity = SkToInt(std::min(SIZE_MAX / sizeof(T), (size_t)INT_MAX)); + + void setDataFromBytes(SkSpan allocation) { + T* data = TCast(allocation.data()); + // We have gotten extra bytes back from the allocation limit, pin to kMaxCapacity. It + // would seem like the SkContainerAllocator should handle the divide, but it would have + // to a full divide instruction. If done here the size is known at compile, and usually + // can be implemented by a right shift. The full divide takes ~50X longer than the shift. + size_t size = std::min(allocation.size() / sizeof(T), SkToSizeT(kMaxCapacity)); + setData(SkSpan(data, size)); + } + + void setData(SkSpan array) { + fData = array.data(); + fCapacity = SkToU32(array.size()); + fOwnMemory = true; + } + + // We disable Control-Flow Integrity sanitization (go/cfi) when casting item-array buffers. + // CFI flags this code as dangerous because we are casting `buffer` to a T* while the buffer's + // contents might still be uninitialized memory. When T has a vtable, this is especially risky + // because we could hypothetically access a virtual method on fItemArray and jump to an + // unpredictable location in memory. Of course, TArray won't actually use fItemArray in this + // way, and we don't want to construct a T before the user requests one. There's no real risk + // here, so disable CFI when doing these casts. + SK_CLANG_NO_SANITIZE("cfi") + static T* TCast(void* buffer) { + return (T*)buffer; + } + + size_t bytes(int n) const { + SkASSERT(n <= kMaxCapacity); + return SkToSizeT(n) * sizeof(T); + } + + static SkSpan Allocate(int capacity, double growthFactor = 1.0) { + return SkContainerAllocator{sizeof(T), kMaxCapacity}.allocate(capacity, growthFactor); + } + + void initData(int count) { + this->setDataFromBytes(Allocate(count)); + fSize = count; + } + + void destroyAll() { + if (!this->empty()) { + T* cursor = this->begin(); + T* const end = this->end(); + do { + cursor->~T(); + cursor++; + } while (cursor < end); + } + } + + /** In the following move and copy methods, 'dst' is assumed to be uninitialized raw storage. + * In the following move methods, 'src' is destroyed leaving behind uninitialized raw storage. + */ + void copy(const T* src) { + if constexpr (std::is_trivially_copyable_v) { + if (!this->empty() && src != nullptr) { + sk_careful_memcpy(fData, src, this->size_bytes()); + } + } else { + for (int i = 0; i < this->size(); ++i) { + new (fData + i) T(src[i]); + } + } + } + + void move(int dst, int src) { + if constexpr (MEM_MOVE) { + memcpy(static_cast(&fData[dst]), + static_cast(&fData[src]), + sizeof(T)); + } else { + new (&fData[dst]) T(std::move(fData[src])); + fData[src].~T(); + } + } + + void move(void* dst) { + if constexpr (MEM_MOVE) { + sk_careful_memcpy(dst, fData, this->bytes(fSize)); + } else { + for (int i = 0; i < this->size(); ++i) { + new (static_cast(dst) + this->bytes(i)) T(std::move(fData[i])); + fData[i].~T(); + } + } + } + + // Helper function that makes space for n objects, adjusts the count, but does not initialize + // the new objects. + void* push_back_raw(int n) { + this->checkRealloc(n, kGrowing); + void* ptr = fData + fSize; + fSize += n; + return ptr; + } + + void checkRealloc(int delta, double growthFactor) { + // This constant needs to be declared in the function where it is used to work around + // MSVC's persnickety nature about template definitions. + SkASSERT(delta >= 0); + SkASSERT(fSize >= 0); + SkASSERT(fCapacity >= 0); + + // Return if there are enough remaining allocated elements to satisfy the request. + if (this->capacity() - fSize >= delta) { + return; + } + + // Don't overflow fSize or size_t later in the memory allocation. Overflowing memory + // allocation really only applies to fSizes on 32-bit machines; on 64-bit machines this + // will probably never produce a check. Since kMaxCapacity is bounded above by INT_MAX, + // this also checks the bounds of fSize. + if (delta > kMaxCapacity - fSize) { + sk_report_container_overflow_and_die(); + } + const int newCount = fSize + delta; + + SkSpan allocation = Allocate(newCount, growthFactor); + + this->move(TCast(allocation.data())); + if (fOwnMemory) { + sk_free(fData); + } + this->setDataFromBytes(allocation); + SkASSERT(this->capacity() >= newCount); + SkASSERT(fData != nullptr); + } + + T* fData{nullptr}; + int fSize{0}; + uint32_t fOwnMemory : 1; + uint32_t fCapacity : 31; +}; + +template static inline void swap(TArray& a, TArray& b) { + a.swap(b); +} + +// Subclass of TArray that contains a pre-allocated memory block for the array. +template > +class STArray : private SkAlignedSTStorage, public TArray { + static_assert(N > 0); + using Storage = SkAlignedSTStorage; + +public: + STArray() + : Storage{} + , TArray(this) {} // Must use () to avoid confusion with initializer_list + // when T=bool because * are convertable to bool. + + STArray(const T* array, int count) + : Storage{} + , TArray{array, count, this} {} + + STArray(std::initializer_list data) + : STArray{data.begin(), SkToInt(data.size())} {} + + explicit STArray(int reserveCount) + : STArray() { this->reserve_back(reserveCount); } + + STArray(const STArray& that) + : STArray() { *this = that; } + + explicit STArray(const TArray& that) + : STArray() { *this = that; } + + STArray(STArray&& that) + : STArray() { *this = std::move(that); } + + explicit STArray(TArray&& that) + : STArray() { *this = std::move(that); } + + STArray& operator=(const STArray& that) { + TArray::operator=(that); + return *this; + } + + STArray& operator=(const TArray& that) { + TArray::operator=(that); + return *this; + } + + STArray& operator=(STArray&& that) { + TArray::operator=(std::move(that)); + return *this; + } + + STArray& operator=(TArray&& that) { + TArray::operator=(std::move(that)); + return *this; + } + + // Force the use of TArray for data() and size(). + using TArray::data; + using TArray::size; +}; +} // namespace skia_private +#endif // SkTArray_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h similarity index 81% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h index 1b56266535a56..b08d285378b10 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h @@ -8,21 +8,18 @@ #ifndef SkTDArray_DEFINED #define SkTDArray_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTo.h" #include #include -#include #include -#include -#include class SK_SPI SkTDStorage { public: explicit SkTDStorage(int sizeOfT); - SkTDStorage(const void* src, int count, int sizeOfT); + SkTDStorage(const void* src, int size, int sizeOfT); // Copy SkTDStorage(const SkTDStorage& that); @@ -38,15 +35,15 @@ class SK_SPI SkTDStorage { void swap(SkTDStorage& that); // Size routines - bool empty() const { return fCount == 0; } - void clear() { fCount = 0; } - int size() const { return fCount; } - void resize(int newCount); - size_t size_bytes() const { return this->bytes(fCount); } + bool empty() const { return fSize == 0; } + void clear() { fSize = 0; } + int size() const { return fSize; } + void resize(int newSize); + size_t size_bytes() const { return this->bytes(fSize); } // Capacity routines - int capacity() const { return fReserve; } - void reserve(int newReserve); + int capacity() const { return fCapacity; } + void reserve(int newCapacity); void shrink_to_fit(); void* data() { return fStorage; } @@ -68,8 +65,8 @@ class SK_SPI SkTDStorage { void* insert(int index, int count, const void* src); void pop_back() { - SkASSERT(fCount > 0); - fCount--; + SkASSERT(fSize > 0); + fSize--; } friend bool operator==(const SkTDStorage& a, const SkTDStorage& b); @@ -81,7 +78,7 @@ class SK_SPI SkTDStorage { size_t bytes(int n) const { return SkToSizeT(n * fSizeOfT); } void* address(int n) { return fStorage + this->bytes(n); } - // Adds delta to fCount. Crash if outside [0, INT_MAX] + // Adds delta to fSize. Crash if outside [0, INT_MAX] int calculateSizeOrDie(int delta); // Move the tail of the array defined by the indexes tailStart and tailEnd to dstIndex. The @@ -93,8 +90,8 @@ class SK_SPI SkTDStorage { const int fSizeOfT; std::byte* fStorage{nullptr}; - int fReserve{0}; // size of the allocation in fArray (#elements) - int fCount{0}; // logical number of elements (fCount <= fReserve) + int fCapacity{0}; // size of the allocation in fArray (#elements) + int fSize{0}; // logical number of elements (fSize <= fCapacity) }; static inline void swap(SkTDStorage& a, SkTDStorage& b) { @@ -188,7 +185,7 @@ template class SkTDArray { fStorage.resize(count); } - void reserve(size_t n) { + void reserve(int n) { fStorage.reserve(n); } @@ -219,18 +216,6 @@ template class SkTDArray { fStorage.removeShuffle(index); } - int find(const T& elem) const { - const T* iter = this->begin(); - const T* stop = this->end(); - - for (; iter < stop; iter++) { - if (*iter == elem) { - return SkToInt(iter - this->begin()); - } - } - return -1; - } - // routines to treat the array like a stack void push_back(const T& v) { this->append(); @@ -238,28 +223,6 @@ template class SkTDArray { } void pop_back() { fStorage.pop_back(); } - void deleteAll() { - for (T p : *this) { - delete p; - } - this->reset(); - } - - void freeAll() { - for (T p : *this) { - sk_free(p); - } - - this->reset(); - } - - void unrefAll() { - for (T p : *this) { - p->unref(); - } - this->reset(); - } - void shrink_to_fit() { fStorage.shrink_to_fit(); } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h similarity index 82% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h index a912f13e08c01..365748abef483 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h @@ -8,8 +8,10 @@ #ifndef SkTFitsIn_DEFINED #define SkTFitsIn_DEFINED +#include "include/private/base/SkDebug.h" + +#include #include -#include #include /** @@ -71,28 +73,32 @@ static constexpr inline typename std::enable_if<(std::is_integral::value || std::is_enum::value) && (std::is_integral::value || std::is_enum::value), bool>::type /*bool*/ SkTFitsIn(S src) { + // Ensure that is_signed and is_unsigned are passed the arithmetic underlyng types of enums. + using Sa = typename sk_strip_enum::type; + using Da = typename sk_strip_enum::type; + // SkTFitsIn() is used in public headers, so needs to be written targeting at most C++11. return // E.g. (int8_t)(uint8_t) int8_t(-1) == -1, but the uint8_t == 255, not -1. - (std::is_signed::value && std::is_unsigned::value && sizeof(S) <= sizeof(D)) ? + (std::is_signed::value && std::is_unsigned::value && sizeof(Sa) <= sizeof(Da)) ? (S)0 <= src : // E.g. (uint8_t)(int8_t) uint8_t(255) == 255, but the int8_t == -1. - (std::is_signed::value && std::is_unsigned::value && sizeof(D) <= sizeof(S)) ? - src <= (S)std::numeric_limits::type>::max() : + (std::is_signed::value && std::is_unsigned::value && sizeof(Da) <= sizeof(Sa)) ? + src <= (S)std::numeric_limits::max() : #if !defined(SK_DEBUG) && !defined(__MSVC_RUNTIME_CHECKS ) // Correct (simple) version. This trips up MSVC's /RTCc run-time checking. (S)(D)src == src; #else // More complex version that's safe with /RTCc. Used in all debug builds, for coverage. - (std::is_signed::value) ? - (intmax_t)src >= (intmax_t)std::numeric_limits::type>::min() && - (intmax_t)src <= (intmax_t)std::numeric_limits::type>::max() : + (std::is_signed::value) ? + (intmax_t)src >= (intmax_t)std::numeric_limits::min() && + (intmax_t)src <= (intmax_t)std::numeric_limits::max() : // std::is_unsigned ? - (uintmax_t)src <= (uintmax_t)std::numeric_limits::type>::max(); + (uintmax_t)src <= (uintmax_t)std::numeric_limits::max(); #endif } diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h similarity index 98% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h index dce0dc804becd..26f363c94699e 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h @@ -14,7 +14,7 @@ #include #include -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" // The sknonstd namespace contains things we would like to be proposed and feel std-ish. namespace sknonstd { diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTPin.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTPin.h similarity index 100% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTPin.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTPin.h diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h similarity index 73% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h index 16b0e0e586a29..cbcf36c5943b8 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h @@ -8,18 +8,21 @@ #ifndef SkTemplates_DEFINED #define SkTemplates_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkAlign.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMalloc.h" +#include "include/private/base/SkTLogic.h" -#include #include #include +#include +#include #include -#include #include #include + /** \file SkTemplates.h This file contains light-weight template classes for type-safe and exception-safe @@ -32,6 +35,17 @@ */ template inline void sk_ignore_unused_variable(const T&) { } +/** + * This is a general purpose absolute-value function. + * See SkAbs32 in (SkSafe32.h) for a 32-bit int specific version that asserts. + */ +template static inline T SkTAbs(T value) { + if (value < 0) { + value = -value; + } + return value; +} + /** * Returns a pointer to a D which comes immediately after S[count]. */ @@ -48,14 +62,16 @@ template inline D* SkTAddOffset(S* ptr, ptrdiff_t byteO return reinterpret_cast(reinterpret_cast*>(ptr) + byteOffset); } -// TODO: when C++17 the language is available, use template -template struct SkFunctionWrapper { +template struct SkOverloadedFunctionObject { template auto operator()(Args&&... args) const -> decltype(P(std::forward(args)...)) { return P(std::forward(args)...); } }; +template using SkFunctionObject = + SkOverloadedFunctionObject, F>; + /** \class SkAutoTCallVProc Call a function when this goes out of scope. The template uses two @@ -65,8 +81,8 @@ template struct SkFunctionWrapper { function. */ template class SkAutoTCallVProc - : public std::unique_ptr, P>> { - using inherited = std::unique_ptr, P>>; + : public std::unique_ptr> { + using inherited = std::unique_ptr>; public: using inherited::inherited; SkAutoTCallVProc(const SkAutoTCallVProc&) = delete; @@ -75,14 +91,16 @@ template class SkAutoTCallVProc operator T*() const { return this->get(); } }; + +namespace skia_private { /** Allocate an array of T elements, and free the array in the destructor */ -template class SkAutoTArray { +template class AutoTArray { public: - SkAutoTArray() {} + AutoTArray() {} /** Allocate count number of T elements */ - explicit SkAutoTArray(int count) { + explicit AutoTArray(int count) { SkASSERT(count >= 0); if (count) { fArray.reset(new T[count]); @@ -90,10 +108,10 @@ template class SkAutoTArray { SkDEBUGCODE(fCount = count;) } - SkAutoTArray(SkAutoTArray&& other) : fArray(std::move(other.fArray)) { + AutoTArray(AutoTArray&& other) : fArray(std::move(other.fArray)) { SkDEBUGCODE(fCount = other.fCount; other.fCount = 0;) } - SkAutoTArray& operator=(SkAutoTArray&& other) { + AutoTArray& operator=(AutoTArray&& other) { if (this != &other) { fArray = std::move(other.fArray); SkDEBUGCODE(fCount = other.fCount; other.fCount = 0;) @@ -103,7 +121,7 @@ template class SkAutoTArray { /** Reallocates given a new count. Reallocation occurs even if new count equals old count. */ - void reset(int count = 0) { *this = SkAutoTArray(count); } + void reset(int count = 0) { *this = AutoTArray(count); } /** Return the array of T elements. Will be NULL if count == 0 */ @@ -125,30 +143,30 @@ template class SkAutoTArray { SkDEBUGCODE(int fCount = 0;) }; -/** Wraps SkAutoTArray, with room for kCountRequested elements preallocated. +/** Wraps AutoTArray, with room for kCountRequested elements preallocated. */ -template class SkAutoSTArray { +template class AutoSTArray { public: - SkAutoSTArray(SkAutoSTArray&&) = delete; - SkAutoSTArray(const SkAutoSTArray&) = delete; - SkAutoSTArray& operator=(SkAutoSTArray&&) = delete; - SkAutoSTArray& operator=(const SkAutoSTArray&) = delete; + AutoSTArray(AutoSTArray&&) = delete; + AutoSTArray(const AutoSTArray&) = delete; + AutoSTArray& operator=(AutoSTArray&&) = delete; + AutoSTArray& operator=(const AutoSTArray&) = delete; /** Initialize with no objects */ - SkAutoSTArray() { + AutoSTArray() { fArray = nullptr; fCount = 0; } /** Allocate count number of T elements */ - SkAutoSTArray(int count) { + AutoSTArray(int count) { fArray = nullptr; fCount = 0; this->reset(count); } - ~SkAutoSTArray() { + ~AutoSTArray() { this->reset(0); } @@ -216,8 +234,8 @@ template class SkAutoSTArray { private: #if defined(SK_BUILD_FOR_GOOGLE3) - // Stack frame size is limited for SK_BUILD_FOR_GOOGLE3. 4k is less than the actual max, but some functions - // have multiple large stack allocations. + // Stack frame size is limited for SK_BUILD_FOR_GOOGLE3. 4k is less than the actual max, + // but some functions have multiple large stack allocations. static const int kMaxBytes = 4 * 1024; static const int kCount = kCountRequested * sizeof(T) > kMaxBytes ? kMaxBytes / sizeof(T) @@ -226,10 +244,9 @@ template class SkAutoSTArray { static const int kCount = kCountRequested; #endif - int fCount; - T* fArray; - // since we come right after fArray, fStorage should be properly aligned - char fStorage[kCount * sizeof(T)]; + int fCount; + T* fArray; + alignas(T) char fStorage[kCount * sizeof(T)]; }; /** Manages an array of T elements, freeing the array in the destructor. @@ -238,17 +255,17 @@ template class SkAutoSTArray { template ::value && std::is_trivially_destructible::value>> -class SkAutoTMalloc { +class AutoTMalloc { public: /** Takes ownership of the ptr. The ptr must be a value which can be passed to sk_free. */ - explicit SkAutoTMalloc(T* ptr = nullptr) : fPtr(ptr) {} + explicit AutoTMalloc(T* ptr = nullptr) : fPtr(ptr) {} /** Allocates space for 'count' Ts. */ - explicit SkAutoTMalloc(size_t count) + explicit AutoTMalloc(size_t count) : fPtr(count ? (T*)sk_malloc_throw(count, sizeof(T)) : nullptr) {} - SkAutoTMalloc(SkAutoTMalloc&&) = default; - SkAutoTMalloc& operator=(SkAutoTMalloc&&) = default; + AutoTMalloc(AutoTMalloc&&) = default; + AutoTMalloc& operator=(AutoTMalloc&&) = default; /** Resize the memory area pointed to by the current ptr preserving contents. */ void realloc(size_t count) { @@ -283,18 +300,18 @@ class SkAutoTMalloc { T* release() { return fPtr.release(); } private: - std::unique_ptr> fPtr; + std::unique_ptr> fPtr; }; template ::value && std::is_trivially_destructible::value>> -class SkAutoSTMalloc { +class AutoSTMalloc { public: - SkAutoSTMalloc() : fPtr(fTStorage) {} + AutoSTMalloc() : fPtr(fTStorage) {} - SkAutoSTMalloc(size_t count) { + AutoSTMalloc(size_t count) { if (count > kCount) { fPtr = (T*)sk_malloc_throw(count, sizeof(T)); } else if (count) { @@ -304,12 +321,12 @@ class SkAutoSTMalloc { } } - SkAutoSTMalloc(SkAutoSTMalloc&&) = delete; - SkAutoSTMalloc(const SkAutoSTMalloc&) = delete; - SkAutoSTMalloc& operator=(SkAutoSTMalloc&&) = delete; - SkAutoSTMalloc& operator=(const SkAutoSTMalloc&) = delete; + AutoSTMalloc(AutoSTMalloc&&) = delete; + AutoSTMalloc(const AutoSTMalloc&) = delete; + AutoSTMalloc& operator=(AutoSTMalloc&&) = delete; + AutoSTMalloc& operator=(const AutoSTMalloc&) = delete; - ~SkAutoSTMalloc() { + ~AutoSTMalloc() { if (fPtr != fTStorage) { sk_free(fPtr); } @@ -391,27 +408,9 @@ class SkAutoSTMalloc { }; }; -////////////////////////////////////////////////////////////////////////////////////////////////// +using UniqueVoidPtr = std::unique_ptr>; -template class SkAlignedSTStorage { -public: - SkAlignedSTStorage() {} - SkAlignedSTStorage(SkAlignedSTStorage&&) = delete; - SkAlignedSTStorage(const SkAlignedSTStorage&) = delete; - SkAlignedSTStorage& operator=(SkAlignedSTStorage&&) = delete; - SkAlignedSTStorage& operator=(const SkAlignedSTStorage&) = delete; - - /** - * Returns void* because this object does not initialize the - * memory. Use placement new for types that require a constructor. - */ - void* get() { return fStorage; } - const void* get() const { return fStorage; } -private: - alignas(T) char fStorage[sizeof(T)*N]; -}; - -using SkAutoFree = std::unique_ptr>; +} // namespace skia_private template constexpr auto SkMakeArrayFromIndexSequence(C c, std::index_sequence is) @@ -424,28 +423,4 @@ template constexpr auto SkMakeArray(C c) return SkMakeArrayFromIndexSequence(c, std::make_index_sequence{}); } -/** - * Trait for identifying types which are relocatable via memcpy, for container optimizations. - * - */ -template -struct sk_has_trivially_relocatable_member : std::false_type {}; - -// Types can declare themselves trivially relocatable with a public -// using sk_is_trivially_relocatable = std::true_type; -template -struct sk_has_trivially_relocatable_member> - : T::sk_is_trivially_relocatable {}; - -// By default, all trivially copyable types are trivially relocatable. -template -struct sk_is_trivially_relocatable - : std::disjunction, sk_has_trivially_relocatable_member ->{}; - -// Here be some dragons: while technically not guaranteed, we count on all sane unique_ptr -// implementations to be trivially relocatable. -template -struct sk_is_trivially_relocatable> : std::true_type {}; - #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkThreadAnnotations.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadAnnotations.h similarity index 100% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkThreadAnnotations.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadAnnotations.h diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h similarity index 69% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h index e14388b3de5bd..18984884c96f7 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h @@ -8,11 +8,14 @@ #ifndef SkThreadID_DEFINED #define SkThreadID_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" + +#include typedef int64_t SkThreadID; -// SkMutex.h uses SkGetThredID in debug only code. +// SkMutex.h uses SkGetThreadID in debug only code. SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID(); const SkThreadID kIllegalThreadID = 0; diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h similarity index 71% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h index d788f7b269dad..51ccafeeaf754 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h @@ -7,8 +7,11 @@ #ifndef SkTo_DEFINED #define SkTo_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkTFitsIn.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTFitsIn.h" + +#include +#include template constexpr D SkTo(S s) { return SkASSERT(SkTFitsIn(s)), @@ -21,8 +24,16 @@ template constexpr int16_t SkToS16(S x) { return SkTo(x template constexpr uint16_t SkToU16(S x) { return SkTo(x); } template constexpr int32_t SkToS32(S x) { return SkTo(x); } template constexpr uint32_t SkToU32(S x) { return SkTo(x); } +template constexpr int64_t SkToS64(S x) { return SkTo(x); } +template constexpr uint64_t SkToU64(S x) { return SkTo(x); } template constexpr int SkToInt(S x) { return SkTo(x); } template constexpr unsigned SkToUInt(S x) { return SkTo(x); } template constexpr size_t SkToSizeT(S x) { return SkTo(x); } +/** @return false or true based on the condition +*/ +template static constexpr bool SkToBool(const T& x) { + return (bool)x; +} + #endif // SkTo_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h new file mode 100644 index 0000000000000..736f7897763d5 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h @@ -0,0 +1,33 @@ +// 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 SkTypeTraits_DEFINED +#define SkTypeTraits_DEFINED + +#include +#include + +// Trait for identifying types which are relocatable via memcpy, for container optimizations. +template +struct sk_has_trivially_relocatable_member : std::false_type {}; + +// Types can declare themselves trivially relocatable with a public +// using sk_is_trivially_relocatable = std::true_type; +template +struct sk_has_trivially_relocatable_member> + : T::sk_is_trivially_relocatable {}; + +// By default, all trivially copyable types are trivially relocatable. +template +struct sk_is_trivially_relocatable + : std::disjunction, sk_has_trivially_relocatable_member>{}; + +// Here be some dragons: while technically not guaranteed, we count on all sane unique_ptr +// implementations to be trivially relocatable. +template +struct sk_is_trivially_relocatable> : std::true_type {}; + +template +inline constexpr bool sk_is_trivially_relocatable_v = sk_is_trivially_relocatable::value; + +#endif // SkTypeTraits_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h new file mode 100644 index 0000000000000..51ed8a804defe --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h @@ -0,0 +1,130 @@ +/* + * Copyright 2019 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrVkSecondaryCBDrawContext_DEFINED +#define GrVkSecondaryCBDrawContext_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/core/SkSurfaceProps.h" +#include "include/core/SkTypes.h" + +#include + +class GrBackendSemaphore; +class GrRecordingContext; +struct GrVkDrawableInfo; +namespace skgpu::ganesh { +class Device; +} +class SkCanvas; +class SkDeferredDisplayList; +struct SkImageInfo; +class SkSurfaceCharacterization; +class SkSurfaceProps; + +/** + * This class is a private header that is intended to only be used inside of Chromium. This requires + * Chromium to burrow in and include this specifically since it is not part of skia's public include + * directory. + */ + +/** + * This class is used to draw into an external Vulkan secondary command buffer that is imported + * by the client. The secondary command buffer that gets imported must already have had begin called + * on it with VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT. Thus any draws to the imported + * command buffer cannot require changing the render pass. This requirement means that certain types + * of draws will not be supported when using a GrVkSecondaryCBDrawContext. This includes: + * Draws that require a dst copy for blending will be dropped + * Text draws will be dropped (these may require intermediate uploads of text data) + * Read and Write pixels will not work + * Any other draw that requires a copy will fail (this includes using backdrop filter with save + * layer). + * Stenciling is also disabled, but that should not restrict any actual draws from working. + * + * While using a GrVkSecondaryCBDrawContext, the client can also draw into normal SkSurfaces and + * then draw those SkSufaces (as SkImages) into the GrVkSecondaryCBDrawContext. If any of the + * previously mentioned unsupported draws are needed by the client, they can draw them into an + * offscreen surface, and then draw that into the GrVkSecondaryCBDrawContext. + * + * After all drawing to the GrVkSecondaryCBDrawContext has been done, the client must call flush() + * on the GrVkSecondaryCBDrawContext to actually fill in the secondary VkCommandBuffer with the + * draws. + * + * Additionally, the client must keep the GrVkSecondaryCBDrawContext alive until the secondary + * VkCommandBuffer has been submitted and all work finished on the GPU. Before deleting the + * GrVkSecondaryCBDrawContext, the client must call releaseResources() so that Skia can cleanup + * any internal objects that were created for the draws into the secondary command buffer. + */ +class SK_SPI GrVkSecondaryCBDrawContext : public SkRefCnt { +public: + static sk_sp Make(GrRecordingContext*, + const SkImageInfo&, + const GrVkDrawableInfo&, + const SkSurfaceProps* props); + + ~GrVkSecondaryCBDrawContext() override; + + SkCanvas* getCanvas(); + + // Records all the draws to the imported secondary command buffer and sets any dependent + // offscreen draws to the GPU. + void flush(); + + /** Inserts a list of GPU semaphores that Skia will have the driver wait on before executing + commands for this secondary CB. The wait semaphores will get added to the VkCommandBuffer + owned by this GrContext when flush() is called, and not the command buffer which the + Secondary CB is from. This will guarantee that the driver waits on the semaphores before + the secondary command buffer gets executed. If this call returns false, then the GPU + back end will not wait on any passed in semaphores, and the client will still own the + semaphores, regardless of the value of deleteSemaphoresAfterWait. + + If deleteSemaphoresAfterWait is false then Skia will not delete the semaphores. In this case + it is the client's responsibility to not destroy or attempt to reuse the semaphores until it + knows that Skia has finished waiting on them. This can be done by using finishedProcs + on flush calls. + + @param numSemaphores size of waitSemaphores array + @param waitSemaphores array of semaphore containers + @paramm deleteSemaphoresAfterWait who owns and should delete the semaphores + @return true if GPU is waiting on semaphores + */ + bool wait(int numSemaphores, + const GrBackendSemaphore waitSemaphores[], + bool deleteSemaphoresAfterWait = true); + + // This call will release all resources held by the draw context. The client must call + // releaseResources() before deleting the drawing context. However, the resources also include + // any Vulkan resources that were created and used for draws. Therefore the client must only + // call releaseResources() after submitting the secondary command buffer, and waiting for it to + // finish on the GPU. If it is called earlier then some vulkan objects may be deleted while they + // are still in use by the GPU. + void releaseResources(); + + const SkSurfaceProps& props() const { return fProps; } + + // TODO: Fill out these calls to support DDL + bool characterize(SkSurfaceCharacterization* characterization) const; + +#ifndef SK_DDL_IS_UNIQUE_POINTER + bool draw(sk_sp deferredDisplayList); +#else + bool draw(const SkDeferredDisplayList* deferredDisplayList); +#endif + + bool isCompatible(const SkSurfaceCharacterization& characterization) const; + +private: + explicit GrVkSecondaryCBDrawContext(sk_sp, const SkSurfaceProps*); + + sk_sp fDevice; + std::unique_ptr fCachedCanvas; + const SkSurfaceProps fProps; + + using INHERITED = SkRefCnt; +}; + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h index 55568b9af75a9..962d183b2d979 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h @@ -13,6 +13,7 @@ #include "include/core/SkData.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTypeface.h" #include "include/utils/SkNoDrawCanvas.h" struct SkPackedGlyphID; @@ -21,7 +22,6 @@ class SkStrikeCache; class SkStrikeClientImpl; class SkStrikeServer; class SkStrikeServerImpl; -class SkTypeface; namespace sktext::gpu { class Slug; } using SkDiscardableHandleId = uint32_t; @@ -62,9 +62,6 @@ class SkStrikeServer { bool DFTSupport, bool DFTPerspSupport = true); - // Serializes the typeface to be transmitted using this server. - SK_SPI sk_sp serializeTypeface(SkTypeface*); - // Serializes the strike data captured using a canvas returned by ::makeAnalysisCanvas. Any // handles locked using the DiscardableHandleManager will be assumed to be // unlocked after this call. @@ -128,10 +125,6 @@ class SkStrikeClient { SkStrikeCache* strikeCache = nullptr); SK_SPI ~SkStrikeClient(); - // Deserializes the typeface previously serialized using the SkStrikeServer. Returns null if the - // data is invalid. - SK_SPI sk_sp deserializeTypeface(const void* data, size_t length); - // Deserializes the strike data from a SkStrikeServer. All messages generated // from a server when serializing the ops must be deserialized before the op // is rasterized. @@ -142,9 +135,12 @@ class SkStrikeClient { // corresponding typefaceID on the GPU. SK_SPI bool translateTypefaceID(SkAutoDescriptor* descriptor) const; + // Testing helpers + sk_sp retrieveTypefaceUsingServerIDForTest(SkTypefaceID) const; + // Given a buffer, unflatten into a slug making sure to do the typefaceID translation from // renderer to GPU. Returns nullptr if there was a problem. - sk_sp deserializeSlug(const void* data, size_t size) const; + sk_sp deserializeSlugForTest(const void* data, size_t size) const; private: std::unique_ptr fImpl; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h new file mode 100644 index 0000000000000..ade4d71aa7497 --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h @@ -0,0 +1,70 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkDiscardableMemory_DEFINED +#define SkDiscardableMemory_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +/** + * Interface for discardable memory. Implementation is provided by the + * embedder. + */ +class SK_SPI SkDiscardableMemory { +public: + /** + * Factory method that creates, initializes and locks an SkDiscardableMemory + * object. If either of these steps fails, a nullptr pointer will be returned. + */ + static SkDiscardableMemory* Create(size_t bytes); + + /** + * Factory class that creates, initializes and locks an SkDiscardableMemory + * object. If either of these steps fails, a nullptr pointer will be returned. + */ + class Factory : public SkRefCnt { + public: + virtual SkDiscardableMemory* create(size_t bytes) = 0; + private: + using INHERITED = SkRefCnt; + }; + + /** Must not be called while locked. + */ + virtual ~SkDiscardableMemory() {} + + /** + * Locks the memory, prevent it from being discarded. Once locked. you may + * obtain a pointer to that memory using the data() method. + * + * lock() may return false, indicating that the underlying memory was + * discarded and that the lock failed. + * + * Nested calls to lock are not allowed. + */ + virtual bool SK_WARN_UNUSED_RESULT lock() = 0; + + /** + * Returns the current pointer for the discardable memory. This call is ONLY + * valid when the discardable memory object is locked. + */ + virtual void* data() = 0; + + /** + * Unlock the memory so that it can be purged by the system. Must be called + * after every successful lock call. + */ + virtual void unlock() = 0; + +protected: + SkDiscardableMemory() = default; + SkDiscardableMemory(const SkDiscardableMemory&) = delete; + SkDiscardableMemory& operator=(const SkDiscardableMemory&) = delete; +}; + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h index 0f4d9773db776..6775af0fc6966 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h @@ -21,14 +21,6 @@ class SkStrikeClient; class SkWriteBuffer; namespace sktext::gpu { - -// You can use Slug to simulate drawTextBlob by defining the following at compile time. -// SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG -// You can use Slug serialization to simulate drawTextBlob by defining the following: -// SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE -// For Skia, add this to your args.gn file. -// extra_cflags = ["-D", "SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG"] - // Slug encapsulates an SkTextBlob at a specific origin, using a specific paint. It can be // manipulated using matrix and clip changes to the canvas. If the canvas is transformed, then // the Slug will also transform with smaller glyphs using bi-linear interpolation to render. You @@ -70,7 +62,6 @@ class SK_API Slug : public SkRefCnt { static uint32_t NextUniqueID(); const uint32_t fUniqueID{NextUniqueID()}; }; - } // namespace sktext::gpu #endif // sktext_gpu_Slug_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h index 847e76f23252e..ba7172e005ae5 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h @@ -19,6 +19,7 @@ class GrContextThreadSafeProxy; class GrDirectContext; class GrImageContext; class GrRecordingContext; +enum class SkTextureCompressionType; class GrContext_Base : public SkRefCnt { public: @@ -43,7 +44,7 @@ class GrContext_Base : public SkRefCnt { */ SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const; - SK_API GrBackendFormat compressedBackendFormat(SkImage::CompressionType) const; + SK_API GrBackendFormat compressedBackendFormat(SkTextureCompressionType) const; /** * Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h index 049c07bff63be..26b75344760ee 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h @@ -65,7 +65,7 @@ struct GrD3DTextureResourceSpecHolder { GrD3DSurfaceInfo getSurfaceInfo(uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected) const; + skgpu::Protected isProtected) const; private: GrD3DTextureResourceSpec* fSpec; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h index 5eacf2ea2d263..ffcdc0eaaf49e 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h @@ -20,7 +20,7 @@ struct GrDawnTextureSpec { GrDawnSurfaceInfo GrDawnTextureSpecToSurfaceInfo(const GrDawnTextureSpec& dawnSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h index e951fbd17cfa5..7db777487aecc 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h @@ -103,6 +103,6 @@ struct GrGLTextureSpec { GrGLSurfaceInfo GrGLTextureSpecToSurfaceInfo(const GrGLTextureSpec& glSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h index 5a1a7a32d6241..72fdd4433d065 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h @@ -8,7 +8,7 @@ #ifndef GrImageContext_DEFINED #define GrImageContext_DEFINED -#include "include/private/SingleOwner.h" +#include "include/private/base/SingleOwner.h" #include "include/private/gpu/ganesh/GrContext_Base.h" class GrImageContextPriv; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h index fc72c7fd93bed..59a608dcfca0d 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h @@ -8,18 +8,19 @@ #ifndef GrMockTypesPriv_DEFINED #define GrMockTypesPriv_DEFINED +#include "include/core/SkTextureCompressionType.h" #include "include/gpu/mock/GrMockTypes.h" struct GrMockTextureSpec { GrMockTextureSpec() : fColorType(GrColorType::kUnknown) - , fCompressionType(SkImage::CompressionType::kNone) {} + , fCompressionType(SkTextureCompressionType::kNone) {} GrMockTextureSpec(const GrMockSurfaceInfo& info) : fColorType(info.fColorType) , fCompressionType(info.fCompressionType) {} GrColorType fColorType = GrColorType::kUnknown; - SkImage::CompressionType fCompressionType = SkImage::CompressionType::kNone; + SkTextureCompressionType fCompressionType = SkTextureCompressionType::kNone; }; GrMockSurfaceInfo GrMockTextureSpecToSurfaceInfo(const GrMockTextureSpec& mockSpec, diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h index 550d01760f946..ef65848b5e15a 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h @@ -68,7 +68,7 @@ struct GrMtlTextureSpec { GrMtlSurfaceInfo GrMtlTextureSpecToSurfaceInfo(const GrMtlTextureSpec& mtlSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif // __APPLE__ diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h index b663ff2b193ee..84e2346348503 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h @@ -8,28 +8,21 @@ #ifndef GrTypesPriv_DEFINED #define GrTypesPriv_DEFINED -#include -#include "include/core/SkImage.h" +#include "include/core/SkColor.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPath.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTextureCompressionType.h" #include "include/gpu/GrTypes.h" -#include "include/private/SkImageInfoPriv.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" +#include "include/private/base/SkTypeTraits.h" + +#include class GrBackendFormat; class GrCaps; class GrSurfaceProxy; -// The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might -// not actually be monotonic, depending on how libstdc++ was built. However, this is only currently -// used for idle resource purging so it shouldn't cause a correctness problem. -#if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000) -using GrStdSteadyClock = std::chrono::monotonic_clock; -#else -using GrStdSteadyClock = std::chrono::steady_clock; -#endif - /** * divide, rounding up */ @@ -643,6 +636,7 @@ static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct) { case kRGB_101010x_SkColorType: return GrColorType::kUnknown; case kBGRA_1010102_SkColorType: return GrColorType::kBGRA_1010102; case kBGR_101010x_SkColorType: return GrColorType::kUnknown; + case kBGR_101010x_XR_SkColorType: return GrColorType::kUnknown; case kRGBA_F32_SkColorType: return GrColorType::kRGBA_F32; case kR8G8_unorm_SkColorType: return GrColorType::kRG_88; case kA16_unorm_SkColorType: return GrColorType::kAlpha_16; @@ -924,12 +918,12 @@ static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct) { // In general we try to not mix CompressionType and ColorType, but currently SkImage still requires // an SkColorType even for CompressedTypes so we need some conversion. -static constexpr SkColorType GrCompressionTypeToSkColorType(SkImage::CompressionType compression) { +static constexpr SkColorType GrCompressionTypeToSkColorType(SkTextureCompressionType compression) { switch (compression) { - case SkImage::CompressionType::kNone: return kUnknown_SkColorType; - case SkImage::CompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType; - case SkImage::CompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType; - case SkImage::CompressionType::kBC1_RGBA8_UNORM: return kRGBA_8888_SkColorType; + case SkTextureCompressionType::kNone: return kUnknown_SkColorType; + case SkTextureCompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType; + case SkTextureCompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType; + case SkTextureCompressionType::kBC1_RGBA8_UNORM: return kRGBA_8888_SkColorType; } SkUNREACHABLE; @@ -995,12 +989,12 @@ static constexpr const char* GrColorTypeToStr(GrColorType ct) { SkUNREACHABLE; } -static constexpr const char* GrCompressionTypeToStr(SkImage::CompressionType compression) { +static constexpr const char* GrCompressionTypeToStr(SkTextureCompressionType compression) { switch (compression) { - case SkImage::CompressionType::kNone: return "kNone"; - case SkImage::CompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM"; - case SkImage::CompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM"; - case SkImage::CompressionType::kBC1_RGBA8_UNORM: return "kBC1_RGBA8_UNORM"; + case SkTextureCompressionType::kNone: return "kNone"; + case SkTextureCompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM"; + case SkTextureCompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM"; + case SkTextureCompressionType::kBC1_RGBA8_UNORM: return "kBC1_RGBA8_UNORM"; } SkUNREACHABLE; } diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h index a68d467dd8c92..f300a7139632b 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h @@ -35,7 +35,7 @@ struct GrVkBackendSurfaceInfo { GrVkImageInfo snapImageInfo(const skgpu::MutableTextureStateRef*) const; - bool isProtected() const { return fImageInfo.fProtected == GrProtected::kYes; } + bool isProtected() const { return fImageInfo.fProtected == skgpu::Protected::kYes; } #if GR_TEST_UTILS bool operator==(const GrVkBackendSurfaceInfo& that) const; #endif @@ -68,6 +68,6 @@ struct GrVkImageSpec { GrVkSurfaceInfo GrVkImageSpecToSurfaceInfo(const GrVkImageSpec& vkSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h new file mode 100644 index 0000000000000..bbf401c95e48d --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h @@ -0,0 +1,38 @@ +/* + * 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 skgpu_graphite_DawnTypesPriv_DEFINED +#define skgpu_graphite_DawnTypesPriv_DEFINED + +#include "include/gpu/graphite/dawn/DawnTypes.h" + +namespace skgpu::graphite { + +struct DawnTextureSpec { + DawnTextureSpec() + : fFormat(wgpu::TextureFormat::Undefined) + , fUsage(wgpu::TextureUsage::None) {} + DawnTextureSpec(const DawnTextureInfo& info) + : fFormat(info.fFormat) + , fUsage(info.fUsage) {} + + bool operator==(const DawnTextureSpec& that) const { + return fUsage == that.fUsage && + fFormat == that.fFormat; + } + + wgpu::TextureFormat fFormat; + wgpu::TextureUsage fUsage; +}; + +DawnTextureInfo DawnTextureSpecToTextureInfo(const DawnTextureSpec& dawnSpec, + uint32_t sampleCount, + Mipmapped mipmapped); + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_DawnTypesPriv_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h similarity index 87% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h index 697628a84d939..bf26aa2a78ad3 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h @@ -5,11 +5,11 @@ * found in the LICENSE file. */ -#ifndef skgpu_graphite_MtlTypesPriv_DEFINED -#define skgpu_graphite_MtlTypesPriv_DEFINED +#ifndef skgpu_graphite_MtlGraphiteTypesPriv_DEFINED +#define skgpu_graphite_MtlGraphiteTypesPriv_DEFINED #include "include/gpu/graphite/GraphiteTypes.h" -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" /////////////////////////////////////////////////////////////////////////////// @@ -67,8 +67,8 @@ struct MtlTextureSpec { MtlTextureInfo MtlTextureSpecToTextureInfo(const MtlTextureSpec& mtlSpec, uint32_t sampleCount, - uint32_t levelCount); + Mipmapped mipmapped); } // namespace skgpu::graphite -#endif // skgpu_graphite_MtlTypesPriv_DEFINED +#endif // skgpu_graphite_MtlGraphiteTypesPriv_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h index e0703d7ef1c86..b4304e3ae8988 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h @@ -19,8 +19,6 @@ struct VulkanTextureSpec { , fImageTiling(VK_IMAGE_TILING_OPTIMAL) , fImageUsageFlags(0) , fSharingMode(VK_SHARING_MODE_EXCLUSIVE) - , fCurrentQueueFamily(VK_QUEUE_FAMILY_IGNORED) - , fImageLayout(VK_IMAGE_LAYOUT_UNDEFINED) , fAspectMask(VK_IMAGE_ASPECT_COLOR_BIT) {} VulkanTextureSpec(const VulkanTextureInfo& info) : fFlags(info.fFlags) @@ -28,8 +26,6 @@ struct VulkanTextureSpec { , fImageTiling(info.fImageTiling) , fImageUsageFlags(info.fImageUsageFlags) , fSharingMode(info.fSharingMode) - , fCurrentQueueFamily(info.fCurrentQueueFamily) - , fImageLayout(info.fImageLayout) , fAspectMask(info.fAspectMask) {} bool operator==(const VulkanTextureSpec& that) const { @@ -38,8 +34,6 @@ struct VulkanTextureSpec { fImageTiling == that.fImageTiling && fImageUsageFlags == that.fImageUsageFlags && fSharingMode == that.fSharingMode && - fCurrentQueueFamily == that.fCurrentQueueFamily && - fImageLayout == that.fImageLayout && fAspectMask == that.fAspectMask; } @@ -48,15 +42,13 @@ struct VulkanTextureSpec { VkImageTiling fImageTiling; VkImageUsageFlags fImageUsageFlags; VkSharingMode fSharingMode; - uint32_t fCurrentQueueFamily; - VkImageLayout fImageLayout; VkImageAspectFlags fAspectMask; // GrVkYcbcrConversionInfo fYcbcrConversionInfo; }; VulkanTextureInfo VulkanTextureSpecToTextureInfo(const VulkanTextureSpec& vkSpec, uint32_t sampleCount, - uint32_t levelCount); + Mipmapped mipmapped); } // namespace skgpu::graphite diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h index c0a9b03bdaa02..ca4bcf108bf45 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h @@ -10,6 +10,8 @@ #include "include/core/SkTypes.h" +// IWYU pragma: begin_exports + #if SKIA_IMPLEMENTATION || !defined(SK_VULKAN) #include "include/third_party/vulkan/vulkan/vulkan_core.h" #else @@ -29,4 +31,6 @@ #endif #endif +// IWYU pragma: end_exports + #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h deleted file mode 100644 index 6b9ebd4727730..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL -#define SKSL_DSL - -#include "include/sksl/DSLBlock.h" -#include "include/sksl/DSLCore.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLFunction.h" -#include "include/sksl/DSLType.h" - -namespace SkSL { - -namespace dsl { - -using Block = DSLBlock; -using Case = DSLCase; -using Expression = DSLExpression; -using Field = DSLField; -using Function = DSLFunction; -using GlobalVar = DSLGlobalVar; -using Layout = DSLLayout; -using Modifiers = DSLModifiers; -using Parameter = DSLParameter; -using Statement = DSLStatement; -using Var = DSLVar; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h deleted file mode 100644 index 959ea2235bacd..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_BLOCK -#define SKSL_DSL_BLOCK - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include - -namespace SkSL { - -class Block; -class SymbolTable; - -namespace dsl { - -class DSLBlock { -public: - template - DSLBlock(Statements... statements) { - fStatements.reserve_back(sizeof...(statements)); - ((void)fStatements.push_back(DSLStatement(statements.release()).release()), ...); - } - - DSLBlock(SkSL::StatementArray statements, std::shared_ptr symbols = nullptr, - Position pos = {}); - - DSLBlock(SkTArray statements, std::shared_ptr symbols = nullptr, - Position pos = {}); - - DSLBlock(DSLBlock&& other) = default; - DSLBlock& operator=(DSLBlock&& other) = default; - - ~DSLBlock() = default; - - void append(DSLStatement stmt); - - std::unique_ptr release(); - -private: - SkSL::StatementArray fStatements; - std::shared_ptr fSymbols; - Position fPosition; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h deleted file mode 100644 index 16780e644a2c9..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_CASE -#define SKSL_DSL_CASE - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include - -namespace SkSL { - -namespace dsl { - -class DSLCase { -public: - // An empty expression means 'default:'. - template - DSLCase(DSLExpression value, Statements... statements) - : fValue(std::move(value)) { - fStatements.reserve_back(sizeof...(statements)); - ((void)fStatements.push_back(DSLStatement(std::move(statements)).release()), ...); - } - - DSLCase(DSLExpression value, SkTArray statements, - Position pos = {}); - - DSLCase(DSLExpression value, SkSL::StatementArray statements, - Position pos = {}); - - DSLCase(DSLCase&&); - - ~DSLCase(); - - DSLCase& operator=(DSLCase&&); - - void append(DSLStatement stmt); - -private: - DSLExpression fValue; - SkSL::StatementArray fStatements; - Position fPosition; - - friend class DSLCore; - - template - friend DSLStatement Switch(DSLExpression value, Cases... cases); -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h deleted file mode 100644 index 72441d4dee15a..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h +++ /dev/null @@ -1,492 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_CORE -#define SKSL_DSL_CORE - -#include "include/private/SkSLDefines.h" -#include "include/private/SkSLProgramKind.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLCase.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/DSLVar.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Compiler; -class ErrorReporter; -struct Program; -struct ProgramSettings; - -namespace dsl { - -class DSLField; -class DSLModifiers; - -// When users import the DSL namespace via `using namespace SkSL::dsl`, we want the SwizzleComponent -// Type enum to come into scope as well, so `Swizzle(var, X, Y, ONE)` can work as expected. -// `namespace SkSL::SwizzleComponent` contains only an `enum Type`; this `using namespace` directive -// shouldn't pollute the SkSL::dsl namespace with anything else. -using namespace SkSL::SwizzleComponent; - -/** - * Starts DSL output on the current thread using the specified compiler. This must be called - * prior to any other DSL functions. - */ -void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment); - -void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind, const SkSL::ProgramSettings& settings); - -/** - * Signals the end of DSL output. This must be called sometime between a call to Start() and the - * termination of the thread. - */ -void End(); - -/** - * Returns all global elements (functions and global variables) as a self-contained Program. The - * optional source string is retained as the program's source. DSL programs do not normally have - * sources, but when a DSL program is produced from parsed program text (as in Parser), it may be - * important to retain it so that any std::string_views derived from it remain valid. - */ -std::unique_ptr ReleaseProgram(std::unique_ptr source = nullptr); - -/** - * Returns the ErrorReporter which will be notified of any errors that occur during DSL calls. The - * default error reporter aborts on any error. - */ -ErrorReporter& GetErrorReporter(); - -/** - * Installs an ErrorReporter which will be notified of any errors that occur during DSL calls. - */ -void SetErrorReporter(ErrorReporter* errorReporter); - -DSLGlobalVar sk_FragColor(); - -DSLGlobalVar sk_FragCoord(); - -DSLExpression sk_Position(); - -/** - * #extension : enable - */ -void AddExtension(std::string_view name, Position pos = {}); - -/** - * break; - */ -DSLStatement Break(Position pos = {}); - -/** - * continue; - */ -DSLStatement Continue(Position pos = {}); - -/** - * Adds a modifiers declaration to the current program. - */ -void Declare(const DSLModifiers& modifiers, Position pos = {}); - -/** - * Creates a local variable declaration statement. - */ -DSLStatement Declare(DSLVar& var, Position pos = {}); - -/** - * Creates a local variable declaration statement containing multiple variables. - */ -DSLStatement Declare(SkTArray& vars, Position pos = {}); - -/** - * Declares a global variable. - */ -void Declare(DSLGlobalVar& var, Position pos = {}); - -/** - * Declares a set of global variables. - */ -void Declare(SkTArray& vars, Position pos = {}); - -/** - * default: statements - */ -template -DSLCase Default(Statements... statements) { - return DSLCase(DSLExpression(), std::move(statements)...); -} - -/** - * discard; - */ -DSLStatement Discard(Position pos = {}); - -/** - * do stmt; while (test); - */ -DSLStatement Do(DSLStatement stmt, DSLExpression test, Position pos = {}); - -/** - * for (initializer; test; next) stmt; - */ -DSLStatement For(DSLStatement initializer, DSLExpression test, DSLExpression next, - DSLStatement stmt, Position pos = {}, ForLoopPositions positions = {}); - -/** - * if (test) ifTrue; [else ifFalse;] - */ -DSLStatement If(DSLExpression test, DSLStatement ifTrue, DSLStatement ifFalse = DSLStatement(), - Position pos = {}); - -DSLGlobalVar InterfaceBlock(const DSLModifiers& modifiers, std::string_view typeName, - SkTArray fields, std::string_view varName = "", - int arraySize = 0, Position pos = {}); - -/** - * return [value]; - */ -DSLStatement Return(DSLExpression value = DSLExpression(), - Position pos = {}); - -/** - * test ? ifTrue : ifFalse - */ -DSLExpression Select(DSLExpression test, DSLExpression ifTrue, DSLExpression ifFalse, - Position = {}); - -DSLStatement StaticIf(DSLExpression test, DSLStatement ifTrue, - DSLStatement ifFalse = DSLStatement(), - Position pos = {}); - -// Internal use only -DSLStatement StaticSwitch(DSLExpression value, SkTArray cases, Position pos = {}); - -/** - * @switch (value) { cases } - */ -template -DSLStatement StaticSwitch(DSLExpression value, Cases... cases) { - SkTArray caseArray; - caseArray.reserve_back(sizeof...(cases)); - (caseArray.push_back(std::move(cases)), ...); - return StaticSwitch(std::move(value), std::move(caseArray), Position{}); -} - -// Internal use only -DSLStatement Switch(DSLExpression value, SkTArray cases, Position pos = {}); - -/** - * switch (value) { cases } - */ -template -DSLStatement Switch(DSLExpression value, Cases... cases) { - SkTArray caseArray; - caseArray.reserve_back(sizeof...(cases)); - (caseArray.push_back(std::move(cases)), ...); - return Switch(std::move(value), std::move(caseArray), Position{}); -} - -/** - * while (test) stmt; - */ -DSLStatement While(DSLExpression test, DSLStatement stmt, - Position pos = {}); - -/** - * expression.xyz1 - */ -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - SkSL::SwizzleComponent::Type c, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - SkSL::SwizzleComponent::Type c, - SkSL::SwizzleComponent::Type d, - Position pos = {}, - Position maskPos = {}); - -/** - * Returns the absolute value of x. If x is a vector, operates componentwise. - */ -DSLExpression Abs(DSLExpression x, Position pos = {}); - -/** - * Returns true if all of the components of boolean vector x are true. - */ -DSLExpression All(DSLExpression x, Position pos = {}); - -/** - * Returns true if any of the components of boolean vector x are true. - */ -DSLExpression Any(DSLExpression x, Position pos = {}); - -/** - * Returns the arctangent of y over x. Operates componentwise on vectors. - */ -DSLExpression Atan(DSLExpression y_over_x, Position pos = {}); -DSLExpression Atan(DSLExpression y, DSLExpression x, Position pos = {}); - -/** - * Returns x rounded towards positive infinity. If x is a vector, operates componentwise. - */ -DSLExpression Ceil(DSLExpression x, Position pos = {}); - -/** - * Returns x clamped to between min and max. If x is a vector, operates componentwise. - */ -DSLExpression Clamp(DSLExpression x, DSLExpression min, DSLExpression max, - Position pos = {}); - -/** - * Returns the cosine of x. If x is a vector, operates componentwise. - */ -DSLExpression Cos(DSLExpression x, Position pos = {}); - -/** - * Returns the cross product of x and y. - */ -DSLExpression Cross(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns x converted from radians to degrees. If x is a vector, operates componentwise. - */ -DSLExpression Degrees(DSLExpression x, Position pos = {}); - -/** - * Returns the distance between x and y. - */ -DSLExpression Distance(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the dot product of x and y. - */ -DSLExpression Dot(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are equal to the corresponding - * components of y. - */ -DSLExpression Equal(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns e^x. If x is a vector, operates componentwise. - */ -DSLExpression Exp(DSLExpression x, Position pos = {}); - -/** - * Returns 2^x. If x is a vector, operates componentwise. - */ -DSLExpression Exp2(DSLExpression x, Position pos = {}); - -/** - * If dot(i, nref) >= 0, returns n, otherwise returns -n. - */ -DSLExpression Faceforward(DSLExpression n, DSLExpression i, DSLExpression nref, - Position pos = {}); - -/** - * Returns x rounded towards negative infinity. If x is a vector, operates componentwise. - */ -DSLExpression Floor(DSLExpression x, Position pos = {}); - -/** - * Returns the fractional part of x. If x is a vector, operates componentwise. - */ -DSLExpression Fract(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are greater than the corresponding - * components of y. - */ -DSLExpression GreaterThan(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are greater than or equal to the - * corresponding components of y. - */ -DSLExpression GreaterThanEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the 1/sqrt(x). If x is a vector, operates componentwise. - */ -DSLExpression Inversesqrt(DSLExpression x, Position pos = {}); - -/** - * Returns the inverse of the matrix x. - */ -DSLExpression Inverse(DSLExpression x, Position pos = {}); - -/** - * Returns the length of the vector x. - */ -DSLExpression Length(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are less than the corresponding - * components of y. - */ -DSLExpression LessThan(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are less than or equal to the - * corresponding components of y. - */ -DSLExpression LessThanEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the log base e of x. If x is a vector, operates componentwise. - */ -DSLExpression Log(DSLExpression x, Position pos = {}); - -/** - * Returns the log base 2 of x. If x is a vector, operates componentwise. - */ -DSLExpression Log2(DSLExpression x, Position pos = {}); - -/** - * Returns the larger (closer to positive infinity) of x and y. If x is a vector, operates - * componentwise. y may be either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Max(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns the smaller (closer to negative infinity) of x and y. If x is a vector, operates - * componentwise. y may be either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Min(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns a linear intepolation between x and y at position a, where a=0 results in x and a=1 - * results in y. If x and y are vectors, operates componentwise. a may be either a vector of the - * same dimensions as x and y, or a scalar. - */ -DSLExpression Mix(DSLExpression x, DSLExpression y, DSLExpression a, - Position pos = {}); - -/** - * Returns x modulo y. If x is a vector, operates componentwise. y may be either a vector of the - * same dimensions as x, or a scalar. - */ -DSLExpression Mod(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns the vector x normalized to a length of 1. - */ -DSLExpression Normalize(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are not equal to the corresponding - * components of y. - */ -DSLExpression NotEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns x raised to the power y. If x is a vector, operates componentwise. y may be either a - * vector of the same dimensions as x, or a scalar. - */ -DSLExpression Pow(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns x converted from degrees to radians. If x is a vector, operates componentwise. - */ -DSLExpression Radians(DSLExpression x, Position pos = {}); - -/** - * Returns i reflected from a surface with normal n. - */ -DSLExpression Reflect(DSLExpression i, DSLExpression n, Position pos = {}); - -/** - * Returns i refracted across a surface with normal n and ratio of indices of refraction eta. - */ -DSLExpression Refract(DSLExpression i, DSLExpression n, DSLExpression eta, - Position pos = {}); - -/** - * Returns x, rounded to the nearest integer. If x is a vector, operates componentwise. - */ -DSLExpression Round(DSLExpression x, Position pos = {}); - -/** - * Returns x clamped to the range [0, 1]. If x is a vector, operates componentwise. - */ -DSLExpression Saturate(DSLExpression x, Position pos = {}); - -/** - * Returns -1, 0, or 1 depending on whether x is negative, zero, or positive, respectively. If x is - * a vector, operates componentwise. - */ -DSLExpression Sign(DSLExpression x, Position pos = {}); - -/** - * Returns the sine of x. If x is a vector, operates componentwise. - */ -DSLExpression Sin(DSLExpression x, Position pos = {}); - -/** - * Returns a smooth interpolation between 0 (at x=edge1) and 1 (at x=edge2). If x is a vector, - * operates componentwise. edge1 and edge2 may either be both vectors of the same dimensions as x or - * scalars. - */ -DSLExpression Smoothstep(DSLExpression edge1, DSLExpression edge2, DSLExpression x, - Position pos = {}); - -/** - * Returns the square root of x. If x is a vector, operates componentwise. - */ -DSLExpression Sqrt(DSLExpression x, Position pos = {}); - -/** - * Returns 0 if x < edge or 1 if x >= edge. If x is a vector, operates componentwise. edge may be - * either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Step(DSLExpression edge, DSLExpression x, Position pos = {}); - -/** - * Returns the tangent of x. If x is a vector, operates componentwise. - */ -DSLExpression Tan(DSLExpression x, Position pos = {}); - -/** - * Returns x converted from premultipled to unpremultiplied alpha. - */ -DSLExpression Unpremul(DSLExpression x, Position pos = {}); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h deleted file mode 100644 index bdb5f2fe24691..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_EXPRESSION -#define SKSL_DSL_EXPRESSION - -#include "include/private/SkTArray.h" -#include "include/sksl/SkSLOperator.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include -#include - -#if defined(__has_cpp_attribute) && __has_cpp_attribute(clang::reinitializes) -#define SK_CLANG_REINITIALIZES [[clang::reinitializes]] -#else -#define SK_CLANG_REINITIALIZES -#endif - -namespace SkSL { - -class Expression; -class ExpressionArray; - -namespace dsl { - -class DSLType; -class DSLVarBase; - -/** - * Represents an expression such as 'cos(x)' or 'a + b'. - */ -class DSLExpression { -public: - DSLExpression(const DSLExpression&) = delete; - - DSLExpression(DSLExpression&&); - - DSLExpression(); - - /** - * Creates an expression representing a literal float. - */ - DSLExpression(float value, Position pos = {}); - - /** - * Creates an expression representing a literal float. - */ - DSLExpression(double value, Position pos = {}) - : DSLExpression((float) value) {} - - /** - * Creates an expression representing a literal int. - */ - DSLExpression(int value, Position pos = {}); - - /** - * Creates an expression representing a literal int. - */ - DSLExpression(int64_t value, Position pos = {}); - - /** - * Creates an expression representing a literal uint. - */ - DSLExpression(unsigned int value, Position pos = {}); - - /** - * Creates an expression representing a literal bool. - */ - DSLExpression(bool value, Position pos = {}); - - /** - * Creates an expression representing a variable reference. - */ - DSLExpression(DSLVarBase& var, Position pos = {}); - - DSLExpression(DSLVarBase&& var, Position pos = {}); - - // If expression is null, returns Poison - explicit DSLExpression(std::unique_ptr expression, Position pos = {}); - - static DSLExpression Poison(Position pos = {}); - - ~DSLExpression(); - - DSLType type() const; - - std::string description() const; - - Position position() const; - - void setPosition(Position pos); - - /** - * Performs assignment, like the '=' operator. - */ - DSLExpression assign(DSLExpression other); - - DSLExpression x(Position pos = {}); - - DSLExpression y(Position pos = {}); - - DSLExpression z(Position pos = {}); - - DSLExpression w(Position pos = {}); - - DSLExpression r(Position pos = {}); - - DSLExpression g(Position pos = {}); - - DSLExpression b(Position pos = {}); - - DSLExpression a(Position pos = {}); - - /** - * Creates an SkSL struct field access expression. - */ - DSLExpression field(std::string_view name, Position pos = {}); - - /** - * Creates an SkSL array index expression. - */ - DSLExpression operator[](DSLExpression index); - - DSLExpression operator()(SkTArray args, Position pos = {}); - - DSLExpression operator()(ExpressionArray args, Position pos = {}); - - /** - * Invokes a prefix operator. - */ - DSLExpression prefix(Operator::Kind op, Position pos); - - /** - * Invokes a postfix operator. - */ - DSLExpression postfix(Operator::Kind op, Position pos); - - /** - * Invokes a binary operator. - */ - DSLExpression binary(Operator::Kind op, DSLExpression right, Position pos); - - /** - * Equivalent to operator[]. - */ - DSLExpression index(DSLExpression index, Position pos); - - /** - * Returns true if this object contains an expression. DSLExpressions which were created with - * the empty constructor or which have already been release()ed do not have a value. - * DSLExpressions created with errors are still considered to have a value (but contain poison). - */ - bool hasValue() const { - return fExpression != nullptr; - } - - /** - * Returns true if this object contains an expression which is not poison. - */ - bool isValid() const; - - SK_CLANG_REINITIALIZES void swap(DSLExpression& other); - - /** - * Invalidates this object and returns the SkSL expression it represents. It is an error to call - * this on an invalid DSLExpression. - */ - std::unique_ptr release(); - -private: - /** - * Calls release if this expression has a value, otherwise returns null. - */ - std::unique_ptr releaseIfPossible(); - - std::unique_ptr fExpression; - - friend DSLExpression SampleChild(int index, DSLExpression coords); - - friend class DSLCore; - friend class DSLVarBase; - friend class DSLWriter; -}; - -DSLExpression operator+(DSLExpression left, DSLExpression right); -DSLExpression operator+(DSLExpression expr); -DSLExpression operator+=(DSLExpression left, DSLExpression right); -DSLExpression operator-(DSLExpression left, DSLExpression right); -DSLExpression operator-(DSLExpression expr); -DSLExpression operator-=(DSLExpression left, DSLExpression right); -DSLExpression operator*(DSLExpression left, DSLExpression right); -DSLExpression operator*=(DSLExpression left, DSLExpression right); -DSLExpression operator/(DSLExpression left, DSLExpression right); -DSLExpression operator/=(DSLExpression left, DSLExpression right); -DSLExpression operator%(DSLExpression left, DSLExpression right); -DSLExpression operator%=(DSLExpression left, DSLExpression right); -DSLExpression operator<<(DSLExpression left, DSLExpression right); -DSLExpression operator<<=(DSLExpression left, DSLExpression right); -DSLExpression operator>>(DSLExpression left, DSLExpression right); -DSLExpression operator>>=(DSLExpression left, DSLExpression right); -DSLExpression operator&&(DSLExpression left, DSLExpression right); -DSLExpression operator||(DSLExpression left, DSLExpression right); -DSLExpression operator&(DSLExpression left, DSLExpression right); -DSLExpression operator&=(DSLExpression left, DSLExpression right); -DSLExpression operator|(DSLExpression left, DSLExpression right); -DSLExpression operator|=(DSLExpression left, DSLExpression right); -DSLExpression operator^(DSLExpression left, DSLExpression right); -DSLExpression operator^=(DSLExpression left, DSLExpression right); -DSLExpression LogicalXor(DSLExpression left, DSLExpression right); -DSLExpression operator,(DSLExpression left, DSLExpression right); -DSLExpression operator==(DSLExpression left, DSLExpression right); -DSLExpression operator!=(DSLExpression left, DSLExpression right); -DSLExpression operator>(DSLExpression left, DSLExpression right); -DSLExpression operator<(DSLExpression left, DSLExpression right); -DSLExpression operator>=(DSLExpression left, DSLExpression right); -DSLExpression operator<=(DSLExpression left, DSLExpression right); -DSLExpression operator!(DSLExpression expr); -DSLExpression operator~(DSLExpression expr); -DSLExpression operator++(DSLExpression expr); -DSLExpression operator++(DSLExpression expr, int); -DSLExpression operator--(DSLExpression expr); -DSLExpression operator--(DSLExpression expr, int); - -} // namespace dsl - -} // namespace SkSL - -template struct sk_is_trivially_relocatable; - -template <> -struct sk_is_trivially_relocatable : std::true_type {}; - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h deleted file mode 100644 index de7b8f1fbcb6d..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_FUNCTION -#define SKSL_DSL_FUNCTION - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLBlock.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/DSLVar.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include - -namespace SkSL { - -class FunctionDeclaration; - -namespace dsl { - -class DSLType; - -class DSLFunction { -public: - template - DSLFunction(const DSLType& returnType, std::string_view name, Parameters&... parameters) - : DSLFunction(DSLModifiers(), returnType, name, parameters...) {} - - template - DSLFunction(const DSLModifiers& modifiers, const DSLType& returnType, std::string_view name, - Parameters&... parameters) { - SkTArray parameterArray; - parameterArray.reserve_back(sizeof...(parameters)); - (parameterArray.push_back(¶meters), ...); - - // We can't have a default parameter and a template parameter pack at the same time, so - // unfortunately we can't capture position from this overload. - this->init(modifiers, returnType, name, std::move(parameterArray), Position()); - } - - DSLFunction(std::string_view name, const DSLModifiers& modifiers, const DSLType& returnType, - SkTArray parameters, Position pos = {}) { - this->init(modifiers, returnType, name, std::move(parameters), pos); - } - - DSLFunction(SkSL::FunctionDeclaration* decl) - : fDecl(decl) {} - - virtual ~DSLFunction() = default; - - template - void define(Stmt... stmts) { - DSLBlock block = DSLBlock(DSLStatement(std::move(stmts))...); - this->define(std::move(block)); - } - - void define(DSLBlock block, Position pos = {}); - - void prototype(); - - /** - * Invokes the function with the given arguments. - */ - template - DSLExpression operator()(Args&&... args) { - ExpressionArray argArray; - argArray.reserve_back(sizeof...(args)); - this->collectArgs(argArray, std::forward(args)...); - return this->call(std::move(argArray)); - } - - /** - * Invokes the function with the given arguments. - */ - DSLExpression call(SkTArray args, Position pos = {}); - - DSLExpression call(ExpressionArray args, Position pos = {}); - -private: - void collectArgs(ExpressionArray& args) {} - - template - void collectArgs(ExpressionArray& args, DSLVar& var, RemainingArgs&&... remaining) { - args.push_back(DSLExpression(var).release()); - collectArgs(args, std::forward(remaining)...); - } - - template - void collectArgs(ExpressionArray& args, DSLExpression expr, RemainingArgs&&... remaining) { - args.push_back(expr.release()); - collectArgs(args, std::forward(remaining)...); - } - - void init(DSLModifiers modifiers, const DSLType& returnType, std::string_view name, - SkTArray params, Position pos); - - SkSL::FunctionDeclaration* fDecl = nullptr; - SkSL::Position fPosition; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h deleted file mode 100644 index a1c963a74eacd..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_LAYOUT -#define SKSL_DSL_LAYOUT - -#include "include/private/SkSLLayout.h" -#include "include/sksl/SkSLPosition.h" - -namespace SkSL { - -namespace dsl { - -class DSLLayout { -public: - DSLLayout() {} - - DSLLayout& originUpperLeft(Position pos = {}) { - return this->flag(SkSL::Layout::kOriginUpperLeft_Flag, "origin_upper_left", pos); - } - - DSLLayout& pushConstant(Position pos = {}) { - return this->flag(SkSL::Layout::kPushConstant_Flag, "push_constant", pos); - } - - DSLLayout& blendSupportAllEquations(Position pos = {}) { - return this->flag(SkSL::Layout::kBlendSupportAllEquations_Flag, - "blend_support_all_equations", pos); - } - - DSLLayout& color(Position pos = {}) { - return this->flag(SkSL::Layout::kColor_Flag, "color", pos); - } - - DSLLayout& location(int location, Position pos = {}) { - return this->intValue(&fSkSLLayout.fLocation, location, SkSL::Layout::kLocation_Flag, - "location", pos); - } - - DSLLayout& offset(int offset, Position pos = {}) { - return this->intValue(&fSkSLLayout.fOffset, offset, SkSL::Layout::kOffset_Flag, "offset", - pos); - } - - DSLLayout& binding(int binding, Position pos = {}) { - return this->intValue(&fSkSLLayout.fBinding, binding, SkSL::Layout::kBinding_Flag, - "binding", pos); - } - - DSLLayout& index(int index, Position pos = {}) { - return this->intValue(&fSkSLLayout.fIndex, index, SkSL::Layout::kIndex_Flag, "index", pos); - } - - DSLLayout& set(int set, Position pos = {}) { - return this->intValue(&fSkSLLayout.fSet, set, SkSL::Layout::kSet_Flag, "set", pos); - } - - DSLLayout& builtin(int builtin, Position pos = {}) { - return this->intValue(&fSkSLLayout.fBuiltin, builtin, SkSL::Layout::kBuiltin_Flag, - "builtin", pos); - } - - DSLLayout& inputAttachmentIndex(int inputAttachmentIndex, - Position pos = {}) { - return this->intValue(&fSkSLLayout.fInputAttachmentIndex, inputAttachmentIndex, - SkSL::Layout::kInputAttachmentIndex_Flag, "input_attachment_index", - pos); - } - -private: - explicit DSLLayout(SkSL::Layout skslLayout) - : fSkSLLayout(skslLayout) {} - - DSLLayout& flag(SkSL::Layout::Flag mask, const char* name, Position pos); - - DSLLayout& intValue(int* target, int value, SkSL::Layout::Flag flag, const char* name, - Position pos); - - SkSL::Layout fSkSLLayout; - - friend class DSLModifiers; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h deleted file mode 100644 index 01fb0623376d8..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_MODIFIERS -#define SKSL_DSL_MODIFIERS - -#include "include/core/SkSpan.h" -#include "include/private/SkSLModifiers.h" -#include "include/sksl/DSLLayout.h" - -namespace SkSL { - -namespace dsl { - -class DSLField; -class DSLType; - -enum Modifier { - kNo_Modifier = SkSL::Modifiers::kNo_Flag, - kConst_Modifier = SkSL::Modifiers::kConst_Flag, - kIn_Modifier = SkSL::Modifiers::kIn_Flag, - kOut_Modifier = SkSL::Modifiers::kOut_Flag, - kInOut_Modifier = SkSL::Modifiers::kIn_Flag | SkSL::Modifiers::kOut_Flag, - kUniform_Modifier = SkSL::Modifiers::kUniform_Flag, - kFlat_Modifier = SkSL::Modifiers::kFlat_Flag, - kNoPerspective_Modifier = SkSL::Modifiers::kNoPerspective_Flag, -}; - -class DSLModifiers { -public: - DSLModifiers(int flags = 0, Position pos = {}) - : DSLModifiers(DSLLayout(), flags, pos) {} - - DSLModifiers(DSLLayout layout, int flags = 0, Position pos = {}) - : fModifiers(layout.fSkSLLayout, flags) - , fPosition(pos) {} - - int& flags() { - return fModifiers.fFlags; - } - - const int& flags() const { - return fModifiers.fFlags; - } - - DSLLayout layout() const { - return DSLLayout(fModifiers.fLayout); - } - -private: - SkSL::Modifiers fModifiers; - Position fPosition; - - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); - friend class DSLCore; - friend class DSLFunction; - friend class DSLType; - friend class DSLWriter; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h deleted file mode 100644 index 391e911d3aac9..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_STATEMENT -#define SKSL_DSL_STATEMENT - -#include "include/core/SkTypes.h" -#include "include/private/SkSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include - -namespace SkSL { - -class Expression; - -namespace dsl { - -class DSLBlock; -class DSLExpression; - -class DSLStatement { -public: - DSLStatement(); - - DSLStatement(DSLExpression expr); - - DSLStatement(DSLBlock block); - - DSLStatement(DSLStatement&&) = default; - - DSLStatement(std::unique_ptr expr); - - DSLStatement(std::unique_ptr stmt, Position pos); - - DSLStatement(std::unique_ptr stmt); - - ~DSLStatement(); - - DSLStatement& operator=(DSLStatement&& other) = default; - - Position position() { - SkASSERT(this->hasValue()); - return fStatement->fPosition; - } - - void setPosition(Position pos) { - SkASSERT(this->hasValue()); - fStatement->fPosition = pos; - } - - bool hasValue() { return fStatement != nullptr; } - - std::unique_ptr release() { - SkASSERT(this->hasValue()); - return std::move(fStatement); - } - -private: - std::unique_ptr releaseIfPossible() { - return std::move(fStatement); - } - - std::unique_ptr fStatement; - - friend class DSLCore; - friend class DSLWriter; - friend DSLStatement operator,(DSLStatement left, DSLStatement right); -}; - -DSLStatement operator,(DSLStatement left, DSLStatement right); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h deleted file mode 100644 index dfd45d1b34280..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_SYMBOLS -#define SKSL_DSL_SYMBOLS - -#include "include/sksl/DSLExpression.h" - -#include -#include - -namespace SkSL { - -class Position; -class SymbolTable; - -namespace dsl { - -class DSLVarBase; - -// This header provides methods for manually managing symbol tables in DSL code. They should not be -// used by normal hand-written DSL code, where we rely on C++ to manage symbols, but are instead -// needed when DSL objects are being constructed programmatically (as in Parser). - -/** - * Pushes a new symbol table onto the symbol table stack. - */ -void PushSymbolTable(); - -/** - * Pops the top symbol table from the stack. As symbol tables are shared pointers, this will only - * destroy the symbol table if it was never attached to anything (e.g. passed into a Block - * constructor). - */ -void PopSymbolTable(); - -/** - * Returns the current symbol table. Outside of SkSL itself, this is an opaque pointer, used only - * for passing it to DSL methods that require it. - */ -std::shared_ptr CurrentSymbolTable(); - -/** - * Returns an expression referring to the named symbol. - */ -DSLExpression Symbol(std::string_view name, Position pos = {}); - -/** - * Adds a variable to the current symbol table. - */ -void AddToSymbolTable(DSLVarBase& var, Position pos = {}); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h deleted file mode 100644 index d15e01b3a3eac..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_TYPE -#define SKSL_DSL_TYPE - -#include "include/core/SkSpan.h" -#include "include/core/SkTypes.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include - -namespace SkSL { - -class Compiler; -class Type; - -namespace dsl { - -class DSLField; -class DSLVarBase; - -enum TypeConstant : uint8_t { - kBool_Type, - kBool2_Type, - kBool3_Type, - kBool4_Type, - kHalf_Type, - kHalf2_Type, - kHalf3_Type, - kHalf4_Type, - kHalf2x2_Type, - kHalf3x2_Type, - kHalf4x2_Type, - kHalf2x3_Type, - kHalf3x3_Type, - kHalf4x3_Type, - kHalf2x4_Type, - kHalf3x4_Type, - kHalf4x4_Type, - kFloat_Type, - kFloat2_Type, - kFloat3_Type, - kFloat4_Type, - kFragmentProcessor_Type, - kFloat2x2_Type, - kFloat3x2_Type, - kFloat4x2_Type, - kFloat2x3_Type, - kFloat3x3_Type, - kFloat4x3_Type, - kFloat2x4_Type, - kFloat3x4_Type, - kFloat4x4_Type, - kInt_Type, - kInt2_Type, - kInt3_Type, - kInt4_Type, - kShader_Type, - kShort_Type, - kShort2_Type, - kShort3_Type, - kShort4_Type, - kUInt_Type, - kUInt2_Type, - kUInt3_Type, - kUInt4_Type, - kUShort_Type, - kUShort2_Type, - kUShort3_Type, - kUShort4_Type, - kVoid_Type, - kPoison_Type, -}; - -class DSLType { -public: - DSLType(TypeConstant tc, Position pos = {}); - - DSLType(const SkSL::Type* type, Position pos = {}); - - DSLType(std::string_view name, Position pos = {}); - - DSLType(std::string_view name, - DSLModifiers* modifiers, - Position pos = {}); - - /** - * Returns true if the SkSL type is non-null. - */ - bool hasValue() const { return fSkSLType != nullptr; } - - /** - * Returns true if this type is a bool. - */ - bool isBoolean() const; - - /** - * Returns true if this is a numeric scalar type. - */ - bool isNumber() const; - - /** - * Returns true if this is a floating-point scalar type (float or half). - */ - bool isFloat() const; - - /** - * Returns true if this is a signed scalar type (int or short). - */ - bool isSigned() const; - - /** - * Returns true if this is an unsigned scalar type (uint or ushort). - */ - bool isUnsigned() const; - - /** - * Returns true if this is a signed or unsigned integer. - */ - bool isInteger() const; - - /** - * Returns true if this is a scalar type. - */ - bool isScalar() const; - - /** - * Returns true if this is a vector type. - */ - bool isVector() const; - - /** - * Returns true if this is a matrix type. - */ - bool isMatrix() const; - - /** - * Returns true if this is a array type. - */ - bool isArray() const; - - /** - * Returns true if this is a struct type. - */ - bool isStruct() const; - - /** - * Returns true if this is a Skia object type (shader, colorFilter, blender). - */ - bool isEffectChild() const; - - template - static DSLExpression Construct(DSLType type, DSLVarBase& var, Args&&... args) { - DSLExpression argArray[] = {var, args...}; - return Construct(type, SkSpan(argArray)); - } - - template - static DSLExpression Construct(DSLType type, DSLExpression expr, Args&&... args) { - DSLExpression argArray[] = {std::move(expr), std::move(args)...}; - return Construct(type, SkSpan(argArray)); - } - - static DSLExpression Construct(DSLType type, SkSpan argArray); - -private: - const SkSL::Type& skslType() const { - SkASSERT(fSkSLType); - return *fSkSLType; - } - - const SkSL::Type* fSkSLType = nullptr; - - friend DSLType Array(const DSLType& base, int count, Position pos); - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); - friend DSLType UnsizedArray(const DSLType& base, Position pos); - friend class DSLCore; - friend class DSLFunction; - friend class DSLVarBase; - friend class DSLWriter; - friend class SkSL::Compiler; -}; - -#define TYPE(T) \ - template \ - DSLExpression T(Args&&... args) { \ - return DSLType::Construct(k ## T ## _Type, std::forward(args)...); \ - } - -#define VECTOR_TYPE(T) \ - TYPE(T) \ - TYPE(T ## 2) \ - TYPE(T ## 3) \ - TYPE(T ## 4) - -#define MATRIX_TYPE(T) \ - TYPE(T ## 2x2) \ - TYPE(T ## 3x2) \ - TYPE(T ## 4x2) \ - TYPE(T ## 2x3) \ - TYPE(T ## 3x3) \ - TYPE(T ## 4x3) \ - TYPE(T ## 2x4) \ - TYPE(T ## 3x4) \ - TYPE(T ## 4x4) - -VECTOR_TYPE(Bool) -VECTOR_TYPE(Float) -VECTOR_TYPE(Half) -VECTOR_TYPE(Int) -VECTOR_TYPE(UInt) -VECTOR_TYPE(Short) -VECTOR_TYPE(UShort) - -MATRIX_TYPE(Float) -MATRIX_TYPE(Half) - -#undef TYPE -#undef VECTOR_TYPE -#undef MATRIX_TYPE - -DSLType Array(const DSLType& base, int count, Position pos = {}); - -DSLType UnsizedArray(const DSLType& base, Position pos = {}); - -class DSLField { -public: - DSLField(const DSLType type, std::string_view name, - Position pos = {}) - : DSLField(DSLModifiers(), type, name, pos) {} - - DSLField(const DSLModifiers& modifiers, const DSLType type, std::string_view name, - Position pos = {}) - : fModifiers(modifiers) - , fType(type) - , fName(name) - , fPosition(pos) {} - -private: - DSLModifiers fModifiers; - const DSLType fType; - std::string_view fName; - Position fPosition; - - friend class DSLCore; - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); -}; - -DSLType Struct(std::string_view name, SkSpan fields, - Position pos = {}); - -template -DSLType Struct(std::string_view name, Field... fields) { - DSLField fieldTypes[] = {std::move(fields)...}; - return Struct(name, SkSpan(fieldTypes), Position()); -} - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h deleted file mode 100644 index f052a525e355d..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_VAR -#define SKSL_DSL_VAR - -#include "include/private/SkSLStatement.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/DSLType.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Expression; -class ExpressionArray; -class Variable; -enum class VariableStorage : int8_t; - -namespace dsl { - -class DSLVarBase { -public: - /** - * Constructs a new variable with the specified type and name. - */ - DSLVarBase(VariableStorage storage, DSLType type, std::string_view name, - DSLExpression initialValue, Position pos, Position namePos); - - DSLVarBase(VariableStorage storage, const DSLModifiers& modifiers, DSLType type, - std::string_view name, DSLExpression initialValue, Position pos, Position namePos); - - DSLVarBase(DSLVarBase&&) = default; - - std::string_view name() const { - return fName; - } - - const DSLModifiers& modifiers() const { - return fModifiers; - } - - VariableStorage storage() const { - return fStorage; - } - - DSLExpression x() { - return DSLExpression(*this).x(); - } - - DSLExpression y() { - return DSLExpression(*this).y(); - } - - DSLExpression z() { - return DSLExpression(*this).z(); - } - - DSLExpression w() { - return DSLExpression(*this).w(); - } - - DSLExpression r() { - return DSLExpression(*this).r(); - } - - DSLExpression g() { - return DSLExpression(*this).g(); - } - - DSLExpression b() { - return DSLExpression(*this).b(); - } - - DSLExpression a() { - return DSLExpression(*this).a(); - } - - DSLExpression field(std::string_view name) { - return DSLExpression(*this).field(name); - } - - DSLExpression operator[](DSLExpression&& index); - - DSLExpression operator++() { - return ++DSLExpression(*this); - } - - DSLExpression operator++(int) { - return DSLExpression(*this)++; - } - - DSLExpression operator--() { - return --DSLExpression(*this); - } - - DSLExpression operator--(int) { - return DSLExpression(*this)--; - } - - template DSLExpression assign(T&& param) { - return this->assignExpression(DSLExpression(std::forward(param))); - } - -protected: - /** - * Creates an empty, unpopulated var. Can be replaced with a real var later via `swap`. - */ - DSLVarBase(VariableStorage storage) : fType(kVoid_Type), fStorage(storage) {} - - DSLExpression assignExpression(DSLExpression other); - - void swap(DSLVarBase& other); - - DSLModifiers fModifiers; - // We only need to keep track of the type here so that we can create the SkSL::Variable. For - // predefined variables this field is unnecessary, so we don't bother tracking it and just set - // it to kVoid; in other words, you shouldn't generally be relying on this field to be correct. - // If you need to determine the variable's type, look at DSLWriter::Var(...)->type() instead. - DSLType fType; - std::unique_ptr fDeclaration; - SkSL::Variable* fVar = nullptr; - Position fNamePosition; - std::string_view fName; - DSLExpression fInitialValue; - Position fPosition; - VariableStorage fStorage; - bool fInitialized = false; - - friend class DSLCore; - friend class DSLFunction; - friend class DSLWriter; -}; - -/** - * A local variable. - */ -class DSLVar : public DSLVarBase { -public: - DSLVar(); - - DSLVar(DSLType type, std::string_view name, DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLVar(const DSLModifiers& modifiers, DSLType type, std::string_view name, - DSLExpression initialValue = DSLExpression(), Position pos = {}, Position namePos = {}); - - DSLVar(DSLVar&&) = default; - - void swap(DSLVar& other); - -private: - using INHERITED = DSLVarBase; -}; - -/** - * A global variable. - */ -class DSLGlobalVar : public DSLVarBase { -public: - DSLGlobalVar(); - - DSLGlobalVar(DSLType type, std::string_view name, DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLGlobalVar(const DSLModifiers& modifiers, DSLType type, std::string_view name, - DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLGlobalVar(const char* name); - - DSLGlobalVar(DSLGlobalVar&&) = default; - - void swap(DSLGlobalVar& other); - - /** - * Implements the following method calls: - * half4 shader::eval(float2 coords); - * half4 colorFilter::eval(half4 input); - */ - DSLExpression eval(DSLExpression x, Position pos = {}); - - /** - * Implements the following method call: - * half4 blender::eval(half4 src, half4 dst); - */ - DSLExpression eval(DSLExpression x, DSLExpression y, Position pos = {}); - -private: - DSLExpression eval(ExpressionArray args, Position pos); - - std::unique_ptr methodCall(std::string_view methodName, Position pos); - - using INHERITED = DSLVarBase; -}; - -/** - * A function parameter. - */ -class DSLParameter : public DSLVarBase { -public: - DSLParameter(); - - DSLParameter(DSLType type, std::string_view name, Position pos = {}, Position namePos = {}); - - DSLParameter(const DSLModifiers& modifiers, DSLType type, std::string_view name, - Position pos = {}, Position namePos = {}); - - DSLParameter(DSLParameter&&) = default; - - void swap(DSLParameter& other); - -private: - using INHERITED = DSLVarBase; -}; - -} // namespace dsl - -} // namespace SkSL - - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h deleted file mode 100644 index 4abf4631b8b17..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_ERROR_REPORTER -#define SKSL_ERROR_REPORTER - -#include "include/core/SkTypes.h" - -#include - -namespace SkSL { - -class Position; - -/** - * Class which is notified in the event of an error. - */ -class ErrorReporter { -public: - ErrorReporter() {} - - virtual ~ErrorReporter() {} - - void error(Position position, std::string_view msg); - - std::string_view source() const { return fSource; } - - void setSource(std::string_view source) { fSource = source; } - - int errorCount() const { - return fErrorCount; - } - - void resetErrorCount() { - fErrorCount = 0; - } - -protected: - /** - * Called when an error is reported. - */ - virtual void handleError(std::string_view msg, Position position) = 0; - -private: - Position position(int offset) const; - - std::string_view fSource; - int fErrorCount = 0; -}; - -/** - * Error reporter for tests that need an SkSL context; aborts immediately if an error is reported. - */ -class TestingOnly_AbortErrorReporter : public ErrorReporter { -public: - void handleError(std::string_view msg, Position pos) override; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h deleted file mode 100644 index 1e47dce618856..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_OPERATOR -#define SKSL_OPERATOR - -#include -#include - -namespace SkSL { - -class Context; -class Type; - -enum class OperatorKind : uint8_t { - PLUS, - MINUS, - STAR, - SLASH, - PERCENT, - SHL, - SHR, - LOGICALNOT, - LOGICALAND, - LOGICALOR, - LOGICALXOR, - BITWISENOT, - BITWISEAND, - BITWISEOR, - BITWISEXOR, - EQ, - EQEQ, - NEQ, - LT, - GT, - LTEQ, - GTEQ, - PLUSEQ, - MINUSEQ, - STAREQ, - SLASHEQ, - PERCENTEQ, - SHLEQ, - SHREQ, - BITWISEANDEQ, - BITWISEOREQ, - BITWISEXOREQ, - PLUSPLUS, - MINUSMINUS, - COMMA -}; - -enum class OperatorPrecedence : uint8_t { - kParentheses = 1, - kPostfix = 2, - kPrefix = 3, - kMultiplicative = 4, - kAdditive = 5, - kShift = 6, - kRelational = 7, - kEquality = 8, - kBitwiseAnd = 9, - kBitwiseXor = 10, - kBitwiseOr = 11, - kLogicalAnd = 12, - kLogicalXor = 13, - kLogicalOr = 14, - kTernary = 15, - kAssignment = 16, - kSequence = 17, - kTopLevel = kSequence -}; - -class Operator { -public: - using Kind = OperatorKind; - - Operator(Kind op) : fKind(op) {} - - Kind kind() const { return fKind; } - - bool isEquality() const { - return fKind == Kind::EQEQ || fKind == Kind::NEQ; - } - - OperatorPrecedence getBinaryPrecedence() const; - - // Returns the operator name surrounded by the expected whitespace for a tidy binary expression. - const char* operatorName() const; - - // Returns the operator name without any surrounding whitespace. - std::string_view tightOperatorName() const; - - // Returns true if op is '=' or any compound assignment operator ('+=', '-=', etc.) - bool isAssignment() const; - - // Given a compound assignment operator, returns the non-assignment version of the operator - // (e.g. '+=' becomes '+') - Operator removeAssignment() const; - - /** - * Defines the set of relational (comparison) operators: - * < <= > >= - */ - bool isRelational() const; - - /** - * Defines the set of operators which are only valid on integral types: - * << <<= >> >>= & &= | |= ^ ^= % %= - */ - bool isOnlyValidForIntegralTypes() const; - - /** - * Defines the set of operators which perform vector/matrix math. - * + += - -= * *= / /= % %= << <<= >> >>= & &= | |= ^ ^= - */ - bool isValidForMatrixOrVector() const; - - /* - * Defines the set of operators allowed by The OpenGL ES Shading Language 1.00, Section 5.1. - * The set of illegal (reserved) operators are the ones that only make sense with integral - * types. This is not a coincidence: It's because ES2 doesn't require 'int' to be anything but - * syntactic sugar for floats with truncation after each operation. - */ - bool isAllowedInStrictES2Mode() const { - return !this->isOnlyValidForIntegralTypes(); - } - - /** - * Determines the operand and result types of a binary expression. Returns true if the - * expression is legal, false otherwise. If false, the values of the out parameters are - * undefined. - */ - bool determineBinaryType(const Context& context, - const Type& left, - const Type& right, - const Type** outLeftType, - const Type** outRightType, - const Type** outResultType) const; - -private: - bool isOperator() const; - bool isMatrixMultiply(const Type& left, const Type& right) const; - - Kind fKind; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h deleted file mode 100644 index 5f8e80a607b8f..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_POSITION -#define SKSL_POSITION - -#include "include/core/SkTypes.h" - -#include -#include - -namespace SkSL { - -class Position { -public: - Position() - : fStartOffset(-1) - , fLength(0) {} - - static Position Range(int startOffset, int endOffset) { - SkASSERT(startOffset <= endOffset); - SkASSERT(startOffset <= 0xFFFFFF); - int length = endOffset - startOffset; - Position result; - result.fStartOffset = startOffset; - result.fLength = length <= 0xFF ? length : 0xFF; - return result; - } - - bool valid() const { - return fStartOffset != -1; - } - - int line(std::string_view source) const; - - int startOffset() const { - SkASSERT(this->valid()); - return fStartOffset; - } - - int endOffset() const { - SkASSERT(this->valid()); - return fStartOffset + fLength; - } - - // Returns the position from this through, and including the entirety of, end. - Position rangeThrough(Position end) const { - if (fStartOffset == -1 || end.fStartOffset == -1) { - return *this; - } - SkASSERTF(this->startOffset() <= end.startOffset() && this->endOffset() <= end.endOffset(), - "Invalid range: (%d-%d) - (%d-%d)\n", this->startOffset(), this->endOffset(), - end.startOffset(), end.endOffset()); - return Range(this->startOffset(), end.endOffset()); - } - - // Returns a position representing the character immediately after this position - Position after() const { - int endOffset = this->endOffset(); - return Range(endOffset, endOffset + 1); - } - - bool operator==(const Position& other) const { - return fStartOffset == other.fStartOffset && fLength == other.fLength; - } - - bool operator!=(const Position& other) const { - return !(*this == other); - } - - bool operator>(const Position& other) const { - return fStartOffset > other.fStartOffset; - } - - bool operator>=(const Position& other) const { - return fStartOffset >= other.fStartOffset; - } - - bool operator<(const Position& other) const { - return fStartOffset < other.fStartOffset; - } - - bool operator<=(const Position& other) const { - return fStartOffset <= other.fStartOffset; - } - -private: - int32_t fStartOffset : 24; - uint32_t fLength : 8; -}; - -struct ForLoopPositions { - Position initPosition = Position(); - Position conditionPosition = Position(); - Position nextPosition = Position(); -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h index d2c8b8b23b964..536691875e4f4 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h @@ -14,7 +14,7 @@ #include "include/core/SkMatrix.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" // NOTE -- This entire header / impl is deprecated, and will be removed from Skia soon. // diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h index afdf91e5ebcb8..d387fb24ca6bc 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h @@ -14,12 +14,15 @@ #include "include/core/SkPath.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" +#include #include class SkStream; -class SkTypeface; +class SkStreamAsset; +struct SkFontArguments; class SK_API SkCustomTypefaceBuilder { public: @@ -33,6 +36,9 @@ class SK_API SkCustomTypefaceBuilder { sk_sp detach(); + static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('u','s','e','r'); + static sk_sp MakeFromStream(std::unique_ptr, const SkFontArguments&); + private: struct GlyphRec { // logical union diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h index 5ef7a103a98af..87c6916b39f09 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h @@ -9,17 +9,14 @@ #ifndef SkNWayCanvas_DEFINED #define SkNWayCanvas_DEFINED -#include "include/core/SkBlendMode.h" -#include "include/core/SkCanvas.h" #include "include/core/SkCanvasVirtualEnforcer.h" -#include "include/core/SkClipOp.h" #include "include/core/SkColor.h" #include "include/core/SkM44.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSamplingOptions.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" #include "include/utils/SkNoDrawCanvas.h" #include @@ -28,6 +25,7 @@ namespace sktext { class GlyphRunList; } +class SkCanvas; class SkData; class SkDrawable; class SkImage; @@ -40,12 +38,14 @@ class SkRegion; class SkShader; class SkTextBlob; class SkVertices; +enum class SkBlendMode; +enum class SkClipOp; struct SkDrawShadowRec; struct SkPoint; struct SkRSXform; struct SkRect; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) namespace sktext::gpu { class Slug; } @@ -77,7 +77,7 @@ class SK_API SkNWayCanvas : public SkCanvasVirtualEnforcer { void onDrawGlyphRunList(const sktext::GlyphRunList&, const SkPaint&) override; void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) override; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) void onDrawSlug(const sktext::gpu::Slug* slug) override; #endif void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h index a03bfdb54108a..0b686e5edc5af 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h @@ -39,14 +39,15 @@ class SK_API SkOrderedFontMgr : public SkFontMgr { protected: int onCountFamilies() const override; void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onCreateStyleSet(int index)const override; + sk_sp onCreateStyleSet(int index)const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkTypeface* onMatchFamilyStyle(const char familyName[], const SkFontStyle&) const override; - SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const override; + sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle&) const override; + sk_sp onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const override; // Note: all of these always return null sk_sp onMakeFromData(sk_sp, int ttcIndex) const override; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h index 5ce3c26f1dc74..9a836bc7c2551 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h @@ -8,7 +8,6 @@ #ifndef SkPaintFilterCanvas_DEFINED #define SkPaintFilterCanvas_DEFINED -#include "include/core/SkBlendMode.h" #include "include/core/SkCanvas.h" #include "include/core/SkCanvasVirtualEnforcer.h" #include "include/core/SkColor.h" @@ -18,7 +17,7 @@ #include "include/core/SkScalar.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" #include "include/utils/SkNWayCanvas.h" #include @@ -42,6 +41,7 @@ class SkSurface; class SkSurfaceProps; class SkTextBlob; class SkVertices; +enum class SkBlendMode; struct SkDrawShadowRec; struct SkPoint; struct SkRSXform; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h index f1c81b2f28d3c..acd0ef2305c03 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h @@ -19,7 +19,7 @@ class SK_API SkParsePath { static bool FromSVGString(const char str[], SkPath*); enum class PathEncoding { Absolute, Relative }; - static void ToSVGString(const SkPath&, SkString*, PathEncoding = PathEncoding::Absolute); + static SkString ToSVGString(const SkPath&, PathEncoding = PathEncoding::Absolute); }; #endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h deleted file mode 100644 index ba40732b9cf7a..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2006 The Android Open Source Project - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkRandom_DEFINED -#define SkRandom_DEFINED - -#include "include/core/SkScalar.h" -#include "include/private/SkFixed.h" -#include "include/private/SkFloatBits.h" - -/** \class SkRandom - - Utility class that implements pseudo random 32bit numbers using Marsaglia's - multiply-with-carry "mother of all" algorithm. Unlike rand(), this class holds - its own state, so that multiple instances can be used with no side-effects. - - Has a large period and all bits are well-randomized. - */ -class SkRandom { -public: - SkRandom() { init(0); } - SkRandom(uint32_t seed) { init(seed); } - SkRandom(const SkRandom& rand) : fK(rand.fK), fJ(rand.fJ) {} - - SkRandom& operator=(const SkRandom& rand) { - fK = rand.fK; - fJ = rand.fJ; - - return *this; - } - - /** Return the next pseudo random number as an unsigned 32bit value. - */ - uint32_t nextU() { - fK = kKMul*(fK & 0xffff) + (fK >> 16); - fJ = kJMul*(fJ & 0xffff) + (fJ >> 16); - return (((fK << 16) | (fK >> 16)) + fJ); - } - - /** Return the next pseudo random number as a signed 32bit value. - */ - int32_t nextS() { return (int32_t)this->nextU(); } - - /** - * Returns value [0...1) as an IEEE float - */ - float nextF() { - int floatint = 0x3f800000 | (int)(this->nextU() >> 9); - float f = SkBits2Float(floatint) - 1.0f; - return f; - } - - /** - * Returns value [min...max) as a float - */ - float nextRangeF(float min, float max) { - return min + this->nextF() * (max - min); - } - - /** Return the next pseudo random number, as an unsigned value of - at most bitCount bits. - @param bitCount The maximum number of bits to be returned - */ - uint32_t nextBits(unsigned bitCount) { - SkASSERT(bitCount > 0 && bitCount <= 32); - return this->nextU() >> (32 - bitCount); - } - - /** Return the next pseudo random unsigned number, mapped to lie within - [min, max] inclusive. - */ - uint32_t nextRangeU(uint32_t min, uint32_t max) { - SkASSERT(min <= max); - uint32_t range = max - min + 1; - if (0 == range) { - return this->nextU(); - } else { - return min + this->nextU() % range; - } - } - - /** Return the next pseudo random unsigned number, mapped to lie within - [0, count). - */ - uint32_t nextULessThan(uint32_t count) { - SkASSERT(count > 0); - return this->nextRangeU(0, count - 1); - } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [0..SK_Scalar1). - */ - SkScalar nextUScalar1() { return SkFixedToScalar(this->nextUFixed1()); } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [min..max). - */ - SkScalar nextRangeScalar(SkScalar min, SkScalar max) { - return this->nextUScalar1() * (max - min) + min; - } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [-SK_Scalar1..SK_Scalar1). - */ - SkScalar nextSScalar1() { return SkFixedToScalar(this->nextSFixed1()); } - - /** Return the next pseudo random number as a bool. - */ - bool nextBool() { return this->nextU() >= 0x80000000; } - - /** A biased version of nextBool(). - */ - bool nextBiasedBool(SkScalar fractionTrue) { - SkASSERT(fractionTrue >= 0 && fractionTrue <= SK_Scalar1); - return this->nextUScalar1() <= fractionTrue; - } - - /** Reset the random object. - */ - void setSeed(uint32_t seed) { init(seed); } - -private: - // Initialize state variables with LCG. - // We must ensure that both J and K are non-zero, otherwise the - // multiply-with-carry step will forevermore return zero. - void init(uint32_t seed) { - fK = NextLCG(seed); - if (0 == fK) { - fK = NextLCG(fK); - } - fJ = NextLCG(fK); - if (0 == fJ) { - fJ = NextLCG(fJ); - } - SkASSERT(0 != fK && 0 != fJ); - } - static uint32_t NextLCG(uint32_t seed) { return kMul*seed + kAdd; } - - /** Return the next pseudo random number expressed as an unsigned SkFixed - in the range [0..SK_Fixed1). - */ - SkFixed nextUFixed1() { return this->nextU() >> 16; } - - /** Return the next pseudo random number expressed as a signed SkFixed - in the range [-SK_Fixed1..SK_Fixed1). - */ - SkFixed nextSFixed1() { return this->nextS() >> 15; } - - // See "Numerical Recipes in C", 1992 page 284 for these constants - // For the LCG that sets the initial state from a seed - enum { - kMul = 1664525, - kAdd = 1013904223 - }; - // Constants for the multiply-with-carry steps - enum { - kKMul = 30345, - kJMul = 18000, - }; - - uint32_t fK; - uint32_t fJ; -}; - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h index 2ee56934ade6d..322549b38f7ed 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h @@ -51,6 +51,17 @@ SKCMS_API float skcms_TransferFunction_eval (const skcms_TransferFunction*, flo SKCMS_API bool skcms_TransferFunction_invert(const skcms_TransferFunction*, skcms_TransferFunction*); +typedef enum skcms_TFType { + skcms_TFType_Invalid, + skcms_TFType_sRGBish, + skcms_TFType_PQish, + skcms_TFType_HLGish, + skcms_TFType_HLGinvish, +} skcms_TFType; + +// Identify which kind of transfer function is encoded in an skcms_TransferFunction +SKCMS_API skcms_TFType skcms_TransferFunction_getType(const skcms_TransferFunction*); + // We can jam a couple alternate transfer function forms into skcms_TransferFunction, // including those matching the general forms of the SMPTE ST 2084 PQ function or HLG. // @@ -307,6 +318,9 @@ typedef enum skcms_PixelFormat { skcms_PixelFormat_BGR_fff, // Pointers must be 32-bit aligned. skcms_PixelFormat_RGBA_ffff, skcms_PixelFormat_BGRA_ffff, + + skcms_PixelFormat_RGB_101010x_XR, // Note: This is located here to signal no clamping. + skcms_PixelFormat_BGR_101010x_XR, // Compatible with MTLPixelFormatBGR10_XR. } skcms_PixelFormat; // We always store any alpha channel linearly. In the chart below, tf-1() is the inverse diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h index 7b8aa8ac1c50f..350f6a20a6c6b 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h @@ -903,6 +903,16 @@ static void exec_ops(const Op* ops, const void** args, a = cast((rgba >> 30) & 0x3 ) * (1/ 3.0f); } break; + case Op_load_101010x_XR:{ + static constexpr float min = -0.752941f; + static constexpr float max = 1.25098f; + static constexpr float range = max - min; + U32 rgba = load(src + 4*i); + r = cast((rgba >> 0) & 0x3ff) * (1/1023.0f) * range + min; + g = cast((rgba >> 10) & 0x3ff) * (1/1023.0f) * range + min; + b = cast((rgba >> 20) & 0x3ff) * (1/1023.0f) * range + min; + } break; + case Op_load_161616LE:{ uintptr_t ptr = (uintptr_t)(src + 6*i); assert( (ptr & 1) == 0 ); // src must be 2-byte aligned for this @@ -1313,6 +1323,15 @@ static void exec_ops(const Op* ops, const void** args, | cast(to_fixed(a * 255)) << 24); } return; + case Op_store_101010x_XR: { + static constexpr float min = -0.752941f; + static constexpr float max = 1.25098f; + static constexpr float range = max - min; + store(dst + 4*i, cast(to_fixed(((r - min) / range) * 1023)) << 0 + | cast(to_fixed(((g - min) / range) * 1023)) << 10 + | cast(to_fixed(((b - min) / range) * 1023)) << 20); + return; + } case Op_store_1010102: { store(dst + 4*i, cast(to_fixed(r * 1023)) << 0 | cast(to_fixed(g * 1023)) << 10 diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h index a119e4b28d2c7..bc895f99c6e81 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h @@ -7,10 +7,10 @@ #include #include "include/core/SkFontMgr.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTHash.h" #include "modules/skparagraph/include/FontArguments.h" #include "modules/skparagraph/include/ParagraphCache.h" #include "modules/skparagraph/include/TextStyle.h" +#include "src/core/SkTHash.h" namespace skia { namespace textlayout { @@ -69,7 +69,7 @@ class FontCollection : public SkRefCnt { }; bool fEnableFontFallback; - SkTHashMap>, FamilyKey::Hasher> fTypefaces; + skia_private::THashMap>, FamilyKey::Hasher> fTypefaces; sk_sp fDefaultFontManager; sk_sp fAssetFontManager; sk_sp fDynamicFontManager; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h index 5c5503876bec8..c78b0798412a1 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h @@ -12,6 +12,8 @@ class SkCanvas; namespace skia { namespace textlayout { +class ParagraphPainter; + class Paragraph { public: @@ -39,6 +41,8 @@ class Paragraph { virtual void paint(SkCanvas* canvas, SkScalar x, SkScalar y) = 0; + virtual void paint(ParagraphPainter* painter, SkScalar x, SkScalar y) = 0; + // Returns a vector of bounding boxes that enclose all text between // start and end glyph indexes, including start and excluding end virtual std::vector getRectsForRange(unsigned start, @@ -66,9 +70,9 @@ class Paragraph { // -1 if not applicable (has not been shaped yet - valid case) virtual int32_t unresolvedGlyphs() = 0; - // Experimental API that allows fast way to update "immutable" paragraph + // Experimental API that allows fast way to update some of "immutable" paragraph attributes + // but not the text itself virtual void updateTextAlign(TextAlign textAlign) = 0; - virtual void updateText(size_t from, SkString text) = 0; virtual void updateFontSize(size_t from, size_t to, SkScalar fontSize) = 0; virtual void updateForegroundPaint(size_t from, size_t to, SkPaint paint) = 0; virtual void updateBackgroundPaint(size_t from, size_t to, SkPaint paint) = 0; @@ -91,6 +95,72 @@ class Paragraph { using Visitor = std::function; virtual void visit(const Visitor&) = 0; + // Editing API + virtual int getLineNumberAt(TextIndex codeUnitIndex) const = 0; + + /* Returns line metrics info for the line + * + * @param lineNumber a line number + * @param lineMetrics an address to return the info (in case of null just skipped) + * @return true if the line is found; false if not + */ + virtual bool getLineMetricsAt(int lineNumber, LineMetrics* lineMetrics) const = 0; + + /* Returns the visible text on the line (excluding a possible ellipsis) + * + * @param lineNumber a line number + * @param includeSpaces indicates if the whitespaces should be included + * @return the range of the text that is shown in the line + */ + virtual TextRange getActualTextRange(int lineNumber, bool includeSpaces) const = 0; + + struct GlyphClusterInfo { + SkRect fBounds; + TextRange fClusterTextRange; + TextDirection fGlyphClusterPosition; + }; + + /** Finds a glyph cluster for text index + * + * @param codeUnitIndex a text index + * @param glyphInfo a glyph cluster info filled if not null + * @return true if glyph cluster was found; false if not + */ + virtual bool getGlyphClusterAt(TextIndex codeUnitIndex, GlyphClusterInfo* glyphInfo) = 0; + + /** Finds the closest glyph cluster for a visual text position + * + * @param dx x coordinate + * @param dy y coordinate + * @param glyphInfo a glyph cluster info filled if not null + * @return + */ + virtual bool getClosestGlyphClusterAt(SkScalar dx, + SkScalar dy, + GlyphClusterInfo* glyphInfo) = 0; + + struct FontInfo { + FontInfo(const SkFont font, const TextRange textRange) + : fFont(font), fTextRange(textRange) { } + virtual ~FontInfo() = default; + FontInfo(const FontInfo& ) = default; + SkFont fFont; + TextRange fTextRange; + }; + + /** Returns the font that is used to shape the text at the position + * + * @param codeUnitIndex text index + * @return font info or an empty font info if the text is not found + */ + virtual SkFont getFontAt(TextIndex codeUnitIndex) const = 0; + + /** Returns the information about all the fonts used to shape the paragraph text + * + * @return a list of fonts and text ranges + */ + virtual std::vector getFonts() const = 0; + protected: sk_sp fFontCollection; ParagraphStyle fParagraphStyle; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h index 90ffb7019d8e8..45652ae79912c 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h @@ -2,7 +2,7 @@ #ifndef ParagraphCache_DEFINED #define ParagraphCache_DEFINED -#include "include/private/SkMutex.h" +#include "include/private/base/SkMutex.h" #include "src/core/SkLRUCache.h" #include // std::function @@ -11,16 +11,6 @@ namespace skia { namespace textlayout { -enum InternalState { - kUnknown = 0, - kShaped = 2, - kClusterized = 3, - kMarked = 4, - kLineBroken = 5, - kFormatted = 6, - kDrawn = 7 -}; - class ParagraphImpl; class ParagraphCacheKey; class ParagraphCacheValue; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h new file mode 100644 index 0000000000000..56388e64f17bd --- /dev/null +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h @@ -0,0 +1,63 @@ +// Copyright 2019 Google LLC. +#ifndef ParagraphPainter_DEFINED +#define ParagraphPainter_DEFINED + +#include "include/core/SkPaint.h" +#include "include/core/SkTextBlob.h" + +#include +#include + +namespace skia { +namespace textlayout { + +class ParagraphPainter { +public: + typedef int PaintID; + typedef std::variant SkPaintOrID; + + struct DashPathEffect { + DashPathEffect(SkScalar onLength, SkScalar offLength); + + SkScalar fOnLength; + SkScalar fOffLength; + }; + + class DecorationStyle { + public: + DecorationStyle(); + DecorationStyle(SkColor color, SkScalar strokeWidth, + std::optional dashPathEffect); + + SkColor getColor() const { return fColor; } + SkScalar getStrokeWidth() const { return fStrokeWidth; } + std::optional getDashPathEffect() const { return fDashPathEffect; } + const SkPaint& skPaint() const { return fPaint; } + + private: + SkColor fColor; + SkScalar fStrokeWidth; + std::optional fDashPathEffect; + SkPaint fPaint; + }; + + virtual ~ParagraphPainter() = default; + + virtual void drawTextBlob(const sk_sp& blob, SkScalar x, SkScalar y, const SkPaintOrID& paint) = 0; + virtual void drawTextShadow(const sk_sp& blob, SkScalar x, SkScalar y, SkColor color, SkScalar blurSigma) = 0; + virtual void drawRect(const SkRect& rect, const SkPaintOrID& paint) = 0; + virtual void drawFilledRect(const SkRect& rect, const DecorationStyle& decorStyle) = 0; + virtual void drawPath(const SkPath& path, const DecorationStyle& decorStyle) = 0; + virtual void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const DecorationStyle& decorStyle) = 0; + + virtual void clipRect(const SkRect& rect) = 0; + virtual void translate(SkScalar dx, SkScalar dy) = 0; + + virtual void save() = 0; + virtual void restore() = 0; +}; + +} // namespace textlayout +} // namespace skia + +#endif // ParagraphPainter_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h index 82b4a7cb13cb4..e6f0ae46302d9 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h @@ -12,6 +12,7 @@ #include "include/core/SkScalar.h" #include "modules/skparagraph/include/DartTypes.h" #include "modules/skparagraph/include/FontArguments.h" +#include "modules/skparagraph/include/ParagraphPainter.h" #include "modules/skparagraph/include/TextShadow.h" // TODO: Make it external so the other platforms (Android) could use it @@ -165,19 +166,41 @@ class TextStyle { void setColor(SkColor color) { fColor = color; } bool hasForeground() const { return fHasForeground; } - SkPaint getForeground() const { return fForeground; } + SkPaint getForeground() const { + const SkPaint* paint = std::get_if(&fForeground); + return paint ? *paint : SkPaint(); + } + ParagraphPainter::SkPaintOrID getForegroundPaintOrID() const { + return fForeground; + } void setForegroundColor(SkPaint paint) { fHasForeground = true; fForeground = std::move(paint); } + // Set the foreground to a paint ID. This is intended for use by clients + // that implement a custom ParagraphPainter that can not accept an SkPaint. + void setForegroundPaintID(ParagraphPainter::PaintID paintID) { + fHasForeground = true; + fForeground = paintID; + } void clearForegroundColor() { fHasForeground = false; } bool hasBackground() const { return fHasBackground; } - SkPaint getBackground() const { return fBackground; } + SkPaint getBackground() const { + const SkPaint* paint = std::get_if(&fBackground); + return paint ? *paint : SkPaint(); + } + ParagraphPainter::SkPaintOrID getBackgroundPaintOrID() const { + return fBackground; + } void setBackgroundColor(SkPaint paint) { fHasBackground = true; fBackground = std::move(paint); } + void setBackgroundPaintID(ParagraphPainter::PaintID paintID) { + fHasBackground = true; + fBackground = paintID; + } void clearBackgroundColor() { fHasBackground = false; } // Decorations @@ -291,9 +314,9 @@ class TextStyle { SkColor fColor = SK_ColorWHITE; bool fHasBackground = false; - SkPaint fBackground; + ParagraphPainter::SkPaintOrID fBackground; bool fHasForeground = false; - SkPaint fForeground; + ParagraphPainter::SkPaintOrID fForeground; std::vector fTextShadows; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h index df759b125ad24..c51110cd4fea9 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h @@ -2,8 +2,8 @@ #ifndef TypefaceFontProvider_DEFINED #define TypefaceFontProvider_DEFINED -#include "include/private/SkTArray.h" -#include "include/private/SkTHash.h" +#include "include/private/base/SkTArray.h" +#include "src/core/SkTHash.h" #include #include #include @@ -20,15 +20,15 @@ class TypefaceFontStyleSet : public SkFontStyleSet { int count() override; void getStyle(int index, SkFontStyle*, SkString* name) override; - SkTypeface* createTypeface(int index) override; - SkTypeface* matchStyle(const SkFontStyle& pattern) override; + sk_sp createTypeface(int index) override; + sk_sp matchStyle(const SkFontStyle& pattern) override; SkString getFamilyName() const { return fFamilyName; } SkString getAlias() const { return fAlias; } void appendTypeface(sk_sp typeface); private: - SkTArray> fStyles; + skia_private::TArray> fStyles; SkString fFamilyName; SkString fAlias; }; @@ -42,15 +42,15 @@ class TypefaceFontProvider : public SkFontMgr { void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkFontStyleSet* onCreateStyleSet(int) const override { return nullptr; } - SkTypeface* onMatchFamilyStyle(const char[], const SkFontStyle&) const override { + sk_sp onCreateStyleSet(int) const override { return nullptr; } + sk_sp onMatchFamilyStyle(const char[], const SkFontStyle&) const override { return nullptr; } - SkTypeface* onMatchFamilyStyleCharacter(const char[], const SkFontStyle&, - const char*[], int, - SkUnichar) const override { + sk_sp onMatchFamilyStyleCharacter(const char[], const SkFontStyle&, + const char*[], int, + SkUnichar) const override { return nullptr; } @@ -71,8 +71,8 @@ class TypefaceFontProvider : public SkFontMgr { } private: - SkTHashMap> fRegisteredFamilies; - SkTArray fFamilyNames; + skia_private::THashMap> fRegisteredFamilies; + skia_private::TArray fFamilyNames; }; } // namespace textlayout diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h index f59471198b066..a0f44a83be116 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h @@ -15,8 +15,8 @@ #include "include/core/SkString.h" #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTHash.h" +#include "include/private/base/SkMutex.h" +#include "src/core/SkTHash.h" #include @@ -50,6 +50,18 @@ class SK_API ImageAsset : public SkRefCnt { */ virtual sk_sp getFrame(float t); + // Describes how the frame image is to be scaled to the animation-declared asset size. + enum class SizeFit { + // See SkMatrix::ScaleToFit + kFill = SkMatrix::kFill_ScaleToFit, + kStart = SkMatrix::kStart_ScaleToFit, + kCenter = SkMatrix::kCenter_ScaleToFit, + kEnd = SkMatrix::kEnd_ScaleToFit, + + // No scaling. + kNone, + }; + struct FrameData { // SkImage payload. sk_sp image; @@ -57,6 +69,8 @@ class SK_API ImageAsset : public SkRefCnt { SkSamplingOptions sampling; // Additional image transform to be applied before AE scaling rules. SkMatrix matrix = SkMatrix::I(); + // Strategy for image size -> AE asset size scaling. + SizeFit scaling = SizeFit::kCenter; }; /** @@ -227,8 +241,8 @@ class SK_API CachingResourceProvider final : public ResourceProviderProxyBase { sk_sp loadImageAsset(const char[], const char[], const char[]) const override; - mutable SkMutex fMutex; - mutable SkTHashMap> fImageCache; + mutable SkMutex fMutex; + mutable skia_private::THashMap> fImageCache; using INHERITED = ResourceProviderProxyBase; }; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h index d6996638ccdcf..8e4d56caee221 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h @@ -9,7 +9,7 @@ #define SkSVGAttribute_DEFINED #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGRenderContext; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h index e4ac579f7966d..9513232218668 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h @@ -10,9 +10,9 @@ #include -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGAttributeParser : public SkNoncopyable { public: diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h index 560271854f5b6..e5e9516c32e68 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h @@ -8,7 +8,7 @@ #ifndef SkSVGContainer_DEFINED #define SkSVGContainer_DEFINED -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include "modules/svg/include/SkSVGTransformableNode.h" class SkSVGContainer : public SkSVGTransformableNode { @@ -27,7 +27,7 @@ class SkSVGContainer : public SkSVGTransformableNode { bool hasChildren() const final; // TODO: add some sort of child iterator, and hide the container. - SkSTArray<1, sk_sp, true> fChildren; + skia_private::STArray<1, sk_sp, true> fChildren; private: using INHERITED = SkSVGTransformableNode; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h index a035179b70e7b..f0bd467d28aee 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h @@ -11,7 +11,7 @@ #include "include/core/SkFontMgr.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include "modules/skresources/include/SkResources.h" #include "modules/svg/include/SkSVGIDMapper.h" diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h index edd503403c130..dcd938d1e1838 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h @@ -11,8 +11,8 @@ #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" #include "include/core/SkString.h" -#include "include/private/SkTHash.h" #include "modules/svg/include/SkSVGTypes.h" +#include "src/core/SkTHash.h" class SkImageFilter; class SkSVGFeInputType; @@ -61,7 +61,7 @@ class SkSVGFilterContext { SkSVGObjectBoundingBoxUnits fPrimitiveUnits; - SkTHashMap fResults; + skia_private::THashMap fResults; Result fPreviousResult; }; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h index 2c1e45afcf5d8..16053e83c85fd 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h @@ -37,8 +37,8 @@ class SkSVGGradient : public SkSVGHiddenContainer { SkTileMode, const SkMatrix& localMatrix) const = 0; private: - using StopPositionArray = SkSTArray<2, SkScalar , true>; - using StopColorArray = SkSTArray<2, SkColor4f, true>; + using StopPositionArray = skia_private::STArray<2, SkScalar , true>; + using StopColorArray = skia_private::STArray<2, SkColor4f, true>; void collectColorStops(const SkSVGRenderContext&, StopPositionArray*, StopColorArray*) const; SkColor4f resolveStopColor(const SkSVGRenderContext&, const SkSVGStop&) const; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h index ea0d9165fcbae..e78f28de37368 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h @@ -9,11 +9,11 @@ #define SkSVGIDMapper_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkTHash.h" +#include "src/core/SkTHash.h" class SkString; class SkSVGNode; -using SkSVGIDMapper = SkTHashMap>; +using SkSVGIDMapper = skia_private::THashMap>; #endif // SkSVGIDMapper_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h index 27a86395cb4b4..32ee8a08e415f 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h @@ -15,11 +15,11 @@ #include "include/core/SkRect.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" -#include "include/private/SkTHash.h" #include "modules/skresources/include/SkResources.h" #include "modules/svg/include/SkSVGAttribute.h" #include "modules/svg/include/SkSVGIDMapper.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" +#include "src/core/SkTHash.h" class SkCanvas; class SkSVGLength; @@ -52,7 +52,7 @@ struct SkSVGPresentationContext { SkSVGPresentationContext(const SkSVGPresentationContext&) = default; SkSVGPresentationContext& operator=(const SkSVGPresentationContext&) = default; - const SkTHashMap* fNamedColors = nullptr; + const skia_private::THashMap* fNamedColors = nullptr; // Inherited presentation attributes, computed for the current node. SkSVGPresentationAttributes fInherited; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h index 91f33dea9a3c2..41e041de3f76c 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h @@ -10,7 +10,7 @@ #include "modules/svg/include/SkSVGContainer.h" #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGLengthContext; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h index db103bef59179..77c5fbef40562 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h @@ -18,8 +18,9 @@ #include "include/core/SkSpan.h" #include "include/core/SkString.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" -#include "src/core/SkTLazy.h" + +#include +#include using SkSVGColorType = SkColor; using SkSVGIntegerType = int; @@ -27,7 +28,7 @@ using SkSVGNumberType = SkScalar; using SkSVGStringType = SkString; using SkSVGViewBoxType = SkRect; using SkSVGTransformType = SkMatrix; -using SkSVGPointsType = SkTDArray; +using SkSVGPointsType = std::vector; enum class SkSVGPropertyState { kUnspecified, @@ -45,17 +46,17 @@ template class SkSVGProperty { explicit SkSVGProperty(SkSVGPropertyState state) : fState(state) {} explicit SkSVGProperty(const T& value) : fState(SkSVGPropertyState::kValue) { - fValue.set(value); + fValue = value; } explicit SkSVGProperty(T&& value) : fState(SkSVGPropertyState::kValue) { - fValue.set(std::move(value)); + fValue = std::move(value); } template void init(Args&&... args) { fState = SkSVGPropertyState::kValue; - fValue.init(std::forward(args)...); + fValue.emplace(std::forward(args)...); } constexpr bool isInheritable() const { return kInheritable; } @@ -63,7 +64,7 @@ template class SkSVGProperty { bool isValue() const { return fState == SkSVGPropertyState::kValue; } T* getMaybeNull() const { - return fValue.getMaybeNull(); + return fValue.has_value() ? &fValue.value() : nullptr; } void set(SkSVGPropertyState state) { @@ -75,41 +76,41 @@ template class SkSVGProperty { void set(const T& value) { fState = SkSVGPropertyState::kValue; - fValue.set(value); + fValue = value; } void set(T&& value) { fState = SkSVGPropertyState::kValue; - fValue.set(std::move(value)); + fValue = std::move(value); } T* operator->() { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); - return fValue.get(); + SkASSERT(fValue.has_value()); + return &fValue.value(); } const T* operator->() const { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); - return fValue.get(); + SkASSERT(fValue.has_value()); + return &fValue.value(); } T& operator*() { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); + SkASSERT(fValue.has_value()); return *fValue; } const T& operator*() const { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); + SkASSERT(fValue.has_value()); return *fValue; } private: SkSVGPropertyState fState; - SkTLazy fValue; + std::optional fValue; }; class SkSVGLength { @@ -180,7 +181,7 @@ class SkSVGColor { kColor, kICCColor, }; - using Vars = SkSTArray<1, SkString>; + using Vars = std::vector; SkSVGColor() : SkSVGColor(SK_ColorBLACK) {} explicit SkSVGColor(const SkSVGColorType& c) : fType(Type::kColor), fColor(c), fVars(nullptr) {} @@ -400,7 +401,7 @@ class SkSVGDashArray { SkSVGDashArray() : fType(Type::kNone) {} explicit SkSVGDashArray(Type t) : fType(t) {} - explicit SkSVGDashArray(SkTDArray&& dashArray) + explicit SkSVGDashArray(std::vector&& dashArray) : fType(Type::kDashArray) , fDashArray(std::move(dashArray)) {} @@ -414,11 +415,11 @@ class SkSVGDashArray { Type type() const { return fType; } - const SkTDArray& dashArray() const { return fDashArray; } + const std::vector& dashArray() const { return fDashArray; } private: Type fType; - SkTDArray fDashArray; + std::vector fDashArray; }; class SkSVGStopColor { @@ -673,7 +674,7 @@ enum class SkSVGFeColorMatrixType { kLuminanceToAlpha, }; -using SkSVGFeColorMatrixValues = SkTDArray; +using SkSVGFeColorMatrixValues = std::vector; enum class SkSVGFeCompositeOperator { kOver, diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h index eb1977feb356e..d03afa6d9fa98 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h @@ -12,7 +12,7 @@ #include "include/core/SkMatrix.h" #include "include/core/SkPath.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/svg/include/SkSVGTypes.h" class SkSVGValue : public SkNoncopyable { diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h deleted file mode 100644 index 50429d500f25c..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkLRUCache_DEFINED -#define SkLRUCache_DEFINED - -#include "include/private/SkChecksum.h" -#include "include/private/SkTHash.h" -#include "src/core/SkTInternalLList.h" - -/** - * A generic LRU cache. - */ -template -class SkLRUCache : public SkNoncopyable { -private: - struct Entry { - Entry(const K& key, V&& value) - : fKey(key) - , fValue(std::move(value)) {} - - K fKey; - V fValue; - - SK_DECLARE_INTERNAL_LLIST_INTERFACE(Entry); - }; - -public: - explicit SkLRUCache(int maxCount) - : fMaxCount(maxCount) {} - - ~SkLRUCache() { - Entry* node = fLRU.head(); - while (node) { - fLRU.remove(node); - delete node; - node = fLRU.head(); - } - } - - V* find(const K& key) { - Entry** value = fMap.find(key); - if (!value) { - return nullptr; - } - Entry* entry = *value; - if (entry != fLRU.head()) { - fLRU.remove(entry); - fLRU.addToHead(entry); - } // else it's already at head position, don't need to do anything - return &entry->fValue; - } - - V* insert(const K& key, V value) { - SkASSERT(!this->find(key)); - - Entry* entry = new Entry(key, std::move(value)); - fMap.set(entry); - fLRU.addToHead(entry); - while (fMap.count() > fMaxCount) { - this->remove(fLRU.tail()->fKey); - } - return &entry->fValue; - } - - V* insert_or_update(const K& key, V value) { - if (V* found = this->find(key)) { - *found = std::move(value); - return found; - } else { - return this->insert(key, std::move(value)); - } - } - - int count() { - return fMap.count(); - } - - template // f(K*, V*) - void foreach(Fn&& fn) { - typename SkTInternalLList::Iter iter; - for (Entry* e = iter.init(fLRU, SkTInternalLList::Iter::kHead_IterStart); e; - e = iter.next()) { - fn(&e->fKey, &e->fValue); - } - } - - void reset() { - fMap.reset(); - for (Entry* e = fLRU.head(); e; e = fLRU.head()) { - fLRU.remove(e); - delete e; - } - } - -private: - struct Traits { - static const K& GetKey(Entry* e) { - return e->fKey; - } - - static uint32_t Hash(const K& k) { - return HashK()(k); - } - }; - - void remove(const K& key) { - Entry** value = fMap.find(key); - SkASSERT(value); - Entry* entry = *value; - SkASSERT(key == entry->fKey); - fMap.remove(key); - fLRU.remove(entry); - delete entry; - } - - int fMaxCount; - SkTHashTable fMap; - SkTInternalLList fLRU; -}; - -#endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h similarity index 89% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h rename to ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h index 7fe6d33c70c84..e72483b501df1 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h +++ b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h @@ -10,13 +10,15 @@ #include "include/core/SkTypes.h" #include "include/private/SkChecksum.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include #include #include -// Before trying to use SkTHashTable, look below to see if SkTHashMap or SkTHashSet works for you. +namespace skia_private { + +// Before trying to use THashTable, look below to see if THashMap or THashSet works for you. // They're easier to use, usually perform the same, and have fewer sharp edges. // T and K are treated as ordinary copyable C++ types. @@ -26,15 +28,15 @@ // If the key is large and stored inside T, you may want to make K a const&. // Similarly, if T is large you might want it to be a pointer. template -class SkTHashTable { +class THashTable { public: - SkTHashTable() = default; - ~SkTHashTable() = default; + THashTable() = default; + ~THashTable() = default; - SkTHashTable(const SkTHashTable& that) { *this = that; } - SkTHashTable( SkTHashTable&& that) { *this = std::move(that); } + THashTable(const THashTable& that) { *this = that; } + THashTable( THashTable&& that) { *this = std::move(that); } - SkTHashTable& operator=(const SkTHashTable& that) { + THashTable& operator=(const THashTable& that) { if (this != &that) { fCount = that.fCount; fCapacity = that.fCapacity; @@ -46,7 +48,7 @@ class SkTHashTable { return *this; } - SkTHashTable& operator=(SkTHashTable&& that) { + THashTable& operator=(THashTable&& that) { if (this != &that) { fCount = that.fCount; fCapacity = that.fCapacity; @@ -58,7 +60,7 @@ class SkTHashTable { } // Clear the table. - void reset() { *this = SkTHashTable(); } + void reset() { *this = THashTable(); } // How many entries are in the table? int count() const { return fCount; } @@ -75,7 +77,7 @@ class SkTHashTable { // If you change an entry so that it no longer has the same key, all hell // will break loose. Do not do that! // - // Please prefer to use SkTHashMap or SkTHashSet, which do not have this danger. + // Please prefer to use THashMap or THashSet, which do not have this danger. // The pointers returned by set() and find() are valid only until the next call to set(). // The pointers you receive in foreach() are only valid for its duration. @@ -103,7 +105,7 @@ class SkTHashTable { } index = this->next(index); } - SkASSERT(fCapacity == 0); + SkASSERT(fCapacity == fCount); return nullptr; } @@ -145,8 +147,8 @@ class SkTHashTable { fCount = 0; fCapacity = capacity; - SkAutoTArray oldSlots = std::move(fSlots); - fSlots = SkAutoTArray(capacity); + AutoTArray oldSlots = std::move(fSlots); + fSlots = AutoTArray(capacity); for (int i = 0; i < oldCapacity; i++) { Slot& s = oldSlots[i]; @@ -178,12 +180,12 @@ class SkTHashTable { } // A basic iterator-like class which disallows mutation; sufficient for range-based for loops. - // Intended for use by SkTHashMap and SkTHashSet via begin() and end(). + // Intended for use by THashMap and THashSet via begin() and end(). // Adding or removing elements may invalidate all iterators. template class Iter { public: - using TTable = SkTHashTable; + using TTable = THashTable; Iter(const TTable* table, int slot) : fTable(table), fSlot(slot) {} @@ -411,22 +413,22 @@ class SkTHashTable { int fCount = 0, fCapacity = 0; - SkAutoTArray fSlots; + AutoTArray fSlots; }; -// Maps K->V. A more user-friendly wrapper around SkTHashTable, suitable for most use cases. +// Maps K->V. A more user-friendly wrapper around THashTable, suitable for most use cases. // K and V are treated as ordinary copyable C++ types, with no assumed relationship between the two. template -class SkTHashMap { +class THashMap { public: // Allow default construction and assignment. - SkTHashMap() = default; + THashMap() = default; - SkTHashMap(SkTHashMap&& that) = default; - SkTHashMap(const SkTHashMap& that) = default; + THashMap(THashMap&& that) = default; + THashMap(const THashMap& that) = default; - SkTHashMap& operator=(SkTHashMap&& that) = default; - SkTHashMap& operator=(const SkTHashMap& that) = default; + THashMap& operator=(THashMap&& that) = default; + THashMap& operator=(const THashMap& that) = default; // Construct with an initializer list of key-value pairs. struct Pair : public std::pair { @@ -435,7 +437,7 @@ class SkTHashMap { static auto Hash(const K& key) { return HashK()(key); } }; - SkTHashMap(std::initializer_list pairs) { + THashMap(std::initializer_list pairs) { fTable.resize(pairs.size() * 5 / 3); for (const Pair& p : pairs) { fTable.set(p); @@ -498,7 +500,7 @@ class SkTHashMap { } // Dereferencing an iterator gives back a key-value pair, suitable for structured binding. - using Iter = typename SkTHashTable::template Iter>; + using Iter = typename THashTable::template Iter>; Iter begin() const { return Iter::MakeBegin(&fTable); @@ -509,24 +511,24 @@ class SkTHashMap { } private: - SkTHashTable fTable; + THashTable fTable; }; // A set of T. T is treated as an ordinary copyable C++ type. template -class SkTHashSet { +class THashSet { public: // Allow default construction and assignment. - SkTHashSet() = default; + THashSet() = default; - SkTHashSet(SkTHashSet&& that) = default; - SkTHashSet(const SkTHashSet& that) = default; + THashSet(THashSet&& that) = default; + THashSet(const THashSet& that) = default; - SkTHashSet& operator=(SkTHashSet&& that) = default; - SkTHashSet& operator=(const SkTHashSet& that) = default; + THashSet& operator=(THashSet&& that) = default; + THashSet& operator=(const THashSet& that) = default; // Construct with an initializer list of Ts. - SkTHashSet(std::initializer_list vals) { + THashSet(std::initializer_list vals) { fTable.resize(vals.size() * 5 / 3); for (const T& val : vals) { fTable.set(val); @@ -574,7 +576,7 @@ class SkTHashSet { }; public: - using Iter = typename SkTHashTable::template Iter; + using Iter = typename THashTable::template Iter; Iter begin() const { return Iter::MakeBegin(&fTable); @@ -585,7 +587,9 @@ class SkTHashSet { } private: - SkTHashTable fTable; + THashTable fTable; }; -#endif//SkTHash_DEFINED +} // namespace skia_private + +#endif // SkTHash_DEFINED diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h b/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h deleted file mode 100644 index a5cb615556e56..0000000000000 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkTInternalLList_DEFINED -#define SkTInternalLList_DEFINED - -#include "include/core/SkTypes.h" - -/** - * This macro creates the member variables required by the SkTInternalLList class. It should be - * placed in the private section of any class that will be stored in a double linked list. - */ -#define SK_DECLARE_INTERNAL_LLIST_INTERFACE(ClassName) \ - friend class SkTInternalLList; \ - /* back pointer to the owning list - for debugging */ \ - SkDEBUGCODE(SkTInternalLList* fList = nullptr;) \ - ClassName* fPrev = nullptr; \ - ClassName* fNext = nullptr - -/** - * This class implements a templated internal doubly linked list data structure. - */ -template class SkTInternalLList { -public: - SkTInternalLList() {} - - void reset() { - fHead = nullptr; - fTail = nullptr; - } - - void remove(T* entry) { - SkASSERT(fHead && fTail); - SkASSERT(this->isInList(entry)); - - T* prev = entry->fPrev; - T* next = entry->fNext; - - if (prev) { - prev->fNext = next; - } else { - fHead = next; - } - if (next) { - next->fPrev = prev; - } else { - fTail = prev; - } - - entry->fPrev = nullptr; - entry->fNext = nullptr; - -#ifdef SK_DEBUG - entry->fList = nullptr; -#endif - } - - void addToHead(T* entry) { - SkASSERT(nullptr == entry->fPrev && nullptr == entry->fNext); - SkASSERT(nullptr == entry->fList); - - entry->fPrev = nullptr; - entry->fNext = fHead; - if (fHead) { - fHead->fPrev = entry; - } - fHead = entry; - if (nullptr == fTail) { - fTail = entry; - } - -#ifdef SK_DEBUG - entry->fList = this; -#endif - } - - void addToTail(T* entry) { - SkASSERT(nullptr == entry->fPrev && nullptr == entry->fNext); - SkASSERT(nullptr == entry->fList); - - entry->fPrev = fTail; - entry->fNext = nullptr; - if (fTail) { - fTail->fNext = entry; - } - fTail = entry; - if (nullptr == fHead) { - fHead = entry; - } - -#ifdef SK_DEBUG - entry->fList = this; -#endif - } - - /** - * Inserts a new list entry before an existing list entry. The new entry must not already be - * a member of this or any other list. If existingEntry is NULL then the new entry is added - * at the tail. - */ - void addBefore(T* newEntry, T* existingEntry) { - SkASSERT(newEntry); - - if (nullptr == existingEntry) { - this->addToTail(newEntry); - return; - } - - SkASSERT(this->isInList(existingEntry)); - newEntry->fNext = existingEntry; - T* prev = existingEntry->fPrev; - existingEntry->fPrev = newEntry; - newEntry->fPrev = prev; - if (nullptr == prev) { - SkASSERT(fHead == existingEntry); - fHead = newEntry; - } else { - prev->fNext = newEntry; - } -#ifdef SK_DEBUG - newEntry->fList = this; -#endif - } - - /** - * Inserts a new list entry after an existing list entry. The new entry must not already be - * a member of this or any other list. If existingEntry is NULL then the new entry is added - * at the head. - */ - void addAfter(T* newEntry, T* existingEntry) { - SkASSERT(newEntry); - - if (nullptr == existingEntry) { - this->addToHead(newEntry); - return; - } - - SkASSERT(this->isInList(existingEntry)); - newEntry->fPrev = existingEntry; - T* next = existingEntry->fNext; - existingEntry->fNext = newEntry; - newEntry->fNext = next; - if (nullptr == next) { - SkASSERT(fTail == existingEntry); - fTail = newEntry; - } else { - next->fPrev = newEntry; - } -#ifdef SK_DEBUG - newEntry->fList = this; -#endif - } - - void concat(SkTInternalLList&& list) { - if (list.isEmpty()) { - return; - } - - list.fHead->fPrev = fTail; - if (!fHead) { - SkASSERT(!list.fHead->fPrev); - fHead = list.fHead; - } else { - SkASSERT(fTail); - fTail->fNext = list.fHead; - } - fTail = list.fTail; - -#ifdef SK_DEBUG - for (T* node = list.fHead; node; node = node->fNext) { - SkASSERT(node->fList == &list); - node->fList = this; - } -#endif - - list.fHead = list.fTail = nullptr; - } - - bool isEmpty() const { - SkASSERT(SkToBool(fHead) == SkToBool(fTail)); - return !fHead; - } - - T* head() const { return fHead; } - T* tail() const { return fTail; } - - class Iter { - public: - enum IterStart { - kHead_IterStart, - kTail_IterStart - }; - - Iter() : fCurr(nullptr) {} - Iter(const Iter& iter) : fCurr(iter.fCurr) {} - Iter& operator= (const Iter& iter) { fCurr = iter.fCurr; return *this; } - - T* init(const SkTInternalLList& list, IterStart startLoc) { - if (kHead_IterStart == startLoc) { - fCurr = list.fHead; - } else { - SkASSERT(kTail_IterStart == startLoc); - fCurr = list.fTail; - } - - return fCurr; - } - - T* get() { return fCurr; } - - /** - * Return the next/previous element in the list or NULL if at the end. - */ - T* next() { - if (nullptr == fCurr) { - return nullptr; - } - - fCurr = fCurr->fNext; - return fCurr; - } - - T* prev() { - if (nullptr == fCurr) { - return nullptr; - } - - fCurr = fCurr->fPrev; - return fCurr; - } - - /** - * C++11 range-for interface. - */ - bool operator!=(const Iter& that) { return fCurr != that.fCurr; } - T* operator*() { return this->get(); } - void operator++() { this->next(); } - - private: - T* fCurr; - }; - - Iter begin() const { - Iter iter; - iter.init(*this, Iter::kHead_IterStart); - return iter; - } - - Iter end() const { return Iter(); } - -#ifdef SK_DEBUG - void validate() const { - SkASSERT(!fHead == !fTail); - Iter iter; - for (T* item = iter.init(*this, Iter::kHead_IterStart); item; item = iter.next()) { - SkASSERT(this->isInList(item)); - if (nullptr == item->fPrev) { - SkASSERT(fHead == item); - } else { - SkASSERT(item->fPrev->fNext == item); - } - if (nullptr == item->fNext) { - SkASSERT(fTail == item); - } else { - SkASSERT(item->fNext->fPrev == item); - } - } - } - - /** - * Debugging-only method that uses the list back pointer to check if 'entry' is indeed in 'this' - * list. - */ - bool isInList(const T* entry) const { - return entry->fList == this; - } - - /** - * Debugging-only method that laboriously counts the list entries. - */ - int countEntries() const { - int count = 0; - for (T* entry = fHead; entry; entry = entry->fNext) { - ++count; - } - return count; - } -#endif // SK_DEBUG - -private: - T* fHead = nullptr; - T* fTail = nullptr; - - SkTInternalLList(const SkTInternalLList&) = delete; - SkTInternalLList& operator=(const SkTInternalLList&) = delete; -}; - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/ABI48_0_0react-native-skia.podspec.json b/ios/vendored/sdk48/@shopify/react-native-skia/ABI48_0_0react-native-skia.podspec.json index 7e89c33c22c1d..19fbbcbe27a73 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/ABI48_0_0react-native-skia.podspec.json +++ b/ios/vendored/sdk48/@shopify/react-native-skia/ABI48_0_0react-native-skia.podspec.json @@ -17,10 +17,10 @@ }, "requires_arc": true, "pod_target_xcconfig": { - "GCC_PREPROCESSOR_DEFINITIONS": "$(inherited) SK_GL=1 SK_METAL=1", + "GCC_PREPROCESSOR_DEFINITIONS": "$(inherited) SK_METAL=1 SK_GANESH=1", "CLANG_CXX_LANGUAGE_STANDARD": "c++17", "DEFINES_MODULE": "YES", - "HEADER_SEARCH_PATHS": "\"$(PODS_ROOT)/Headers/Private/ABI48_0_0React-bridging/react/bridging\" \"$(PODS_CONFIGURATION_BUILD_DIR)/ABI48_0_0React-bridging/react_bridging.framework/Headers\"" + "HEADER_SEARCH_PATHS": "\"$(PODS_TARGET_SRCROOT)/cpp/\"/** \"$(PODS_ROOT)/Headers/Private/ABI48_0_0React-bridging/react/bridging\" \"$(PODS_CONFIGURATION_BUILD_DIR)/ABI48_0_0React-bridging/react_bridging.framework/Headers\"" }, "frameworks": [ "GLKit", diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImage.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImage.h index 665e34cfe5af0..0694f70d3f9b6 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImage.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImage.h @@ -14,7 +14,9 @@ #include "SkBase64.h" #include "SkImage.h" #include "SkStream.h" -#include +#include "codec/SkEncodedImageFormat.h" +#include "include/encode/SkJpegEncoder.h" +#include "include/encode/SkPngEncoder.h" #pragma clang diagnostic pop @@ -70,7 +72,15 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject { auto quality = count == 2 ? arguments[1].asNumber() : 100.0; // Get data - auto data = getObject()->encodeToData(format, quality); + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, getObject().get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, getObject().get(), options); + } auto arrayCtor = runtime.global().getPropertyAsFunction(runtime, "Uint8Array"); size_t size = data->size(); @@ -95,8 +105,19 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject { : SkEncodedImageFormat::kPNG; auto quality = count == 2 ? arguments[1].asNumber() : 100.0; - - auto data = getObject()->encodeToData(format, quality); + auto image = getObject(); + if (image->isTextureBacked()) { + image = image->makeNonTextureImage(); + } + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, image.get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, image.get(), options); + } auto len = SkBase64::Encode(data->bytes(), data->size(), nullptr); auto buffer = std::string(len, 0); SkBase64::Encode(data->bytes(), data->size(), diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h index 3797d78162d9b..652ef0d82f64d 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h @@ -18,7 +18,7 @@ class JsiSkImageFactory : public JsiSkHostObject { public: JSI_HOST_FUNCTION(MakeImageFromEncoded) { auto data = JsiSkData::fromValue(runtime, arguments[0]); - auto image = SkImage::MakeFromEncoded(data); + auto image = SkImages::DeferredFromEncodedData(data); if (image == nullptr) { return jsi::Value::null(); } @@ -30,7 +30,7 @@ class JsiSkImageFactory : public JsiSkHostObject { auto imageInfo = JsiSkImageInfo::fromValue(runtime, arguments[0]); auto pixelData = JsiSkData::fromValue(runtime, arguments[1]); auto bytesPerRow = arguments[2].asNumber(); - auto image = SkImage::MakeRasterData(*imageInfo, pixelData, bytesPerRow); + auto image = SkImages::RasterFromData(*imageInfo, pixelData, bytesPerRow); if (image == nullptr) { return jsi::Value::null(); } diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkPath.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkPath.h index 77d9b9bb31929..73f1305d824cd 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkPath.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/api/JsiSkPath.h @@ -7,6 +7,7 @@ #include #include "JsiSkHostObjects.h" +#include "JsiSkMatrix.h" #include "JsiSkPoint.h" #include "JsiSkRRect.h" #include "JsiSkRect.h" @@ -20,6 +21,7 @@ #include "SkPathEffect.h" #include "SkPathOps.h" #include "SkPathTypes.h" +#include "SkPathUtils.h" #include "SkString.h" #include "SkStrokeRec.h" #include "SkTextUtils.h" @@ -289,8 +291,11 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { auto jsiPrecision = opts.getProperty(runtime, "precision"); auto precision = jsiPrecision.isUndefined() ? 1 : jsiPrecision.asNumber(); - auto result = p.getFillPath(path, &path, nullptr, precision); - getObject()->swap(path); + auto result = + skpathutils::FillPathWithPaint(path, p, &path, nullptr, precision); + if (result) { + getObject()->swap(path); + } return result ? thisValue.getObject(runtime) : jsi::Value::null(); } @@ -325,8 +330,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { JSI_HOST_FUNCTION(toSVGString) { SkPath path = *getObject(); - SkString s; - SkParsePath::ToSVGString(path, &s); + auto s = SkParsePath::ToSVGString(path); return jsi::String::createFromUtf8(runtime, s.c_str()); } diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h index f5be928ae11c1..b10d7b90f98ec 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h @@ -10,6 +10,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" +#include #include #pragma clang diagnostic pop diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h index bf7562951b91b..235fb7582e68f 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h @@ -110,8 +110,8 @@ class JsiPathNode : public JsiDomDrawingNode, // _path is const so we can't mutate it directly, let's replace the // path like this: auto p = std::make_shared(*_path.get()); - if (!strokePaint.getFillPath(*_path.get(), p.get(), nullptr, - precision)) { + if (!skpathutils::FillPathWithPaint(*_path.get(), strokePaint, + p.get(), nullptr, precision)) { _path = nullptr; } else { _path = std::const_pointer_cast(p); diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h index 01893eb973d52..21fe7e49e450b 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h @@ -5,6 +5,8 @@ #include #include +#include + namespace ABI48_0_0RNSkia { class BoxShadowProps : public DerivedProp { diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h index 5c8059cd91ee7..3407cfd02c00d 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h @@ -27,7 +27,7 @@ class SkShader; class SkAndroidFrameworkUtils { public: -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** * clipWithStencil draws the current clip into a stencil buffer with reference value and mask * set to 0x1. This function works only on a GPU canvas. @@ -37,7 +37,7 @@ class SkAndroidFrameworkUtils { * @return true on success or false if clip is empty or not a GPU canvas. */ static bool clipWithStencil(SkCanvas* canvas); -#endif //SK_SUPPORT_GPU +#endif //defined(SK_GANESH) static void SafetyNetLog(const char*); @@ -58,12 +58,6 @@ class SkAndroidFrameworkUtils { */ static SkCanvas* getBaseWrappedCanvas(SkCanvas* canvas); - /** - * Skia will change the order in which local matrices concatenate. In order to not break Android - * apps targeting older API levels we offer this function to use the legacy concatenation order. - */ - static void UseLegacyLocalMatrixConcatenation(); - /** * If the shader represents a linear gradient ShaderAsALinearGradient * returns true and if info is not null, ShaderAsALinearGradient populates diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h new file mode 100644 index 0000000000000..14ed009f8c400 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h @@ -0,0 +1,101 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkImageAndroid_DEFINED +#define SkImageAndroid_DEFINED + +#include "include/core/SkImage.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GrTypes.h" + +class SkColorSpace; +class GrDirectContext; +class SkPixmap; +struct AHardwareBuffer; + +namespace SkImages { + +/** (See Skia bug 7447) + Creates SkImage from Android hardware buffer. + Returned SkImage takes a reference on the buffer. + Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + @param hardwareBuffer AHardwareBuffer Android hardware buffer + @param colorSpace range of colors; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer, + SkAlphaType alphaType = kPremul_SkAlphaType); +SK_API sk_sp DeferredFromAHardwareBuffer( + AHardwareBuffer* hardwareBuffer, + SkAlphaType alphaType, + sk_sp colorSpace, + GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); + +/** Creates SkImage from Android hardware buffer and uploads the data from the SkPixmap to it. + Returned SkImage takes a reference on the buffer. + Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + @param context GPU context + @param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer + @param hardwareBuffer AHardwareBuffer Android hardware buffer + @param surfaceOrigin surface origin for resulting image + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromAHardwareBufferWithData( + GrDirectContext* context, + const SkPixmap& pixmap, + AHardwareBuffer* hardwareBuffer, + GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); + +/** + * Like SkImagePriv::SkMakeImageFromRasterBitmap, except this can be pinned using + * skgpu::ganesh::PinAsTexture and CopyPixelMode is never. + */ +SK_API sk_sp PinnableRasterFromBitmap(const SkBitmap&); + +} // namespace SkImages + +// TODO(kjlubick) remove this after Android has been ported. +namespace sk_image_factory { +inline sk_sp MakePinnableFromRasterBitmap(const SkBitmap& b) { + return SkImages::PinnableRasterFromBitmap(b); +} +} // namespace sk_image_factory + +namespace skgpu::ganesh { +/** + * Will attempt to upload and lock the contents of the image as a texture, so that subsequent + * draws to a gpu-target will come from that texture (and not by looking at the original image + * src). In particular this is intended to use the texture even if the image's original content + * changes subsequent to this call (i.e. the src is mutable!). + * + * Only compatible with SkImages created from SkImages::PinnableRasterFromBitmap. + * + * All successful calls must be balanced by an equal number of calls to UnpinTexture(). + * + * Once in this "pinned" state, the image has all of the same thread restrictions that exist + * for a natively created gpu image (e.g. SkImage::MakeFromTexture) + * - all drawing, pinning, unpinning must happen in the same thread as the GrContext. + * + * @return true if the image was successfully uploaded and locked into a texture + */ +bool PinAsTexture(GrRecordingContext*, SkImage*); + +/** + * The balancing call to a successful invocation of PinAsTexture. When a balanced + * number of calls have been made, then the "pinned" texture is free to be purged, etc. This + * also means that a subsequent "pin" call will look at the original content again, and if + * its uniqueID/generationID has changed, then a newer texture will be uploaded/pinned. + * + * Only compatible with SkImages created from SkImages::PinnableRasterFromBitmap. + * + * The context passed to unpin must match the one passed to pin. + */ +void UnpinTexture(GrRecordingContext*, SkImage*); + +} // namespace skgpu::ganesh + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h index 02625838308bd..2b8a79751cfd9 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h @@ -9,24 +9,27 @@ #define SkAndroidCodec_DEFINED #include "include/codec/SkCodec.h" -#include "include/core/SkAlphaType.h" #include "include/core/SkColorSpace.h" -#include "include/core/SkColorType.h" -#include "include/core/SkEncodedImageFormat.h" #include "include/core/SkImageInfo.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" #include "include/private/SkEncodedInfo.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/skcms/skcms.h" +// TODO(kjlubick, bungeman) Replace these includes with forward declares +#include "include/codec/SkEncodedImageFormat.h" // IWYU pragma: keep +#include "include/core/SkAlphaType.h" // IWYU pragma: keep +#include "include/core/SkColorType.h" // IWYU pragma: keep + #include #include class SkData; class SkPngChunkReader; class SkStream; +struct SkGainmapInfo; struct SkIRect; /** @@ -118,10 +121,8 @@ class SK_API SkAndroidCodec : SkNoncopyable { /** * @param outputColorType Color type that the client will decode to. * @param prefColorSpace Preferred color space to decode to. - * This may not return |prefColorSpace| for a couple reasons. - * (1) Android Principles: 565 must be sRGB, F16 must be - * linear sRGB, transfer function must be parametric. - * (2) Codec Limitations: F16 requires a linear color space. + * This may not return |prefColorSpace| for + * specific color types. * * Returns the appropriate color space to decode to. */ @@ -262,6 +263,23 @@ class SK_API SkAndroidCodec : SkNoncopyable { SkCodec* codec() const { return fCodec.get(); } + /** + * Retrieve the gainmap for an image. + * + * @param outInfo On success, this is populated with the parameters for + * rendering this gainmap. This parameter must be non-nullptr. + * + * @param outGainmapImageStream On success, this is populated with a stream from which the + * gainmap image may be decoded. This parameter is optional, and + * may be set to nullptr. + * + * @return If this has a gainmap image and that gainmap image was + * successfully extracted then return true. Otherwise return + * false. + */ + bool getAndroidGainmap(SkGainmapInfo* outInfo, + std::unique_ptr* outGainmapImageStream); + protected: SkAndroidCodec(SkCodec*); diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h index 5af847afcfe30..3ed1a95a800c9 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h @@ -8,10 +8,7 @@ #ifndef SkCodec_DEFINED #define SkCodec_DEFINED -#include "include/codec/SkCodecAnimation.h" #include "include/codec/SkEncodedOrigin.h" -#include "include/core/SkAlphaType.h" -#include "include/core/SkEncodedImageFormat.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" #include "include/core/SkRect.h" @@ -20,21 +17,30 @@ #include "include/core/SkTypes.h" #include "include/core/SkYUVAPixmaps.h" #include "include/private/SkEncodedInfo.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/skcms/skcms.h" #include +#include #include #include #include -class SkAndroidCodec; class SkData; class SkFrameHolder; class SkImage; class SkPngChunkReader; class SkSampler; class SkStream; +struct SkGainmapInfo; +enum SkAlphaType : int; +enum class SkEncodedImageFormat; + +namespace SkCodecAnimation { +enum class Blend; +enum class DisposalMethod; +} + namespace DM { class CodecSrc; @@ -767,6 +773,8 @@ class SK_API SkCodec : SkNoncopyable { return fSrcXformFormat; } + virtual bool onGetGainmapInfo(SkGainmapInfo*, std::unique_ptr*) { return false; } + virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const { // By default, scaling is not supported. return this->dimensions(); @@ -887,8 +895,8 @@ class SK_API SkCodec : SkNoncopyable { const SkEncodedInfo fEncodedInfo; XformFormat fSrcXformFormat; std::unique_ptr fStream; - bool fNeedsRewind; - const SkEncodedOrigin fOrigin; + bool fNeedsRewind = false; + const SkEncodedOrigin fOrigin; SkImageInfo fDstInfo; Options fOptions; @@ -904,13 +912,13 @@ class SK_API SkCodec : SkNoncopyable { skcms_AlphaFormat fDstXformAlphaFormat; // Only meaningful during scanline decodes. - int fCurrScanline; + int fCurrScanline = -1; - bool fStartedIncrementalDecode; + bool fStartedIncrementalDecode = false; // Allows SkAndroidCodec to call handleFrameIndex (potentially decoding a prior frame and - // clearing to transparent) without SkCodec calling it, too. - bool fAndroidCodecHandlesFrameIndex; + // clearing to transparent) without SkCodec itself calling it, too. + bool fUsingCallbackForHandleFrameIndex = false; bool initializeColorXform(const SkImageInfo& dstInfo, SkEncodedInfo::Alpha, bool srcIsOpaque); @@ -934,17 +942,23 @@ class SK_API SkCodec : SkNoncopyable { return nullptr; } + // Callback for decoding a prior frame. The `Options::fFrameIndex` is ignored, + // being replaced by frameIndex. This allows opts to actually be a subclass of + // SkCodec::Options which SkCodec itself does not know how to copy or modify, + // but just passes through to the caller (where it can be reinterpret_cast'd). + using GetPixelsCallback = std::function; + /** * Check for a valid Options.fFrameIndex, and decode prior frames if necessary. * - * If androidCodec is not null, that means this SkCodec is owned by an SkAndroidCodec. In that - * case, the Options will be treated as an AndroidOptions, and SkAndroidCodec will be used to - * decode a prior frame, if a prior frame is needed. When such an owned SkCodec calls - * handleFrameIndex, it will immediately return kSuccess, since SkAndroidCodec already handled - * it. + * If GetPixelsCallback is not null, it will be used to decode a prior frame instead + * of using this SkCodec directly. It may also be used recursively, if that in turn + * depends on a prior frame. This is used by SkAndroidCodec. */ Result handleFrameIndex(const SkImageInfo&, void* pixels, size_t rowBytes, const Options&, - SkAndroidCodec* androidCodec = nullptr); + GetPixelsCallback = nullptr); // Methods for scanline decoding. virtual Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/, diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h new file mode 100644 index 0000000000000..99ca44e765c53 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h @@ -0,0 +1,36 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkEncodedImageFormat_DEFINED +#define SkEncodedImageFormat_DEFINED + +#include + +/** + * Enum describing format of encoded data. + */ +enum class SkEncodedImageFormat { +#ifdef SK_BUILD_FOR_GOOGLE3 + kUnknown, +#endif + kBMP, + kGIF, + kICO, + kJPEG, + kPNG, + kWBMP, + kWEBP, + kPKM, + kKTX, + kASTC, + kDNG, + kHEIF, + kAVIF, + kJPEGXL, +}; + +#endif // SkEncodedImageFormat_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h new file mode 100644 index 0000000000000..0df4a36f0c247 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h @@ -0,0 +1,31 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkPixmapUtils_DEFINED +#define SkPixmapUtils_DEFINED + +#include "include/codec/SkEncodedOrigin.h" +#include "include/core/SkImageInfo.h" +#include "include/private/base/SkAPI.h" + +class SkPixmap; + +namespace SkPixmapUtils { +/** + * Copy the pixels in src into dst, applying the orientation transformations specified + * by origin. If the inputs are invalid, this returns false and no copy is made. + */ +SK_API bool Orient(const SkPixmap& dst, const SkPixmap& src, SkEncodedOrigin origin); + +/** + * Return a copy of the provided ImageInfo with the width and height swapped. + */ +SK_API SkImageInfo SwapWidthHeight(const SkImageInfo& info); + +} // namespace SkPixmapUtils + +#endif // SkPixmapUtils_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPngChunkReader.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkPngChunkReader.h similarity index 100% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPngChunkReader.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/codec/SkPngChunkReader.h diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h index 313d324e405b8..74c21f9438b9e 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h @@ -1,4 +1,3 @@ - /* * Copyright 2006 The Android Open Source Project * @@ -6,7 +5,6 @@ * found in the LICENSE file. */ - #ifndef SkUserConfig_DEFINED #define SkUserConfig_DEFINED @@ -16,9 +14,9 @@ Below are optional defines that add, subtract, or change default behavior in Skia. Your port can locally edit this file to enable/disable flags as - you choose, or these can be delared on your command line (i.e. -Dfoo). + you choose, or these can be declared on your command line (i.e. -Dfoo). - By default, this include file will always default to having all of the flags + By default, this #include file will always default to having all the flags commented out, so including it will have no effect. */ @@ -32,58 +30,92 @@ By default, these mutually exclusive flags are defined in SkTypes.h, based on the presence or absence of NDEBUG, but that decision can be changed here. - */ +*/ //#define SK_DEBUG //#define SK_RELEASE /* To write debug messages to a console, skia will call SkDebugf(...) following printf conventions (e.g. const char* format, ...). If you want to redirect this to something other than printf, define yours here - */ +*/ //#define SkDebugf(...) MyFunction(__VA_ARGS__) -/* - * To specify a different default font cache limit, define this. If this is - * undefined, skia will use a built-in value. - */ +/* Skia has both debug and release asserts. When an assert fails SK_ABORT will + be used to report an abort message. SK_ABORT is expected not to return. Skia + provides a default implementation which will print the message with SkDebugf + and then call sk_abort_no_print. +*/ +//#define SK_ABORT(message, ...) + +/* To specify a different default font strike cache memory limit, define this. If this is + undefined, skia will use a built-in value. +*/ //#define SK_DEFAULT_FONT_CACHE_LIMIT (1024 * 1024) -/* - * To specify the default size of the image cache, undefine this and set it to - * the desired value (in bytes). SkGraphics.h as a runtime API to set this - * value as well. If this is undefined, a built-in value will be used. - */ +/* To specify a different default font strike cache count limit, define this. If this is + undefined, skia will use a built-in value. +*/ +// #define SK_DEFAULT_FONT_CACHE_COUNT_LIMIT 2048 + +/* To specify the default size of the image cache, undefine this and set it to + the desired value (in bytes). SkGraphics.h as a runtime API to set this + value as well. If this is undefined, a built-in value will be used. +*/ //#define SK_DEFAULT_IMAGE_CACHE_LIMIT (1024 * 1024) /* Define this to set the upper limit for text to support LCD. Values that are very large increase the cost in the font cache and draw slower, without improving readability. If this is undefined, Skia will use its default value (e.g. 48) - */ +*/ //#define SK_MAX_SIZE_FOR_LCDTEXT 48 /* Change the kN32_SkColorType ordering to BGRA to work in X windows. - */ +*/ //#define SK_R32_SHIFT 16 - -/* Determines whether to build code that supports the GPU backend. Some classes +/* Determines whether to build code that supports the Ganesh GPU backend. Some classes that are not GPU-specific, such as SkShader subclasses, have optional code - that is used allows them to interact with the GPU backend. If you'd like to - omit this code set SK_SUPPORT_GPU to 0. This also allows you to omit the gpu - directories from your include search path when you're not building the GPU - backend. Defaults to 1 (build the GPU code). - */ -//#define SK_SUPPORT_GPU 1 + that is used allows them to interact with this GPU backend. If you'd like to + include this code, include -DSK_GANESH in your cflags or uncomment below. + Defaults to not set (No Ganesh GPU backend). + This define affects the ABI of Skia, so make sure it matches the client which uses + the compiled version of Skia. +*/ +//#define SK_GANESH /* Skia makes use of histogram logging macros to trace the frequency of - * events. By default, Skia provides no-op versions of these macros. - * Skia consumers can provide their own definitions of these macros to - * integrate with their histogram collection backend. - */ + events. By default, Skia provides no-op versions of these macros. + Skia consumers can provide their own definitions of these macros to + integrate with their histogram collection backend. +*/ //#define SK_HISTOGRAM_BOOLEAN(name, sample) //#define SK_HISTOGRAM_ENUMERATION(name, sample, enum_size) //#define SK_HISTOGRAM_EXACT_LINEAR(name, sample, value_max) //#define SK_HISTOGRAM_MEMORY_KB(name, sample) +/* Skia tries to make use of some non-standard C++ language extensions. + By default, Skia provides msvc and clang/gcc versions of these macros. + Skia consumers can provide their own definitions of these macros to + integrate with their own compilers and build system. +*/ +//#define SK_UNUSED [[maybe_unused]] +//#define SK_WARN_UNUSED_RESULT [[nodiscard]] +//#define SK_ALWAYS_INLINE inline __attribute__((always_inline)) +//#define SK_NEVER_INLINE __attribute__((noinline)) +//#define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) +//#define SK_NO_SANITIZE(A) __attribute__((no_sanitize(A))) +//#define SK_TRIVIAL_ABI [[clang::trivial_abi]] + +/* + * If compiling Skia as a DLL, public APIs should be exported. Skia will set + * SK_API to something sensible for Clang and MSVC, but if clients need to + * customize it for their build system or compiler, they may. + * If a client needs to use SK_API (e.g. overriding SK_ABORT), then they + * *must* define their own, the default will not be defined prior to loading + * this file. + */ +//#define SK_API __declspec(dllexport) + + #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h index 658f20716e7e5..d4ed7a6000b7a 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h @@ -8,24 +8,32 @@ #ifndef SkBitmap_DEFINED #define SkBitmap_DEFINED +#include "include/core/SkAlphaType.h" #include "include/core/SkColor.h" #include "include/core/SkImageInfo.h" -#include "include/core/SkMatrix.h" #include "include/core/SkPixmap.h" #include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/core/SkShader.h" -#include "include/core/SkTileMode.h" +#include "include/core/SkSamplingOptions.h" +#include "include/core/SkSize.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkDebug.h" + +#include +#include -class SkBitmap; class SkColorSpace; -struct SkMask; +class SkImage; +class SkMatrix; class SkMipmap; -struct SkIRect; -struct SkRect; class SkPaint; class SkPixelRef; class SkShader; +enum SkColorType : int; +enum class SkTileMode; +struct SkMask; /** \class SkBitmap SkBitmap describes a two-dimensional raster pixel array. SkBitmap is built on @@ -766,11 +774,10 @@ class SK_API SkBitmap { treated as opaque. If colorType() is kAlpha_8_SkColorType, then RGB is ignored. @param c unpremultiplied color - @param colorSpace SkColorSpace of c example: https://fiddle.skia.org/c/@Bitmap_eraseColor */ - void eraseColor(SkColor4f c, SkColorSpace* colorSpace = nullptr) const; + void eraseColor(SkColor4f) const; /** Replaces pixel values with c, interpreted as being in the sRGB SkColorSpace. All pixels contained by bounds() are affected. If the colorType() is @@ -810,11 +817,9 @@ class SK_API SkBitmap { @param c unpremultiplied color @param area rectangle to fill - @param colorSpace SkColorSpace of c example: https://fiddle.skia.org/c/@Bitmap_erase */ - void erase(SkColor4f c, SkColorSpace* colorSpace, const SkIRect& area) const; void erase(SkColor4f c, const SkIRect& area) const; /** Replaces pixel values inside area with c. interpreted as being in the sRGB @@ -1168,23 +1173,18 @@ class SK_API SkBitmap { example: https://fiddle.skia.org/c/@Bitmap_peekPixels */ bool peekPixels(SkPixmap* pixmap) const; - sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, - const SkMatrix* = nullptr) const; + /** + * Make a shader with the specified tiling, matrix and sampling. + */ + sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, + const SkMatrix* localMatrix = nullptr) const; sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& localMatrix) const { - return this->makeShader(tmx, tmy, sampling, &localMatrix); - } - - sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix* localMatrix = nullptr) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, localMatrix); - } - + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix& localMatrix) const { - return this->makeShader(sampling, &localMatrix); - } + const SkMatrix* lm = nullptr) const; /** * Returns a new image from the bitmap. If the bitmap is marked immutable, this will diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h index aec37b6e686de..f0dde10f25c6b 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h @@ -8,8 +8,6 @@ #ifndef SkBlurTypes_DEFINED #define SkBlurTypes_DEFINED -#include "include/core/SkTypes.h" - enum SkBlurStyle : int { kNormal_SkBlurStyle, //!< fuzzy inside and outside kSolid_SkBlurStyle, //!< solid inside, fuzzy outside diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h index b16872809e322..225b733a6b717 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h @@ -12,6 +12,7 @@ #include "include/core/SkClipOp.h" #include "include/core/SkColor.h" #include "include/core/SkFontTypes.h" +#include "include/core/SkImageFilter.h" #include "include/core/SkImageInfo.h" #include "include/core/SkM44.h" #include "include/core/SkMatrix.h" @@ -26,13 +27,13 @@ #include "include/core/SkString.h" #include "include/core/SkSurfaceProps.h" #include "include/core/SkTypes.h" -#include "include/private/SkDeque.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkDeque.h" +#include #include #include #include -#include #ifndef SK_SUPPORT_LEGACY_GETTOTALMATRIX #define SK_SUPPORT_LEGACY_GETTOTALMATRIX @@ -44,34 +45,39 @@ class GlyphRunList; } class AutoLayerForImageFilter; -class GrBackendRenderTarget; class GrRecordingContext; + class SkBaseDevice; class SkBitmap; +class SkBlender; class SkData; class SkDrawable; -struct SkDrawShadowRec; class SkFont; class SkImage; -class SkImageFilter; +class SkMesh; class SkPaintFilterCanvas; class SkPath; class SkPicture; class SkPixmap; -class SkRegion; class SkRRect; -struct SkRSXform; -class SkMesh; +class SkRegion; +class SkShader; class SkSpecialImage; class SkSurface; class SkSurface_Base; class SkTextBlob; class SkVertices; +struct SkDrawShadowRec; +struct SkRSXform; namespace skgpu::graphite { class Recorder; } namespace sktext::gpu { class Slug; } namespace SkRecords { class Draw; } +#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_GANESH) +class GrBackendRenderTarget; +#endif + // TODO: // This is not ideal but Chrome is depending on a forward decl of GrSlug here. // It should be removed once Chrome has migrated to sktext::gpu::Slug. @@ -650,7 +656,7 @@ class SK_API SkCanvas { SkRect bounds suggests but does not define layer size. To clip drawing to a specific rectangle, use clipRect(). - alpha of zero is fully transparent, 255 is fully opaque. + alpha of zero is fully transparent, 1.0f is fully opaque. Call restoreToCount() with returned value to restore this and subsequent saves. @@ -660,7 +666,11 @@ class SK_API SkCanvas { example: https://fiddle.skia.org/c/@Canvas_saveLayerAlpha */ - int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); + int saveLayerAlphaf(const SkRect* bounds, float alpha); + // Helper that accepts an int between 0 and 255, and divides it by 255.0 + int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { + return this->saveLayerAlphaf(bounds, alpha * (1.0f / 255)); + } /** \enum SkCanvas::SaveLayerFlagsSet SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, @@ -2173,7 +2183,7 @@ class SK_API SkCanvas { /////////////////////////////////////////////////////////////////////////// -#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && SK_SUPPORT_GPU +#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_GANESH) // These methods exist to support WebView in Android Framework. SkIRect topLayerBounds() const; GrBackendRenderTarget topLayerBackendRenderTarget() const; @@ -2290,7 +2300,7 @@ class SK_API SkCanvas { virtual void onDiscard(); -#if (SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED)) +#if (defined(SK_GANESH) || defined(SK_GRAPHITE)) /** Experimental */ virtual sk_sp onConvertGlyphRunListToSlug( @@ -2352,6 +2362,13 @@ class SK_API SkCanvas { // Encapsulate state needed to restore from saveBehind() struct BackImage { + // Out of line to avoid including SkSpecialImage.h + BackImage(sk_sp, SkIPoint); + BackImage(const BackImage&); + BackImage(BackImage&&); + BackImage& operator=(const BackImage&); + ~BackImage(); + sk_sp fImage; SkIPoint fLoc; }; @@ -2406,7 +2423,7 @@ class SK_API SkCanvas { fSurfaceBase = sb; } friend class SkSurface_Base; - friend class SkSurface_Gpu; + friend class SkSurface_Ganesh; SkIRect fClipRestrictionRect = SkIRect::MakeEmpty(); int fClipRestrictionSaveCount = -1; @@ -2440,7 +2457,7 @@ class SK_API SkCanvas { SkCanvas& operator=(SkCanvas&&) = delete; SkCanvas& operator=(const SkCanvas&) = delete; -#if (SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED)) +#if (defined(SK_GANESH) || defined(SK_GRAPHITE)) friend class sktext::gpu::Slug; /** Experimental * Convert a SkTextBlob to a sktext::gpu::Slug using the current canvas state. diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h index ef15c1670823d..214b5138f0b71 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h @@ -15,7 +15,7 @@ namespace SkSL { struct ShaderCaps; } #endif -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) namespace skgpu::graphite { class Caps; } #endif @@ -28,7 +28,7 @@ class SK_API SkCapabilities : public SkRefCnt { #endif protected: -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) friend class skgpu::graphite::Caps; // for ctor #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h index 6a920e93fddb4..3b46be030f224 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h @@ -11,8 +11,10 @@ #include "include/core/SkAlphaType.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" #include +#include /** \file SkColor.h diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h index 29f64339baaac..f89de9db72fcb 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h @@ -9,9 +9,11 @@ #define SkColorPriv_DEFINED #include "include/core/SkColor.h" -#include "include/core/SkMath.h" -#include "include/private/SkTPin.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkTPin.h" +#include "include/private/base/SkTo.h" + +#include /** Turn 0..255 into 0..256 by adding 1 at the half-way point. Used to turn a byte into a scale value, so that we can say scale * value >> 8 instead of @@ -146,7 +148,20 @@ static SK_ALWAYS_INLINE uint32_t SkAlphaMulQ(uint32_t c, unsigned scale) { } static inline SkPMColor SkPMSrcOver(SkPMColor src, SkPMColor dst) { - return src + SkAlphaMulQ(dst, SkAlpha255To256(255 - SkGetPackedA32(src))); + uint32_t scale = SkAlpha255To256(255 - SkGetPackedA32(src)); + + uint32_t mask = 0xFF00FF; + uint32_t rb = (((dst & mask) * scale) >> 8) & mask; + uint32_t ag = (((dst >> 8) & mask) * scale) & ~mask; + + rb += (src & mask); + ag += (src & ~mask); + + // Color channels (but not alpha) can overflow, so we have to saturate to 0xFF in each lane. + return std::min(rb & 0x000001FF, 0x000000FFU) | + std::min(ag & 0x0001FF00, 0x0000FF00U) | + std::min(rb & 0x01FF0000, 0x00FF0000U) | + (ag & 0xFF000000); } #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h index a09758645b161..57c29e222a43b 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h @@ -9,10 +9,13 @@ #define SkColorSpace_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkFixed.h" -#include "include/private/SkOnce.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkFixed.h" +#include "include/private/base/SkOnce.h" #include "modules/skcms/skcms.h" -#include + +#include +#include class SkData; @@ -147,8 +150,7 @@ class SK_API SkColorSpace : public SkNVRefCnt { bool isNumericalTransferFn(skcms_TransferFunction* fn) const; /** - * Returns true and sets |toXYZD50| if the color gamut can be described as a matrix. - * Returns false otherwise. + * Returns true and sets |toXYZD50|. */ bool toXYZD50(skcms_Matrix3x3* toXYZD50) const; @@ -160,23 +162,19 @@ class SK_API SkColorSpace : public SkNVRefCnt { /** * Returns a color space with the same gamut as this one, but with a linear gamma. - * For color spaces whose gamut can not be described in terms of XYZ D50, returns - * linear sRGB. */ sk_sp makeLinearGamma() const; /** - * Returns a color space with the same gamut as this one, with with the sRGB transfer - * function. For color spaces whose gamut can not be described in terms of XYZ D50, returns - * sRGB. + * Returns a color space with the same gamut as this one, but with the sRGB transfer + * function. */ sk_sp makeSRGBGamma() const; /** * Returns a color space with the same transfer function as this one, but with the primary - * colors rotated. For any XYZ space, this produces a new color space that maps RGB to GBR - * (when applied to a source), and maps RGB to BRG (when applied to a destination). For other - * types of color spaces, returns nullptr. + * colors rotated. In other words, this produces a new color space that maps RGB to GBR + * (when applied to a source), and maps RGB to BRG (when applied to a destination). * * This is used for testing, to construct color spaces that have severe and testable behavior. */ @@ -190,15 +188,14 @@ class SK_API SkColorSpace : public SkNVRefCnt { * in some cases: converting ICC fixed point to float, converting white point to D50, * rounding decisions on transfer function and matrix. * - * This does not consider a 2.2f exponential transfer function to be sRGB. While these + * This does not consider a 2.2f exponential transfer function to be sRGB. While these * functions are similar (and it is sometimes useful to consider them together), this * function checks for logical equality. */ bool isSRGB() const; /** - * Returns nullptr on failure. Fails when we fallback to serializing ICC data and - * the data is too large to serialize. + * Returns a serialized representation of this color space. */ sk_sp serialize() const; @@ -211,7 +208,7 @@ class SK_API SkColorSpace : public SkNVRefCnt { static sk_sp Deserialize(const void* data, size_t length); /** - * If both are null, we return true. If one is null and the other is not, we return false. + * If both are null, we return true. If one is null and the other is not, we return false. * If both are non-null, we do a deeper compare. */ static bool Equals(const SkColorSpace*, const SkColorSpace*); diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h index b51aa7b96f96b..a68dc833b49b5 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h @@ -28,6 +28,7 @@ enum SkColorType : int { kBGRA_1010102_SkColorType, //!< 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word kRGB_101010x_SkColorType, //!< pixel with 10 bits each for red, green, blue; in 32-bit word kBGR_101010x_SkColorType, //!< pixel with 10 bits each for blue, green, red; in 32-bit word + kBGR_101010x_XR_SkColorType, //!< pixel with 10 bits each for blue, green, red; in 32-bit word, extended range kGray_8_SkColorType, //!< pixel with grayscale level in 8-bit byte kRGBA_F16Norm_SkColorType, //!< pixel with half floats in [0,1] for red, green, blue, alpha; // in 64-bit word diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h index 08a50b11054c8..7090deaaed22a 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h @@ -10,7 +10,7 @@ #include "include/core/SkPath.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" struct SkConic; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h index ea5b73d1a4776..aaae60c41920d 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h @@ -8,8 +8,6 @@ #ifndef SkCoverageMode_DEFINED #define SkCoverageMode_DEFINED -#include "include/core/SkTypes.h" - /** * Describes geometric operations (ala SkRegion::Op) that can be applied to coverage bytes. * These can be thought of as variants of porter-duff (SkBlendMode) modes, but only applied diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h index 7389b92afd099..863c9333f6e1e 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h @@ -9,6 +9,8 @@ #define SkCubicMap_DEFINED #include "include/core/SkPoint.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" /** * Fast evaluation of a cubic ease-in / ease-out curve. This is defined as a parametric cubic diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkData.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkData.h index 2a4b40d5f614a..2b50cebc81b6a 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkData.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkData.h @@ -8,9 +8,12 @@ #ifndef SkData_DEFINED #define SkData_DEFINED -#include - #include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" + +#include +#include class SkStream; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h index a6a510b7b221e..3aa48d5f33ea0 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h @@ -8,8 +8,12 @@ #ifndef SkDataTable_DEFINED #define SkDataTable_DEFINED -#include "include/core/SkData.h" -#include "include/private/SkTDArray.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" + +#include +#include /** * Like SkData, SkDataTable holds an immutable data buffer. The data buffer is diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h index 28e460fa8b050..e5511beea3aea 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h @@ -13,10 +13,11 @@ #include "include/core/SkTypes.h" class SkDeferredDisplayListPriv; +class SkPromiseImageTexture; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrRecordingContext.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include class GrRenderTask; class GrRenderTargetProxy; @@ -36,7 +37,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { return fCharacterization; } -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** * Iterate through the programs required by the DDL. */ @@ -52,7 +53,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { private: GrDirectContext* fDContext; - const SkTArray& fProgramData; + const skia_private::TArray& fProgramData; int fIndex; }; #endif @@ -70,7 +71,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { // texture when the DDL is replayed. It has to be separately ref counted bc the lazy proxy // can outlive the DDL. class LazyProxyData : public SkRefCnt { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) public: // Upon being replayed - this field will be filled in (by the DrawingManager) with the // proxy backing the destination SkSurface. Note that, since there is no good place to @@ -87,21 +88,21 @@ class SkDeferredDisplayList : public SkNVRefCnt { sk_sp fTargetProxy, sk_sp); -#if SK_SUPPORT_GPU - const SkTArray& programData() const { +#if defined(SK_GANESH) + const skia_private::TArray& programData() const { return fProgramData; } #endif const SkSurfaceCharacterization fCharacterization; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) // These are ordered such that the destructor cleans op tasks up first (which may refer back // to the arena and memory pool in their destructors). GrRecordingContext::OwnedArenas fArenas; - SkTArray> fRenderTasks; + skia_private::TArray> fRenderTasks; - SkTArray fProgramData; + skia_private::TArray fProgramData; sk_sp fTargetProxy; sk_sp fLazyProxyData; #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h index 8103485597fcf..cd91798513bdf 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h @@ -50,13 +50,14 @@ class SK_API SkDeferredDisplayListRecorder { sk_sp detach(); -#if SK_SUPPORT_GPU - using PromiseImageTextureContext = SkImage::PromiseImageTextureContext; - using PromiseImageTextureFulfillProc = SkImage::PromiseImageTextureFulfillProc; - using PromiseImageTextureReleaseProc = SkImage::PromiseImageTextureReleaseProc; +#if defined(SK_GANESH) + using PromiseImageTextureContext = void*; + using PromiseImageTextureFulfillProc = + sk_sp (*)(PromiseImageTextureContext); + using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); #ifndef SK_MAKE_PROMISE_TEXTURE_DISABLE_LEGACY_API - /** Deprecated: Use SkImage::MakePromiseTexture instead. */ + /** Deprecated: Use SkImages::PromiseTextureFrom instead. */ sk_sp makePromiseTexture(const GrBackendFormat& backendFormat, int width, int height, @@ -69,14 +70,14 @@ class SK_API SkDeferredDisplayListRecorder { PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContext); - /** Deprecated: Use SkImage::MakePromiseYUVATexture instead. */ + /** Deprecated: Use SkImages::PromiseTextureFromYUVA instead. */ sk_sp makeYUVAPromiseTexture(const GrYUVABackendTextureInfo& yuvaBackendTextureInfo, sk_sp imageColorSpace, PromiseImageTextureFulfillProc textureFulfillProc, PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContexts[]); #endif // SK_MAKE_PROMISE_TEXTURE_DISABLE_LEGACY_API -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) private: SkDeferredDisplayListRecorder(const SkDeferredDisplayListRecorder&) = delete; @@ -86,7 +87,7 @@ class SK_API SkDeferredDisplayListRecorder { const SkSurfaceCharacterization fCharacterization; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) sk_sp fContext; sk_sp fTargetProxy; sk_sp fLazyProxyData; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h index c86543dc6b367..316bf058bcf5a 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h @@ -9,14 +9,22 @@ #define SkDrawable_DEFINED #include "include/core/SkFlattenable.h" -#include "include/core/SkImageInfo.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" +#include "include/private/base/SkAPI.h" + +#include +#include +#include class GrBackendDrawableInfo; class SkCanvas; class SkMatrix; class SkPicture; -enum class GrBackendApi : unsigned; +enum class GrBackendApi : unsigned int; +struct SkDeserialProcs; +struct SkIRect; +struct SkImageInfo; struct SkRect; /** diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h index 99ca44e765c53..0db3830b9ac71 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h @@ -1,36 +1,9 @@ /* - * Copyright 2015 Google Inc. + * Copyright 2023 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#ifndef SkEncodedImageFormat_DEFINED -#define SkEncodedImageFormat_DEFINED - -#include - -/** - * Enum describing format of encoded data. - */ -enum class SkEncodedImageFormat { -#ifdef SK_BUILD_FOR_GOOGLE3 - kUnknown, -#endif - kBMP, - kGIF, - kICO, - kJPEG, - kPNG, - kWBMP, - kWEBP, - kPKM, - kKTX, - kASTC, - kDNG, - kHEIF, - kAVIF, - kJPEGXL, -}; - -#endif // SkEncodedImageFormat_DEFINED +// TODO(kjlubick) remove this shim after clients have been moved to the new location +#include "include/codec/SkEncodedImageFormat.h" // IWYU pragma: export diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h index 916ee174f4828..3585e845b5489 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h @@ -9,13 +9,15 @@ #define SkFlattenable_DEFINED #include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +#include class SkData; class SkReadBuffer; class SkWriteBuffer; - -struct SkSerialProcs; struct SkDeserialProcs; +struct SkSerialProcs; /** \class SkFlattenable diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h index 05fb7db414887..88e92694bd455 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h @@ -11,6 +11,7 @@ #include "include/core/SkFontTypes.h" #include "include/core/SkScalar.h" #include "include/core/SkTypeface.h" +#include "include/private/base/SkTemplates.h" #include diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h index 717a87f056f38..f4960393113cb 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h @@ -9,6 +9,7 @@ #define SkFontMetrics_DEFINED #include "include/core/SkScalar.h" +#include "include/private/base/SkTo.h" /** \class SkFontMetrics The metrics of an SkFont. diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h index 125262b466753..eccb0a729cba0 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h @@ -13,6 +13,8 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkTypes.h" +#include + class SkData; class SkFontData; class SkStreamAsset; @@ -23,23 +25,20 @@ class SK_API SkFontStyleSet : public SkRefCnt { public: virtual int count() = 0; virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0; - virtual SkTypeface* createTypeface(int index) = 0; - virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0; + virtual sk_sp createTypeface(int index) = 0; + virtual sk_sp matchStyle(const SkFontStyle& pattern) = 0; - static SkFontStyleSet* CreateEmpty(); + static sk_sp CreateEmpty(); protected: - SkTypeface* matchStyleCSS3(const SkFontStyle& pattern); - -private: - using INHERITED = SkRefCnt; + sk_sp matchStyleCSS3(const SkFontStyle& pattern); }; class SK_API SkFontMgr : public SkRefCnt { public: int countFamilies() const; void getFamilyName(int index, SkString* familyName) const; - SkFontStyleSet* createStyleSet(int index) const; + sk_sp createStyleSet(int index) const; /** * The caller must call unref() on the returned object. @@ -52,7 +51,7 @@ class SK_API SkFontMgr : public SkRefCnt { * It is possible that this will return a style set not accessible from * createStyleSet(int) due to hidden or auto-activated fonts. */ - SkFontStyleSet* matchFamily(const char familyName[]) const; + sk_sp matchFamily(const char familyName[]) const; /** * Find the closest matching typeface to the specified familyName and style @@ -66,7 +65,7 @@ class SK_API SkFontMgr : public SkRefCnt { * createStyleSet(int) or matchFamily(const char[]) due to hidden or * auto-activated fonts. */ - SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&) const; + sk_sp matchFamilyStyle(const char familyName[], const SkFontStyle&) const; /** * Use the system fallback to find a typeface for the given character. @@ -83,9 +82,9 @@ class SK_API SkFontMgr : public SkRefCnt { * most significant. If no specified bcp47 codes match, any font with the * requested character will be matched. */ - SkTypeface* matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const; + sk_sp matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const; /** * Create a typeface for the specified data and TTC index (pass 0 for none) @@ -123,16 +122,17 @@ class SK_API SkFontMgr : public SkRefCnt { protected: virtual int onCountFamilies() const = 0; virtual void onGetFamilyName(int index, SkString* familyName) const = 0; - virtual SkFontStyleSet* onCreateStyleSet(int index)const = 0; + virtual sk_sp onCreateStyleSet(int index)const = 0; /** May return NULL if the name is not found. */ - virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const = 0; + virtual sk_sp onMatchFamily(const char familyName[]) const = 0; - virtual SkTypeface* onMatchFamilyStyle(const char familyName[], - const SkFontStyle&) const = 0; - virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const = 0; + virtual sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle&) const = 0; + virtual sk_sp onMatchFamilyStyleCharacter(const char familyName[], + const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const = 0; virtual sk_sp onMakeFromData(sk_sp, int ttcIndex) const = 0; virtual sk_sp onMakeFromStreamIndex(std::unique_ptr, @@ -143,18 +143,9 @@ class SK_API SkFontMgr : public SkRefCnt { virtual sk_sp onLegacyMakeTypeface(const char familyName[], SkFontStyle) const = 0; - // this method is never called -- will be removed - virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, - const SkFontStyle&) const { - return nullptr; - } - private: - /** Implemented by porting layer to return the default factory. */ static sk_sp Factory(); - - using INHERITED = SkRefCnt; }; #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h index 04893ef2fdc59..be46b53bb2852 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h @@ -9,7 +9,9 @@ #define SkFontStyle_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkTPin.h" +#include "include/private/base/SkTPin.h" + +#include class SK_API SkFontStyle { public: @@ -75,6 +77,7 @@ class SK_API SkFontStyle { } private: + friend class SkTypefaceProxyPrototype; // To serialize fValue int32_t fValue; }; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h index c24bb742e71df..6ce9175d1e091 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h @@ -10,9 +10,12 @@ #include "include/core/SkRefCnt.h" +#include + class SkData; class SkImageGenerator; class SkOpenTypeSVGDecoder; +class SkPath; class SkTraceMemoryDump; class SK_API SkGraphics { @@ -115,16 +118,6 @@ class SK_API SkGraphics { */ static void PurgeAllCaches(); - /** - * Applications with command line options may pass optional state, such - * as cache sizes, here, for instance: - * font-cache-limit=12345678 - * - * The flags format is name=value[;name=value...] with no spaces. - * This format is subject to change. - */ - static void SetFlags(const char* flags); - typedef std::unique_ptr (*ImageGeneratorFromEncodedDataFactory)(sk_sp); @@ -151,18 +144,28 @@ class SK_API SkGraphics { static OpenTypeSVGDecoderFactory GetOpenTypeSVGDecoderFactory(); /** - * Temporarily (until variable COLRv1 is released) pass a feature switch function for whether - * variable COLRv1 is enabled. Needed for initializing FreeType with a property setting so that - * variable COLRv1 can be enabled in Chrome Canaries during development. + * Call early in main() to allow Skia to use a JIT to accelerate CPU-bound operations. */ - using VariableColrV1EnabledFunc = bool (*)(); - static VariableColrV1EnabledFunc SetVariableColrV1EnabledFunc(VariableColrV1EnabledFunc); - static bool GetVariableColrV1Enabled(); + static void AllowJIT(); /** - * Call early in main() to allow Skia to use a JIT to accelerate CPU-bound operations. + * To override the default AA algorithm choice in the CPU backend, provide a function that + * returns whether to use analytic (true) or supersampled (false) for a given path. + * + * NOTE: This is a temporary API, intended for migration of all clients to one algorithm, + * and should not be used. */ - static void AllowJIT(); + typedef bool (*PathAnalyticAADeciderProc)(const SkPath&); + static void SetPathAnalyticAADecider(PathAnalyticAADeciderProc); + + /* + * Similar to above, but simply forces the CPU backend to always use analytic AA. + * + * NOTE: This is a temporary API, intended for migration of all clients to one algorithm. + * If the PathAnalyticAADeciderProc is *also* set, this setting has no effect. + * Unlike that API, this function is thread-safe. + */ + static void SetForceAnalyticAA(bool); }; class SkAutoGraphics { diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h index cb84c1ffbc76d..c0b458100cf88 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h @@ -1,19 +1,9 @@ /* - * Copyright 2016 Google Inc. + * Copyright 2023 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#ifndef SkICC_DEFINED -#define SkICC_DEFINED - -#include "include/core/SkData.h" - -struct skcms_Matrix3x3; -struct skcms_TransferFunction; - -SK_API sk_sp SkWriteICCProfile(const skcms_TransferFunction&, - const skcms_Matrix3x3& toXYZD50); - -#endif//SkICC_DEFINED +// TODO(kjlubick) remove this shim after clients have been moved to the new location +#include "include/encode/SkICC.h" // IWYU pragma: export diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h index 4157eafa0b509..8f7d4a46bd9d9 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h @@ -8,581 +8,252 @@ #ifndef SkImage_DEFINED #define SkImage_DEFINED +#include "include/core/SkAlphaType.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/core/SkSamplingOptions.h" -#include "include/core/SkScalar.h" -#include "include/core/SkShader.h" -#include "include/core/SkSurfaceProps.h" -#include "include/core/SkTileMode.h" -#if SK_SUPPORT_GPU -#include "include/gpu/GrTypes.h" -#endif -#if defined(SK_GRAPHITE_ENABLED) +#include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" + +#if defined(SK_GRAPHITE) #include "include/gpu/graphite/GraphiteTypes.h" +class SkYUVAPixmaps; #endif -#include // std::function -#include -#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 -#include -#endif +#include +#include +#include +#include -class GrBackendFormat; -class GrBackendTexture; -class GrContextThreadSafeProxy; class GrDirectContext; class GrRecordingContext; -class GrYUVABackendTextureInfo; -class GrYUVABackendTextures; -class SkCanvas; +class SkBitmap; +class SkColorSpace; class SkData; class SkImage; class SkImageFilter; class SkImageGenerator; +class SkMatrix; class SkMipmap; class SkPaint; class SkPicture; class SkPixmap; -class SkPromiseImageTexture; -class SkSurface; -class SkYUVAPixmaps; +class SkShader; +class SkSurfaceProps; +enum SkColorType : int; +enum class SkTextureCompressionType; +enum class SkTileMode; -enum class SkEncodedImageFormat; +struct SkIPoint; +struct SkSamplingOptions; -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) namespace skgpu::graphite { class BackendTexture; class Recorder; -}; +class TextureInfo; +enum class Volatile : bool; +class YUVABackendTextures; +} #endif -/** \class SkImage - SkImage describes a two dimensional array of pixels to draw. The pixels may be - decoded in a raster bitmap, encoded in a SkPicture or compressed data stream, - or located in GPU memory as a GPU texture. - - SkImage cannot be modified after it is created. SkImage may allocate additional - storage as needed; for instance, an encoded SkImage may decode when drawn. +namespace SkImages { - SkImage width and height are greater than zero. Creating an SkImage with zero width - or height returns SkImage equal to nullptr. - - SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams, - GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported - include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details - vary with platform. +/** Caller data passed to RasterReleaseProc; may be nullptr. */ +using ReleaseContext = void*; +/** Function called when SkImage no longer shares pixels. ReleaseContext is + provided by caller when SkImage is created, and may be nullptr. */ -class SK_API SkImage : public SkRefCnt { -public: - - /** Caller data passed to RasterReleaseProc; may be nullptr. - */ - typedef void* ReleaseContext; - - /** Creates SkImage from SkPixmap and copy of pixels. Since pixels are copied, SkPixmap - pixels may be modified or deleted without affecting SkImage. - - SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param pixmap SkImageInfo, pixel address, and row bytes - @return copy of SkPixmap pixels, or nullptr +using RasterReleaseProc = void(const void* pixels, ReleaseContext); - example: https://fiddle.skia.org/c/@Image_MakeRasterCopy - */ - static sk_sp MakeRasterCopy(const SkPixmap& pixmap); - - /** Creates SkImage from SkImageInfo, sharing pixels. +/** Creates a CPU-backed SkImage from bitmap, sharing or copying bitmap pixels. If the bitmap + is marked immutable, and its pixel memory is shareable, it may be shared + instead of copied. - SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - rowBytes are large enough to hold one row of pixels; - pixels is not nullptr, and contains enough data for SkImage. - - @param info contains width, height, SkAlphaType, SkColorType, SkColorSpace - @param pixels address or pixel storage - @param rowBytes size of pixel row or larger - @return SkImage sharing pixels, or nullptr - */ - static sk_sp MakeRasterData(const SkImageInfo& info, sk_sp pixels, - size_t rowBytes); + SkImage is returned if bitmap is valid. Valid SkBitmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. - /** Function called when SkImage no longer shares pixels. ReleaseContext is - provided by caller when SkImage is created, and may be nullptr. - */ - typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext); - - /** Creates SkImage from pixmap, sharing SkPixmap pixels. Pixels must remain valid and - unchanged until rasterReleaseProc is called. rasterReleaseProc is passed - releaseContext when SkImage is deleted or no longer refers to pixmap pixels. - - Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback - when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc - does not require state. - - SkImage is returned if pixmap is valid. Valid SkPixmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param pixmap SkImageInfo, pixel address, and row bytes - @param rasterReleaseProc function called when pixels can be released; or nullptr - @param releaseContext state passed to rasterReleaseProc; or nullptr - @return SkImage sharing pixmap - */ - static sk_sp MakeFromRaster(const SkPixmap& pixmap, - RasterReleaseProc rasterReleaseProc, - ReleaseContext releaseContext); - - /** Creates SkImage from bitmap, sharing or copying bitmap pixels. If the bitmap - is marked immutable, and its pixel memory is shareable, it may be shared - instead of copied. - - SkImage is returned if bitmap is valid. Valid SkBitmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param bitmap SkImageInfo, row bytes, and pixels - @return created SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_MakeFromBitmap - */ - static sk_sp MakeFromBitmap(const SkBitmap& bitmap); - - /** Creates SkImage from data returned by imageGenerator. Generated data is owned by SkImage and - may not be shared or accessed. - - SkImage is returned if generator data is valid. Valid data parameters vary by type of data - and platform. - - imageGenerator may wrap SkPicture data, codec data, or custom data. - - @param imageGenerator stock or custom routines to retrieve SkImage - @return created SkImage, or nullptr - */ - static sk_sp MakeFromGenerator(std::unique_ptr imageGenerator); - - /** - * Return an image backed by the encoded data, but attempt to defer decoding until the image - * is actually used/drawn. This deferral allows the system to cache the result, either on the - * CPU or on the GPU, depending on where the image is drawn. If memory is low, the cache may - * be purged, causing the next draw of the image to have to re-decode. - * - * If alphaType is nullopt, the image's alpha type will be chosen automatically based on the - * image format. Transparent images will default to kPremul_SkAlphaType. If alphaType contains - * kPremul_SkAlphaType or kUnpremul_SkAlphaType, that alpha type will be used. Forcing opaque - * (passing kOpaque_SkAlphaType) is not allowed, and will return nullptr. - * - * This is similar to DecodeTo[Raster,Texture], but this method will attempt to defer the - * actual decode, while the DecodeTo... method explicitly decode and allocate the backend - * when the call is made. - * - * If the encoded format is not supported, nullptr is returned. - * - * @param encoded the encoded data - * @return created SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_MakeFromEncoded - */ - static sk_sp MakeFromEncoded(sk_sp encoded, - std::optional alphaType = std::nullopt); - - /* - * Experimental: - * Skia | GL_COMPRESSED_* | MTLPixelFormat* | VK_FORMAT_*_BLOCK - * -------------------------------------------------------------------------------------- - * kETC2_RGB8_UNORM | ETC1_RGB8 | ETC2_RGB8 (iOS-only) | ETC2_R8G8B8_UNORM - * | RGB8_ETC2 | | - * -------------------------------------------------------------------------------------- - * kBC1_RGB8_UNORM | RGB_S3TC_DXT1_EXT | N/A | BC1_RGB_UNORM - * -------------------------------------------------------------------------------------- - * kBC1_RGBA8_UNORM | RGBA_S3TC_DXT1_EXT | BC1_RGBA (macOS-only)| BC1_RGBA_UNORM - */ - enum class CompressionType { - kNone, - kETC2_RGB8_UNORM, // the same as ETC1 - - kBC1_RGB8_UNORM, - kBC1_RGBA8_UNORM, - kLast = kBC1_RGBA8_UNORM, - }; + @param bitmap SkImageInfo, row bytes, and pixels + @return created SkImage, or nullptr +*/ +SK_API sk_sp RasterFromBitmap(const SkBitmap& bitmap); - static constexpr int kCompressionTypeCount = static_cast(CompressionType::kLast) + 1; +/** Creates a CPU-backed SkImage from compressed data. - static const CompressionType kETC1_CompressionType = CompressionType::kETC2_RGB8_UNORM; + This method will decompress the compressed data and create an image wrapping + it. Any mipmap levels present in the compressed data are discarded. - /** Creates a CPU-backed SkImage from compressed data. + @param data compressed data to store in SkImage + @param width width of full SkImage + @param height height of full SkImage + @param type type of compression used + @return created SkImage, or nullptr +*/ +SK_API sk_sp RasterFromCompressedTextureData(sk_sp data, + int width, + int height, + SkTextureCompressionType type); + +/** + * Return a SkImage using the encoded data, but attempts to defer decoding until the + * image is actually used/drawn. This deferral allows the system to cache the result, either on the + * CPU or on the GPU, depending on where the image is drawn. If memory is low, the cache may + * be purged, causing the next draw of the image to have to re-decode. + * + * If alphaType is nullopt, the image's alpha type will be chosen automatically based on the + * image format. Transparent images will default to kPremul_SkAlphaType. If alphaType contains + * kPremul_SkAlphaType or kUnpremul_SkAlphaType, that alpha type will be used. Forcing opaque + * (passing kOpaque_SkAlphaType) is not allowed, and will return nullptr. + * + * If the encoded format is not supported, nullptr is returned. + * + * @param encoded the encoded data + * @return created SkImage, or nullptr - This method will decompress the compressed data and create an image wrapping - it. Any mipmap levels present in the compressed data are discarded. + example: https://fiddle.skia.org/c/@Image_DeferredFromEncodedData +*/ +SK_API sk_sp DeferredFromEncodedData(sk_sp encoded, + std::optional alphaType = std::nullopt); - @param data compressed data to store in SkImage - @param width width of full SkImage - @param height height of full SkImage - @param type type of compression used - @return created SkImage, or nullptr - */ - static sk_sp MakeRasterFromCompressed(sk_sp data, - int width, int height, - CompressionType type); +/** Creates SkImage from data returned by imageGenerator. The image data will not be created + (on either the CPU or GPU) until the image is actually drawn. + Generated data is owned by SkImage and may not be shared or accessed. - enum class BitDepth { - kU8, //!< uses 8-bit unsigned int per color component - kF16, //!< uses 16-bit float per color component - }; + SkImage is returned if generator data is valid. Valid data parameters vary by type of data + and platform. - /** Creates SkImage from picture. Returned SkImage width and height are set by dimensions. - SkImage draws picture with matrix and paint, set to bitDepth and colorSpace. + imageGenerator may wrap SkPicture data, codec data, or custom data. - If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws - with default SkPaint. colorSpace may be nullptr. + @param imageGenerator stock or custom routines to retrieve SkImage + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromGenerator(std::unique_ptr imageGenerator); - @param picture stream of drawing commands - @param dimensions width and height - @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr - @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr - @param bitDepth 8-bit integer or 16-bit float: per component - @param colorSpace range of colors; may be nullptr - @param props props to use when rasterizing the picture - @return created SkImage, or nullptr - */ - static sk_sp MakeFromPicture(sk_sp picture, const SkISize& dimensions, - const SkMatrix* matrix, const SkPaint* paint, - BitDepth bitDepth, sk_sp colorSpace, - SkSurfaceProps props = {}); - -#if SK_SUPPORT_GPU - /** Creates a GPU-backed SkImage from compressed data. - - This method will return an SkImage representing the compressed data. - If the GPU doesn't support the specified compression method, the data - will be decompressed and then wrapped in a GPU-backed image. - - Note: one can query the supported compression formats via - GrRecordingContext::compressedBackendFormat. - - @param context GPU context - @param data compressed data to store in SkImage - @param width width of full SkImage - @param height height of full SkImage - @param type type of compression used - @param mipmapped does 'data' contain data for all the mipmap levels? - @param isProtected do the contents of 'data' require DRM protection (on Vulkan)? - @return created SkImage, or nullptr - */ - static sk_sp MakeTextureFromCompressed(GrDirectContext* direct, - sk_sp data, - int width, int height, - CompressionType type, - GrMipmapped mipmapped = GrMipmapped::kNo, - GrProtected isProtected = GrProtected::kNo); - - /** User function called when supplied texture may be deleted. - */ - typedef void (*TextureReleaseProc)(ReleaseContext releaseContext); +enum class BitDepth { + kU8, //!< uses 8-bit unsigned int per color component + kF16, //!< uses 16-bit float per color component +}; - /** Creates SkImage from GPU texture associated with context. GPU texture must stay - valid and unchanged until textureReleaseProc is called. textureReleaseProc is - passed releaseContext when SkImage is deleted or no longer refers to texture. +/** Creates SkImage from picture. Returned SkImage width and height are set by dimensions. + SkImage draws picture with matrix and paint, set to bitDepth and colorSpace. - SkImage is returned if format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. + The Picture data is not turned into an image (CPU or GPU) until it is drawn. - @note When using a DDL recording context, textureReleaseProc will be called on the - GPU thread after the DDL is played back on the direct context. + If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws + with default SkPaint. colorSpace may be nullptr. - @param context GPU context - @param backendTexture texture residing on GPU - @param colorSpace This describes the color space of this image's contents, as - seen after sampling. In general, if the format of the backend - texture is SRGB, some linear colorSpace should be supplied - (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the - backend texture is linear, then the colorSpace should include - a description of the transfer function as - well (e.g., SkColorSpace::MakeSRGB()). - @param textureReleaseProc function called when texture can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin origin, - SkColorType colorType, - SkAlphaType alphaType, + @param picture stream of drawing commands + @param dimensions width and height + @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr + @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr + @param bitDepth 8-bit integer or 16-bit float: per component + @param colorSpace range of colors; may be nullptr + @param props props to use when rasterizing the picture + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromPicture(sk_sp picture, + const SkISize& dimensions, + const SkMatrix* matrix, + const SkPaint* paint, + BitDepth bitDepth, sk_sp colorSpace, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates an SkImage from a GPU backend texture. The backend texture must stay - valid and unchanged until textureReleaseProc is called. The textureReleaseProc is - called when the SkImage is deleted or no longer refers to the texture and will be - passed the releaseContext. - - An SkImage is returned if the format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. - - @note When using a DDL recording context, textureReleaseProc will be called on the - GPU thread after the DDL is played back on the direct context. - - @param context the GPU context - @param backendTexture a texture already allocated by the GPU - @param alphaType This characterizes the nature of the alpha values in the - backend texture. For opaque compressed formats (e.g., ETC1) - this should usually be set to kOpaque_SkAlphaType. - @param colorSpace This describes the color space of this image's contents, as - seen after sampling. In general, if the format of the backend - texture is SRGB, some linear colorSpace should be supplied - (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the - backend texture is linear, then the colorSpace should include - a description of the transfer function as - well (e.g., SkColorSpace::MakeSRGB()). - @param textureReleaseProc function called when the backend texture can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromCompressedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin origin, - SkAlphaType alphaType, - sk_sp colorSpace, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates SkImage from pixmap. SkImage is uploaded to GPU back-end using context. - - Created SkImage is available to other GPU contexts, and is available across thread - boundaries. All contexts must be in the same GPU share group, or otherwise - share resources. - - When SkImage is no longer referenced, context releases texture memory - asynchronously. - - GrBackendTexture created from pixmap is uploaded to match SkSurface created with - dstColorSpace. SkColorSpace of SkImage is determined by pixmap.colorSpace(). - - SkImage is returned referring to GPU back-end if context is not nullptr, - format of data is recognized and supported, and if context supports moving - resources between contexts. Otherwise, pixmap pixel data is copied and SkImage - as returned in raster format if possible; nullptr may be returned. - Recognized GPU formats vary by platform and GPU back-end. - - @param context GPU context - @param pixmap SkImageInfo, pixel address, and row bytes - @param buildMips create SkImage as mip map if true - @param dstColorSpace range of colors of matching SkSurface on GPU - @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary - @return created SkImage, or nullptr - */ - static sk_sp MakeCrossContextFromPixmap(GrDirectContext* context, - const SkPixmap& pixmap, - bool buildMips, - bool limitToMaxTextureSize = false); - - /** Creates SkImage from backendTexture associated with context. backendTexture and - returned SkImage are managed internally, and are released when no longer needed. - - SkImage is returned if format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. - - @param context GPU context - @param backendTexture texture residing on GPU - @param textureOrigin origin of backendTexture - @param colorType color type of the resulting image - @param alphaType alpha type of the resulting image - @param colorSpace range of colors; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType); - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType, - SkAlphaType alphaType); - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace); - - /** Creates an SkImage from YUV[A] planar textures. This requires that the textures stay valid - for the lifetime of the image. The ReleaseContext can be used to know when it is safe to - either delete or overwrite the textures. If ReleaseProc is provided it is also called before - return on failure. - - @param context GPU context - @param yuvaTextures A set of textures containing YUVA data and a description of the - data and transformation to RGBA. - @param imageColorSpace range of colors of the resulting image after conversion to RGB; - may be nullptr - @param textureReleaseProc called when the backend textures can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromYUVATextures(GrRecordingContext* context, - const GrYUVABackendTextures& yuvaTextures, - sk_sp imageColorSpace = nullptr, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates SkImage from SkYUVAPixmaps. - - The image will remain planar with each plane converted to a texture using the passed - GrRecordingContext. - - SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. - The SkColorSpace of the resulting RGB values is specified by imageColorSpace. This will - be the SkColorSpace reported by the image and when drawn the RGB values will be converted - from this space into the destination space (if the destination is tagged). - - Currently, this is only supported using the GPU backend and will fail if context is nullptr. + SkSurfaceProps props); +SK_API sk_sp DeferredFromPicture(sk_sp picture, + const SkISize& dimensions, + const SkMatrix* matrix, + const SkPaint* paint, + BitDepth bitDepth, + sk_sp colorSpace); + +/** Creates a CPU-backed SkImage from pixmap, copying the pixel data. + As a result, pixmap pixels may be modified or deleted without affecting SkImage. + + SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. + + @param pixmap SkImageInfo, pixel address, and row bytes + @return copy of SkPixmap pixels, or nullptr + + example: https://fiddle.skia.org/c/@Image_RasterFromPixmapCopy +*/ +SK_API sk_sp RasterFromPixmapCopy(const SkPixmap& pixmap); + +/** Creates CPU-backed SkImage from pixmap, sharing SkPixmap pixels. Pixels must remain valid and + unchanged until rasterReleaseProc is called. rasterReleaseProc is passed + releaseContext when SkImage is deleted or no longer refers to pixmap pixels. + + Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback + when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc + does not require state. + + SkImage is returned if pixmap is valid. Valid SkPixmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. + + @param pixmap SkImageInfo, pixel address, and row bytes + @param rasterReleaseProc function called when pixels can be released; or nullptr + @param releaseContext state passed to rasterReleaseProc; or nullptr + @return SkImage sharing pixmap +*/ +SK_API sk_sp RasterFromPixmap(const SkPixmap& pixmap, + RasterReleaseProc rasterReleaseProc, + ReleaseContext releaseContext); + +/** Creates CPU-backed SkImage from pixel data described by info. + The pixels data will *not* be copied. + + SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + rowBytes are large enough to hold one row of pixels; + pixels is not nullptr, and contains enough data for SkImage. + + @param info contains width, height, SkAlphaType, SkColorType, SkColorSpace + @param pixels address or pixel storage + @param rowBytes size of pixel row or larger + @return SkImage sharing pixels, or nullptr +*/ +SK_API sk_sp RasterFromData(const SkImageInfo& info, + sk_sp pixels, + size_t rowBytes); - SkYUVAPixmaps does not need to remain valid after this returns. +} // namespace SkImages - @param context GPU context - @param pixmaps The planes as pixmaps with supported SkYUVAInfo that - specifies conversion to RGB. - @param buildMips create internal YUVA textures as mip map if kYes. This is - silently ignored if the context does not support mip maps. - @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary - @param imageColorSpace range of colors of the resulting image; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromYUVAPixmaps(GrRecordingContext* context, - const SkYUVAPixmaps& pixmaps, - GrMipmapped buildMips = GrMipmapped::kNo, - bool limitToMaxTextureSize = false, - sk_sp imageColorSpace = nullptr); - - using PromiseImageTextureContext = void*; - using PromiseImageTextureFulfillProc = - sk_sp (*)(PromiseImageTextureContext); - using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); - - /** Create a new SkImage that is very similar to an SkImage created by MakeFromTexture. The - difference is that the caller need not have created the texture nor populated it with the - image pixel data. Moreover, the SkImage may be created on a thread as the creation of the - image does not require access to the backend API or GrDirectContext. Instead of passing a - GrBackendTexture the client supplies a description of the texture consisting of - GrBackendFormat, width, height, and GrMipmapped state. The resulting SkImage can be drawn - to a SkDeferredDisplayListRecorder or directly to a GPU-backed SkSurface. - - When the actual texture is required to perform a backend API draw, textureFulfillProc will - be called to receive a GrBackendTexture. The properties of the GrBackendTexture must match - those set during the SkImage creation, and it must refer to a valid existing texture in the - backend API context/device, and be populated with the image pixel data. The texture cannot - be deleted until textureReleaseProc is called. - - There is at most one call to each of textureFulfillProc and textureReleaseProc. - textureReleaseProc is always called even if image creation fails or if the - image is never fulfilled (e.g. it is never drawn or all draws are clipped out) - - @param gpuContextProxy the thread-safe proxy of the gpu context. required. - @param backendFormat format of promised gpu texture - @param dimensions width & height of promised gpu texture - @param mipmapped mip mapped state of promised gpu texture - @param origin surface origin of promised gpu texture - @param colorType color type of promised gpu texture - @param alphaType alpha type of promised gpu texture - @param colorSpace range of colors; may be nullptr - @param textureFulfillProc function called to get actual gpu texture - @param textureReleaseProc function called when texture can be deleted - @param textureContext state passed to textureFulfillProc and textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakePromiseTexture(sk_sp gpuContextProxy, - const GrBackendFormat& backendFormat, - SkISize dimensions, - GrMipmapped mipmapped, - GrSurfaceOrigin origin, - SkColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace, - PromiseImageTextureFulfillProc textureFulfillProc, - PromiseImageTextureReleaseProc textureReleaseProc, - PromiseImageTextureContext textureContext); - - /** This entry point operates like 'MakePromiseTexture' but it is used to construct a SkImage - from YUV[A] data. The source data may be planar (i.e. spread across multiple textures). In - the extreme Y, U, V, and A are all in different planes and thus the image is specified by - four textures. 'backendTextureInfo' describes the planar arrangement, texture formats, - conversion to RGB, and origin of the textures. Separate 'textureFulfillProc' and - 'textureReleaseProc' calls are made for each texture. Each texture has its own - PromiseImageTextureContext. If 'backendTextureInfo' is not valid then no release proc - calls are made. Otherwise, the calls will be made even on failure. 'textureContexts' has one - entry for each of the up to four textures, as indicated by 'backendTextureInfo'. - - Currently the mip mapped property of 'backendTextureInfo' is ignored. However, in the - near future it will be required that if it is kYes then textureFulfillProc must return - a mip mapped texture for each plane in order to successfully draw the image. - - @param gpuContextProxy the thread-safe proxy of the gpu context. required. - @param backendTextureInfo info about the promised yuva gpu texture - @param imageColorSpace range of colors; may be nullptr - @param textureFulfillProc function called to get actual gpu texture - @param textureReleaseProc function called when texture can be deleted - @param textureContexts state passed to textureFulfillProc and textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakePromiseYUVATexture(sk_sp gpuContextProxy, - const GrYUVABackendTextureInfo& backendTextureInfo, - sk_sp imageColorSpace, - PromiseImageTextureFulfillProc textureFulfillProc, - PromiseImageTextureReleaseProc textureReleaseProc, - PromiseImageTextureContext textureContexts[]); +/** \class SkImage + SkImage describes a two dimensional array of pixels to draw. The pixels may be + decoded in a raster bitmap, encoded in a SkPicture or compressed data stream, + or located in GPU memory as a GPU texture. -#endif // SK_SUPPORT_GPU + SkImage cannot be modified after it is created. SkImage may allocate additional + storage as needed; for instance, an encoded SkImage may decode when drawn. -#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 - /** (See Skia bug 7447) - Creates SkImage from Android hardware buffer. - Returned SkImage takes a reference on the buffer. + SkImage width and height are greater than zero. Creating an SkImage with zero width + or height returns SkImage equal to nullptr. - Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams, + GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported + include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details + vary with platform. - @param hardwareBuffer AHardwareBuffer Android hardware buffer - @param colorSpace range of colors; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAHardwareBuffer( - AHardwareBuffer* hardwareBuffer, - SkAlphaType alphaType = kPremul_SkAlphaType, - sk_sp colorSpace = nullptr, - GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); - - /** Creates SkImage from Android hardware buffer and uploads the data from the SkPixmap to it. - Returned SkImage takes a reference on the buffer. - - Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. - - @param context GPU context - @param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer - @param hardwareBuffer AHardwareBuffer Android hardware buffer - @param surfaceOrigin surface origin for resulting image - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAHardwareBufferWithData( - GrDirectContext* context, - const SkPixmap& pixmap, - AHardwareBuffer* hardwareBuffer, - GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); -#endif + See SkImages namespace for the static factory methods to make SkImages. + Clients should *not* subclass SkImage as there is a lot of internal machinery that is + not publicly accessible. +*/ +class SK_API SkImage : public SkRefCnt { +public: /** Returns a SkImageInfo describing the width, height, color type, alpha type, and color space of the SkImage. @@ -691,18 +362,12 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, const SkMatrix* localMatrix = nullptr) const; - sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& lm) const { - return this->makeShader(tmx, tmy, sampling, &lm); - } - sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm); - } + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix* lm = nullptr) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm); - } + const SkMatrix* lm = nullptr) const; /** * makeRawShader functions like makeShader, but for images that contain non-color data. @@ -719,20 +384,12 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, const SkMatrix* localMatrix = nullptr) const; - sk_sp makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& lm) const { - return this->makeRawShader(tmx, tmy, sampling, &lm); - } - sk_sp makeRawShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const { - return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm); - } + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeRawShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeRawShader(const SkSamplingOptions& sampling, - const SkMatrix* lm = nullptr) const { - return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm); - } - - using CubicResampler = SkCubicResampler; + const SkMatrix* lm = nullptr) const; /** Copies SkImage pixel address, row bytes, and SkImageInfo to pixmap, if address is available, and returns true. If pixel address is not available, return @@ -752,12 +409,12 @@ class SK_API SkImage : public SkRefCnt { example: https://fiddle.skia.org/c/@Image_isTextureBacked */ - bool isTextureBacked() const; + virtual bool isTextureBacked() const = 0; /** Returns an approximation of the amount of texture memory used by the image. Returns zero if the image is not texture backed or if the texture has an external format. */ - size_t textureSize() const; + virtual size_t textureSize() const = 0; /** Returns true if SkImage can be drawn on either raster surface or GPU surface. If context is nullptr, tests if SkImage draws on raster surface; @@ -772,43 +429,7 @@ class SK_API SkImage : public SkRefCnt { example: https://fiddle.skia.org/c/@Image_isValid */ - bool isValid(GrRecordingContext* context) const; - -#if SK_SUPPORT_GPU - /** Flushes any pending uses of texture-backed images in the GPU backend. If the image is not - texture-backed (including promise texture images) or if the GrDirectContext does not - have the same context ID as the context backing the image then this is a no-op. - - If the image was not used in any non-culled draws in the current queue of work for the - passed GrDirectContext then this is a no-op unless the GrFlushInfo contains semaphores or - a finish proc. Those are respected even when the image has not been used. - - @param context the context on which to flush pending usages of the image. - @param info flush options - */ - GrSemaphoresSubmitted flush(GrDirectContext* context, const GrFlushInfo& flushInfo) const; - - void flush(GrDirectContext* context) const { this->flush(context, {}); } - - /** Version of flush() that uses a default GrFlushInfo. Also submits the flushed work to the - GPU. - */ - void flushAndSubmit(GrDirectContext*) const; - - /** Retrieves the back-end texture. If SkImage has no back-end texture, an invalid - object is returned. Call GrBackendTexture::isValid to determine if the result - is valid. - - If flushPendingGrContextIO is true, completes deferred I/O operations. - - If origin in not nullptr, copies location of content drawn into SkImage. - - @param flushPendingGrContextIO flag to flush outstanding requests - @return back-end API texture handle; invalid on failure - */ - GrBackendTexture getBackendTexture(bool flushPendingGrContextIO, - GrSurfaceOrigin* origin = nullptr) const; -#endif // SK_SUPPORT_GPU + virtual bool isValid(GrRecordingContext* context) const = 0; /** \enum SkImage::CachingHint CachingHint selects whether Skia may internally cache SkBitmap generated by @@ -941,40 +562,11 @@ class SK_API SkImage : public SkRefCnt { enum class RescaleMode { kNearest, + kLinear, kRepeatedLinear, kRepeatedCubic, }; - /** Makes image pixel data available to caller, possibly asynchronously. - - Currently asynchronous reads are only supported on the GPU backend and only when the - underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all - other cases this operates synchronously. - - Data is read from the source sub-rectangle, then converted to the color space, color type, - and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the image - causes failure. - - When the pixel data is ready the caller's ReadPixelsCallback is called with a - AsyncReadResult containing pixel data in the requested color type, alpha type, and color - space. The AsyncReadResult will have count() == 1. Upon failure the callback is called with - nullptr for AsyncReadResult. For a GPU image this flushes work but a submit must occur to - guarantee a finite time before the callback is called. - - The data is valid for the lifetime of AsyncReadResult with the exception that if the SkImage - is GPU-backed the data is immediately invalidated if the context is abandoned or - destroyed. - - @param info info of the requested pixels - @param srcRect subrectangle of image to read - @param callback function to call with result of the read - @param context passed to callback - */ - void asyncReadPixels(const SkImageInfo& info, - const SkIRect& srcRect, - ReadPixelsCallback callback, - ReadPixelsContext context) const; - /** Makes image pixel data available to caller, possibly asynchronously. It can also rescale the image pixels. @@ -1071,44 +663,6 @@ class SK_API SkImage : public SkRefCnt { bool scalePixels(const SkPixmap& dst, const SkSamplingOptions&, CachingHint cachingHint = kAllow_CachingHint) const; - /** Encodes SkImage pixels, returning result as SkData. - - Returns nullptr if encoding fails, or if encodedImageFormat is not supported. - - SkImage encoding in a format requires both building with one or more of: - SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP; and platform support - for the encoded format. - - If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encodedImageFormat can - additionally be one of: SkEncodedImageFormat::kICO, SkEncodedImageFormat::kBMP, - SkEncodedImageFormat::kGIF. - - quality is a platform and format specific metric trading off size and encoding - error. When used, quality equaling 100 encodes with the least error. quality may - be ignored by the encoder. - - @param encodedImageFormat one of: SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kPNG, - SkEncodedImageFormat::kWEBP - @param quality encoder specific metric with 100 equaling best - @return encoded SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_encodeToData - */ - sk_sp encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const; - - /** Encodes SkImage pixels, returning result as SkData. Returns existing encoded data - if present; otherwise, SkImage is encoded with SkEncodedImageFormat::kPNG. Skia - must be built with SK_ENCODE_PNG to encode SkImage. - - Returns nullptr if existing encoded data is missing or invalid, and - encoding fails. - - @return encoded SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_encodeToData_2 - */ - sk_sp encodeToData() const; - /** Returns encoded SkImage pixels as SkData, if SkImage was created from supported encoded stream format. Platform support for formats vary and may require building with one or more of: SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP. @@ -1151,33 +705,79 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp withDefaultMipmaps() const; -#if SK_SUPPORT_GPU - /** Returns SkImage backed by GPU texture associated with context. Returned SkImage is - compatible with SkSurface created with dstColorSpace. The returned SkImage respects - mipmapped setting; if mipmapped equals GrMipmapped::kYes, the backing texture - allocates mip map levels. - - The mipmapped parameter is effectively treated as kNo if MIP maps are not supported by the - GPU. - - Returns original SkImage if the image is already texture-backed, the context matches, and - mipmapped is compatible with the backing GPU texture. SkBudgeted is ignored in this case. - - Returns nullptr if context is nullptr, or if SkImage was created with another - GrDirectContext. +#if defined(SK_GANESH) || defined(SK_GRAPHITE) + using ReleaseContext = SkImages::ReleaseContext; + using TextureReleaseProc = void (*)(ReleaseContext); +#endif - @param GrDirectContext the GrDirectContext in play, if it exists - @param GrMipmapped whether created SkImage texture must allocate mip map levels - @param SkBudgeted whether to count a newly created texture for the returned image - counts against the context's budget. - @return created SkImage, or nullptr +#if defined(SK_GRAPHITE) + // Passed to both fulfill and imageRelease + using GraphitePromiseImageContext = void*; + // Returned from fulfill and passed into textureRelease + using GraphitePromiseTextureReleaseContext = void*; + + using GraphitePromiseImageFulfillProc = + std::tuple + (*)(GraphitePromiseImageContext); + using GraphitePromiseImageReleaseProc = void (*)(GraphitePromiseImageContext); + using GraphitePromiseTextureReleaseProc = void (*)(GraphitePromiseTextureReleaseContext); + + /** Create a new SkImage that is very similar to an SkImage created by + MakeGraphiteFromBackendTexture. The difference is that the caller need not have created the + backend texture nor populated it with data when creating the image. Instead of passing a + BackendTexture to the factory the client supplies a description of the texture consisting + of dimensions, TextureInfo, SkColorInfo and Volatility. + + In general, 'fulfill' must return a BackendTexture that matches the properties + provided at SkImage creation time. The BackendTexture must refer to a valid existing + texture in the backend API context/device, and already be populated with data. + The texture cannot be deleted until 'textureRelease' is called. 'textureRelease' will + be called with the textureReleaseContext returned by 'fulfill'. + + Wrt when and how often the fulfill, imageRelease, and textureRelease callbacks will + be called: + + For non-volatile promise images, 'fulfill' will be called at Context::insertRecording + time. Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' will always be + called only once - when Skia will no longer try calling 'fulfill' to get a backend + texture. If 'fulfill' failed (i.e., it didn't return a valid backend texture) then + 'textureRelease' will never be called. If 'fulfill' was successful then + 'textureRelease' will be called only once when the GPU is done with the contents of the + promise image. This will usually occur during a Context::submit call but it could occur + earlier due to error conditions. 'fulfill' can be called multiple times if the promise + image is used in multiple recordings. If 'fulfill' fails, the insertRecording itself will + fail. Subsequent insertRecording calls (with Recordings that use the promise image) will + keep calling 'fulfill' until it succeeds. + + For volatile promise images, 'fulfill' will be called each time the Recording is inserted + into a Context. Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' + will always be called only once just like the non-volatile case. If 'fulfill' fails at + insertRecording-time, 'textureRelease' will never be called. If 'fulfill' was successful + then a 'textureRelease' matching that 'fulfill' will be called when the GPU is done with + the contents of the promise image. This will usually occur during a Context::submit call + but it could occur earlier due to error conditions. + + @param recorder the recorder that will capture the commands creating the image + @param dimensions width & height of promised gpu texture + @param textureInfo structural information for the promised gpu texture + @param colorInfo color type, alpha type and colorSpace information for the image + @param isVolatile volatility of the promise image + @param fulfill function called to get the actual backend texture + @param imageRelease function called when any image-centric data can be deleted + @param textureRelease function called when the backend texture can be deleted + @param imageContext state passed to fulfill and imageRelease + @return created SkImage, or nullptr */ - sk_sp makeTextureImage(GrDirectContext*, - GrMipmapped = GrMipmapped::kNo, - SkBudgeted = SkBudgeted::kYes) const; -#endif + static sk_sp MakeGraphitePromiseTexture(skgpu::graphite::Recorder*, + SkISize dimensions, + const skgpu::graphite::TextureInfo&, + const SkColorInfo&, + skgpu::graphite::Volatile, + GraphitePromiseImageFulfillProc, + GraphitePromiseImageReleaseProc, + GraphitePromiseTextureReleaseProc, + GraphitePromiseImageContext); -#ifdef SK_GRAPHITE_ENABLED /** Creates an SkImage from a GPU texture associated with the recorder. SkImage is returned if the format of backendTexture is recognized and supported. @@ -1198,12 +798,60 @@ class SK_API SkImage : public SkRefCnt { const skgpu::graphite::BackendTexture&, SkColorType colorType, SkAlphaType alphaType, - sk_sp colorSpace); + sk_sp colorSpace, + TextureReleaseProc = nullptr, + ReleaseContext = nullptr); + + /** Creates an SkImage from YUV[A] planar textures associated with the recorder. + @param recorder The recorder. + @param yuvaBackendTextures A set of textures containing YUVA data and a description of the + data and transformation to RGBA. + @param imageColorSpace range of colors of the resulting image after conversion to RGB; + may be nullptr + @param TextureReleaseProc called when the backend textures can be released + @param ReleaseContext state passed to TextureReleaseProc + @return created SkImage, or nullptr + */ + static sk_sp MakeGraphiteFromYUVABackendTextures( + skgpu::graphite::Recorder* recorder, + const skgpu::graphite::YUVABackendTextures& yuvaBackendTextures, + sk_sp imageColorSpace, + TextureReleaseProc = nullptr, + ReleaseContext = nullptr); struct RequiredImageProperties { - skgpu::graphite::Mipmapped fMipmapped; + skgpu::Mipmapped fMipmapped; }; + /** Creates SkImage from SkYUVAPixmaps. + + The image will remain planar with each plane converted to a texture using the passed + Recorder. + + SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. + The SkColorSpace of the resulting RGB values is specified by imgColorSpace. This will + be the SkColorSpace reported by the image and when drawn the RGB values will be converted + from this space into the destination space (if the destination is tagged). + + This is only supported using the GPU backend and will fail if recorder is nullptr. + + SkYUVAPixmaps does not need to remain valid after this returns. + + @param Recorder The Recorder to use for storing commands + @param pixmaps The planes as pixmaps with supported SkYUVAInfo that + specifies conversion to RGB. + @param RequiredImageProperties Properties the returned SkImage must possess (e.g., + mipmaps) + @param limitToMaxTextureSize Downscale image to GPU maximum texture size, if necessary + @param imgColorSpace Range of colors of the resulting image; may be nullptr + @return Created SkImage, or nullptr + */ + static sk_sp MakeGraphiteFromYUVAPixmaps(skgpu::graphite::Recorder*, + const SkYUVAPixmaps& pixmaps, + RequiredImageProperties = {}, + bool limitToMaxTextureSize = false, + sk_sp imgColorSpace = nullptr); + /** Graphite version of makeTextureImage. Returns an SkImage backed by a Graphite texture, using the provided Recorder for creation @@ -1225,9 +873,70 @@ class SK_API SkImage : public SkRefCnt { mipmaps) @return created SkImage, or nullptr */ - sk_sp makeTextureImage(skgpu::graphite::Recorder*, - RequiredImageProperties = {}) const; -#endif + virtual sk_sp makeTextureImage(skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const = 0; + + /** Returns subset of this image. + + Returns nullptr if any of the following are true: + - Subset is empty + - Subset is not contained inside the image's bounds + - Pixels in the image could not be read or copied + + If this image is texture-backed, the recorder parameter is required. + If the recorder parameter is provided, and the image is raster-backed, the subset will + be converted to texture-backed. + + @param subset bounds of returned SkImage + @param recorder the recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return the subsetted image, or nullptr + */ + sk_sp makeSubset(const SkIRect& subset, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + + /** Creates SkImage in target SkColorSpace. + Returns nullptr if SkImage could not be created. + + Returns original SkImage if it is in target SkColorSpace. + Otherwise, converts pixels from SkImage SkColorSpace to target SkColorSpace. + If SkImage colorSpace() returns nullptr, SkImage SkColorSpace is assumed to be sRGB. + + If this image is graphite-backed, the recorder parameter is required. + + @param targetColorSpace SkColorSpace describing color range of returned SkImage + @param recorder The Recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return created SkImage in target SkColorSpace + */ + sk_sp makeColorSpace(sk_sp targetColorSpace, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + + /** Experimental. + Creates SkImage in target SkColorType and SkColorSpace. + Returns nullptr if SkImage could not be created. + + Returns original SkImage if it is in target SkColorType and SkColorSpace. + + If this image is graphite-backed, the recorder parameter is required. + + @param targetColorType SkColorType of returned SkImage + @param targetColorSpace SkColorSpace of returned SkImage + @param recorder The Recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return created SkImage in target SkColorType and SkColorSpace + */ + sk_sp makeColorTypeAndColorSpace(SkColorType targetColorType, + sk_sp targetColorSpace, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + +#endif // SK_GRAPHITE /** Returns raster image or lazy image. Copies SkImage backed by GPU texture into CPU memory if needed. Returns original SkImage if decoded in raster bitmap, @@ -1285,38 +994,6 @@ class SK_API SkImage : public SkRefCnt { const SkIRect& clipBounds, SkIRect* outSubset, SkIPoint* offset) const; - /** Defines a callback function, taking one parameter of type GrBackendTexture with - no return value. Function is called when back-end texture is to be released. - */ - typedef std::function BackendTextureReleaseProc; - -#if SK_SUPPORT_GPU - /** Creates a GrBackendTexture from the provided SkImage. Returns true and - stores result in backendTexture and backendTextureReleaseProc if - texture is created; otherwise, returns false and leaves - backendTexture and backendTextureReleaseProc unmodified. - - Call backendTextureReleaseProc after deleting backendTexture. - backendTextureReleaseProc cleans up auxiliary data related to returned - backendTexture. The caller must delete returned backendTexture after use. - - If SkImage is both texture backed and singly referenced, image is returned in - backendTexture without conversion or making a copy. SkImage is singly referenced - if its was transferred solely using std::move(). - - If SkImage is not texture backed, returns texture with SkImage contents. - - @param context GPU context - @param image SkImage used for texture - @param backendTexture storage for back-end texture - @param backendTextureReleaseProc storage for clean up function - @return true if back-end texture was created - */ - static bool MakeBackendTextureFromSkImage(GrDirectContext* context, - sk_sp image, - GrBackendTexture* backendTexture, - BackendTextureReleaseProc* backendTextureReleaseProc); -#endif /** Deprecated. */ enum LegacyBitmapMode { @@ -1393,7 +1070,8 @@ class SK_API SkImage : public SkRefCnt { SkImage(const SkImageInfo& info, uint32_t uniqueID); friend class SkBitmap; - friend class SkImage_Base; + friend class SkImage_Base; // for private ctor + friend class SkImage_Raster; // for withMipmaps friend class SkMipmapBuilder; SkImageInfo fInfo; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h deleted file mode 100644 index be0183c094cba..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkImageEncoder_DEFINED -#define SkImageEncoder_DEFINED - -#include "include/core/SkEncodedImageFormat.h" -#include "include/core/SkRefCnt.h" -#include "include/core/SkTypes.h" - -class SkBitmap; -class SkData; -class SkPixmap; -class SkWStream; - -/** - * Encode SkPixmap in the given binary image format. - * - * @param dst results are written to this stream. - * @param src source pixels. - * @param format image format, not all formats are supported. - * @param quality range from 0-100, this is supported by jpeg and webp. - * higher values correspond to improved visual quality, but less compression. - * - * @return false iff input is bad or format is unsupported. - * - * Will always return false if Skia is compiled without image - * encoders. - * - * For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise - * it will use lossy. - * - * For examples of encoding an image to a file or to a block of memory, - * see tools/ToolUtils.h. - */ -SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src, - SkEncodedImageFormat format, int quality); - -/** - * The following helper function wraps SkEncodeImage(). - */ -SK_API bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q); - -/** - * Encode SkPixmap in the given binary image format. - * - * @param src source pixels. - * @param format image format, not all formats are supported. - * @param quality range from 0-100, this is supported by jpeg and webp. - * higher values correspond to improved visual quality, but less compression. - * - * @return encoded data or nullptr if input is bad or format is unsupported. - * - * Will always return nullptr if Skia is compiled without image - * encoders. - * - * For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise - * it will use lossy. - */ -SK_API sk_sp SkEncodePixmap(const SkPixmap& src, SkEncodedImageFormat format, int quality); - -/** - * Helper that extracts the pixmap from the bitmap, and then calls SkEncodePixmap() - */ -SK_API sk_sp SkEncodeBitmap(const SkBitmap& src, SkEncodedImageFormat format, int quality); - -#endif // SkImageEncoder_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h index 42125214e7167..ba9ae09833066 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h @@ -8,32 +8,25 @@ #ifndef SkImageGenerator_DEFINED #define SkImageGenerator_DEFINED -#include "include/core/SkBitmap.h" -#include "include/core/SkColor.h" -#include "include/core/SkImage.h" +#include "include/core/SkData.h" #include "include/core/SkImageInfo.h" -#include "include/core/SkSurfaceProps.h" +#include "include/core/SkPixmap.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkYUVAPixmaps.h" +#include "include/private/base/SkAPI.h" +#if defined(SK_GRAPHITE) +#include "include/core/SkImage.h" +#include "include/gpu/graphite/Recorder.h" +#endif + +#include +#include +#include #include class GrRecordingContext; -class GrSurfaceProxyView; -class GrSamplerState; -class SkBitmap; -class SkData; -class SkMatrix; -class SkPaint; -class SkPicture; - -enum class GrImageTexGenPolicy : int; - -#if SK_GRAPHITE_ENABLED -namespace skgpu::graphite { -enum class Mipmapped : bool; -class Recorder; -} -#endif +enum SkAlphaType : int; class SK_API SkImageGenerator { public: @@ -121,36 +114,12 @@ class SK_API SkImageGenerator { */ bool getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps); -#if SK_SUPPORT_GPU - /** - * If the generator can natively/efficiently return its pixels as a GPU image (backed by a - * texture) this will return that image. If not, this will return NULL. - * - * Regarding the GrRecordingContext parameter: - * - * It must be non-NULL. The generator should only succeed if: - * - its internal context is the same - * - it can somehow convert its texture into one that is valid for the provided context. - * - * If the mipmapped parameter is kYes, the generator should try to create a TextureProxy that - * at least has the mip levels allocated and the base layer filled in. If this is not possible, - * the generator is allowed to return a non mipped proxy, but this will have some additional - * overhead in later allocating mips and copying of the base layer. - * - * GrImageTexGenPolicy determines whether or not a new texture must be created (and its budget - * status) or whether this may (but is not required to) return a pre-existing texture that is - * retained by the generator (kDraw). - */ - GrSurfaceProxyView generateTexture(GrRecordingContext*, - const SkImageInfo& info, - GrMipmapped mipmapped, - GrImageTexGenPolicy); -#endif + virtual bool isTextureGenerator() const { return false; } -#if SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) sk_sp makeTextureImage(skgpu::graphite::Recorder*, const SkImageInfo&, - skgpu::graphite::Mipmapped); + skgpu::Mipmapped); #endif /** @@ -164,17 +133,6 @@ class SK_API SkImageGenerator { static std::unique_ptr MakeFromEncoded( sk_sp, std::optional = std::nullopt); - /** Return a new image generator backed by the specified picture. If the size is empty or - * the picture is NULL, this returns NULL. - * The optional matrix and paint arguments are passed to drawPicture() at rasterization - * time. - */ - static std::unique_ptr MakeFromPicture(const SkISize&, sk_sp, - const SkMatrix*, const SkPaint*, - SkImage::BitDepth, - sk_sp, - SkSurfaceProps props = {}); - protected: static constexpr int kNeedNewImageUniqueID = 0; @@ -187,30 +145,17 @@ class SK_API SkImageGenerator { virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes&, SkYUVAPixmapInfo*) const { return false; } virtual bool onGetYUVAPlanes(const SkYUVAPixmaps&) { return false; } -#if SK_SUPPORT_GPU - // returns nullptr - virtual GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&, - GrMipmapped, GrImageTexGenPolicy); - - // Most internal SkImageGenerators produce textures and views that use kTopLeft_GrSurfaceOrigin. - // If the generator may produce textures with different origins (e.g. - // GrAHardwareBufferImageGenerator) it should override this function to return the correct - // origin. - virtual GrSurfaceOrigin origin() const { return kTopLeft_GrSurfaceOrigin; } -#endif -#if SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) virtual sk_sp onMakeTextureImage(skgpu::graphite::Recorder*, const SkImageInfo&, - skgpu::graphite::Mipmapped); + skgpu::Mipmapped); #endif + const SkImageInfo fInfo; private: - const SkImageInfo fInfo; const uint32_t fUniqueID; - friend class SkImage_Lazy; - // This is our default impl, which may be different on different platforms. // It is called from NewFromEncoded() after it has checked for any runtime factory. // The SkData will never be NULL, as that will have been checked by NewFromEncoded. diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h index 9befe3071fb2b..b5661719006ef 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h @@ -10,16 +10,18 @@ #include "include/core/SkAlphaType.h" #include "include/core/SkColorType.h" -#include "include/core/SkMath.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkTFitsIn.h" -#include "include/private/SkTFitsIn.h" -#include "include/private/SkTo.h" +#include +#include +#include -class SkReadBuffer; -class SkWriteBuffer; class SkColorSpace; /** Returns the number of bytes required to store a pixel, including unused padding. diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h index 7fdbcb8e820d3..11a06a15b1a6d 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h @@ -99,6 +99,11 @@ struct SK_API SkV4 { } bool operator!=(const SkV4& v) const { return !(*this == v); } + static SkScalar Dot(const SkV4& a, const SkV4& b) { + return a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; + } + static SkV4 Normalize(const SkV4& v) { return v * (1.0f / v.length()); } + SkV4 operator-() const { return {-x, -y, -z, -w}; } SkV4 operator+(const SkV4& v) const { return { x + v.x, y + v.y, z + v.z, w + v.w }; } SkV4 operator-(const SkV4& v) const { return { x - v.x, y - v.y, z - v.z, w - v.w }; } @@ -111,6 +116,12 @@ struct SK_API SkV4 { } friend SkV4 operator*(SkScalar s, const SkV4& v) { return v*s; } + SkScalar lengthSquared() const { return Dot(*this, *this); } + SkScalar length() const { return SkScalarSqrt(Dot(*this, *this)); } + + SkScalar dot(const SkV4& v) const { return Dot(*this, v); } + SkV4 normalize() const { return Normalize(*this); } + const float* ptr() const { return &x; } float* ptr() { return &x; } diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h index 3fde51b717e53..9d03e98c0c5f8 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h @@ -8,12 +8,15 @@ #ifndef SkMaskFilter_DEFINED #define SkMaskFilter_DEFINED -#include "include/core/SkBlurTypes.h" -#include "include/core/SkCoverageMode.h" #include "include/core/SkFlattenable.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" -class SkMatrix; +#include + +enum SkBlurStyle : int; +struct SkDeserialProcs; struct SkRect; /** \class SkMaskFilter diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h index 03140760d6f2b..cf84d26228b60 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h @@ -8,12 +8,19 @@ #ifndef SkMatrix_DEFINED #define SkMatrix_DEFINED +#include "include/core/SkPoint.h" #include "include/core/SkRect.h" -#include "include/private/SkMacros.h" -#include "include/private/SkTo.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkMacros.h" +#include "include/private/base/SkTo.h" + +#include +#include -struct SkRSXform; struct SkPoint3; +struct SkRSXform; +struct SkSize; // Remove when clients are updated to live without this #define SK_SUPPORT_LEGACY_MATRIX_RECTTORECT @@ -1812,7 +1819,10 @@ class SK_API SkMatrix { if (tx != 0.0f || ty != 0.0f) { mask |= kTranslate_Mask; } - this->setTypeMask(mask | kRectStaysRect_Mask); + if (sx != 0 && sy != 0) { + mask |= kRectStaysRect_Mask; + } + this->setTypeMask(mask); } /** Returns true if all elements of the matrix are finite. Returns false if any diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h index f34672e3ab05e..360a039e7f531 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h @@ -19,6 +19,7 @@ #include "include/effects/SkRuntimeEffect.h" #include +#include #include class GrDirectContext; @@ -29,22 +30,31 @@ namespace SkSL { struct Program; } /** * A specification for custom meshes. Specifies the vertex buffer attributes and stride, the - * vertex program that produces a user-defined set of varyings, a fragment program that ingests - * the interpolated varyings and produces local coordinates and optionally a color. + * vertex program that produces a user-defined set of varyings, and a fragment program that ingests + * the interpolated varyings and produces local coordinates for shading and optionally a color. + * + * The varyings must include a float2 named "position". If the passed varyings does not + * contain such a varying then one is implicitly added to the final specification and the SkSL + * Varyings struct described below. It is an error to have a varying named "position" that has a + * type other than float2. + * + * The provided attributes and varyings are used to create Attributes and Varyings structs in SkSL + * that are used by the shaders. Each attribute from the Attribute span becomes a member of the + * SkSL Attributes struct and likewise for the varyings. * * The signature of the vertex program must be: - * float2 main(Attributes, out Varyings) - * where the return value is a local position that will be transformed by SkCanvas's matrix. + * Varyings main(const Attributes). * * The signature of the fragment program must be either: - * (float2|void) main(Varyings) + * float2 main(const Varyings) * or - * (float2|void) main(Varyings, out (half4|float4) color) + * float2 main(const Varyings, out (half4|float4) color) * * where the return value is the local coordinates that will be used to access SkShader. If the - * return type is void then the interpolated position from vertex shader return is used as the local - * coordinate. If the color variant is used it will be blended with SkShader (or SkPaint color in - * absence of a shader) using the SkBlender provided to the SkCanvas draw call. + * color variant is used, the returned color will be blended with SkPaint's SkShader (or SkPaint + * color in absence of a SkShader) using the SkBlender passed to SkCanvas drawMesh(). To use + * interpolated local space positions as the shader coordinates, equivalent to how SkPaths are + * shaded, return the position field from the Varying struct as the coordinates. * * The vertex and fragment programs may both contain uniforms. Uniforms with the same name are * assumed to be shared between stages. It is an error to specify uniforms in the vertex and @@ -187,11 +197,12 @@ class SkMeshSpecification : public SkNVRefCnt { SkMeshSpecification(SkSpan, size_t, SkSpan, + int passthroughLocalCoordsVaryingIndex, + uint32_t deadVaryingMask, std::vector uniforms, std::unique_ptr, std::unique_ptr, ColorType, - bool hasLocalCoords, sk_sp, SkAlphaType); @@ -208,8 +219,9 @@ class SkMeshSpecification : public SkNVRefCnt { const std::unique_ptr fFS; const size_t fStride; uint32_t fHash; + const int fPassthroughLocalCoordsVaryingIndex; + const uint32_t fDeadVaryingMask; const ColorType fColorType; - const bool fHasLocalCoords; const sk_sp fColorSpace; const SkAlphaType fAlphaType; }; @@ -295,8 +307,11 @@ class SkMesh { */ static sk_sp MakeIndexBuffer(GrDirectContext*, const void* data, size_t size); - /** Deprecated in favor of const void* and size_t version above. */ - static sk_sp MakeIndexBuffer(GrDirectContext*, sk_sp); + /** + * Makes a copy of an index buffer. The implementation currently only supports a CPU-backed + * source buffer. + */ + static sk_sp CopyIndexBuffer(GrDirectContext*, sk_sp); /** * Makes a vertex buffer to be used with SkMeshes. The buffer may be CPU- or GPU-backed @@ -313,12 +328,23 @@ class SkMesh { */ static sk_sp MakeVertexBuffer(GrDirectContext*, const void*, size_t size); - /** Deprecated in favor of const void* and size_t version above. */ - static sk_sp MakeVertexBuffer(GrDirectContext*, sk_sp); + /** + * Makes a copy of a vertex buffer. The implementation currently only supports a CPU-backed + * source buffer. + */ + static sk_sp CopyVertexBuffer(GrDirectContext*, sk_sp); enum class Mode { kTriangles, kTriangleStrip }; - static SkMesh Make(sk_sp, + struct Result; + + /** + * Creates a non-indexed SkMesh. The returned SkMesh can be tested for validity using + * SkMesh::isValid(). An invalid mesh simply fails to draws if passed to SkCanvas::drawMesh(). + * If the mesh is invalid the returned string give contain the reason for the failure (e.g. the + * vertex buffer was null or uniform data too small). + */ + static Result Make(sk_sp, Mode, sk_sp, size_t vertexCount, @@ -326,7 +352,13 @@ class SkMesh { sk_sp uniforms, const SkRect& bounds); - static SkMesh MakeIndexed(sk_sp, + /** + * Creates an indexed SkMesh. The returned SkMesh can be tested for validity using + * SkMesh::isValid(). A invalid mesh simply fails to draw if passed to SkCanvas::drawMesh(). + * If the mesh is invalid the returned string give contain the reason for the failure (e.g. the + * index buffer was null or uniform data too small). + */ + static Result MakeIndexed(sk_sp, Mode, sk_sp, size_t vertexCount, @@ -364,7 +396,7 @@ class SkMesh { private: friend struct SkMeshPriv; - bool validate() const; + std::tuple validate() const; sk_sp fSpec; @@ -384,6 +416,8 @@ class SkMesh { SkRect fBounds = SkRect::MakeEmpty(); }; +struct SkMesh::Result { SkMesh mesh; SkString error; }; + #endif // SK_ENABLE_SKSL #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h index a6c6bdf195e1f..398de57d0c59f 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h @@ -5,5 +5,5 @@ * found in the LICENSE file. */ #ifndef SK_MILESTONE -#define SK_MILESTONE 108 +#define SK_MILESTONE 114 #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h index d6c1d830c7ed3..157dbb59d8d6c 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h @@ -8,23 +8,28 @@ #ifndef SkPaint_DEFINED #define SkPaint_DEFINED -#include "include/core/SkBlendMode.h" #include "include/core/SkColor.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTo.h" - +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkFloatingPoint.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" + +#include #include +#include class SkBlender; class SkColorFilter; class SkColorSpace; -struct SkRect; class SkImageFilter; class SkMaskFilter; -class SkMatrix; -class SkPath; class SkPathEffect; class SkShader; +enum class SkBlendMode; +struct SkRect; /** \class SkPaint SkPaint controls options applied when drawing. SkPaint collects all @@ -383,34 +388,6 @@ class SK_API SkPaint { */ void setStrokeJoin(Join join); - /** Returns the filled equivalent of the stroked path. - - @param src SkPath read to create a filled version - @param dst resulting SkPath; may be the same as src, but may not be nullptr - @param cullRect optional limit passed to SkPathEffect - @param resScale if > 1, increase precision, else if (0 < resScale < 1) reduce precision - to favor speed and size - @return true if the path represents style fill, or false if it represents hairline - */ - bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect, - SkScalar resScale = 1) const; - - bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect, - const SkMatrix& ctm) const; - - /** Returns the filled equivalent of the stroked path. - - Replaces dst with the src path modified by SkPathEffect and style stroke. - SkPathEffect, if any, is not culled. stroke width is created with default precision. - - @param src SkPath read to create a filled version - @param dst resulting SkPath dst may be the same as src, but may not be nullptr - @return true if the path represents style fill, or false if it represents hairline - */ - bool getFillPath(const SkPath& src, SkPath* dst) const { - return this->getFillPath(src, dst, nullptr, 1); - } - /** Returns optional colors used when filling a path, such as a gradient. Does not alter SkShader SkRefCnt. diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h index fea6932e04035..0b69dd2b6fd95 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h @@ -10,20 +10,29 @@ #include "include/core/SkMatrix.h" #include "include/core/SkPathTypes.h" +#include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTo.h" - +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" + +#include +#include +#include #include #include +#include -class SkAutoPathBoundsUpdate; class SkData; class SkPathRef; class SkRRect; class SkWStream; - enum class SkPathConvexity; enum class SkPathFirstDirection; +struct SkPathVerbAnalysis; // WIP -- define this locally, and fix call-sites to use SkPathBuilder (skbug.com/9000) //#define SK_HIDE_PATH_EDIT_METHODS @@ -1866,6 +1875,16 @@ class SK_API SkPath { */ void shrinkToFit(); + // Creates a new Path after the supplied arguments have been validated by + // sk_path_analyze_verbs(). + static SkPath MakeInternal(const SkPathVerbAnalysis& analsis, + const SkPoint points[], + const uint8_t verbs[], + int verbCount, + const SkScalar conics[], + SkPathFillType fillType, + bool isVolatile); + friend class SkAutoPathBoundsUpdate; friend class SkAutoDisableOvalCheck; friend class SkAutoDisableDirectionCheck; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h index b52eaaaa96b0b..247c08624c554 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h @@ -8,11 +8,19 @@ #ifndef SkPathBuilder_DEFINED #define SkPathBuilder_DEFINED -#include "include/core/SkMatrix.h" #include "include/core/SkPath.h" #include "include/core/SkPathTypes.h" +#include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTDArray.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/SkPathRef.h" +#include "include/private/base/SkTo.h" + +#include + +class SkRRect; class SK_API SkPathBuilder { public: @@ -220,9 +228,9 @@ class SK_API SkPathBuilder { } private: - SkTDArray fPts; - SkTDArray fVerbs; - SkTDArray fConicWeights; + SkPathRef::PointsArray fPts; + SkPathRef::VerbsArray fVerbs; + SkPathRef::ConicWeightsArray fConicWeights; SkPathFillType fFillType; bool fIsVolatile; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h index 2335c7c23ce13..167b18278d923 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h @@ -10,7 +10,7 @@ #include "include/core/SkContourMeasure.h" #include "include/core/SkPath.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" class SK_API SkPathMeasure { public: diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h index f589ea46ce2e3..963a6bda00b00 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h @@ -8,8 +8,6 @@ #ifndef SkPathTypes_DEFINED #define SkPathTypes_DEFINED -#include "include/core/SkTypes.h" - enum class SkPathFillType { /** Specifies that "inside" is computed by a non-zero sum of signed edge crossings */ kWinding, diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h new file mode 100644 index 0000000000000..6285da7996033 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h @@ -0,0 +1,42 @@ +/* + * 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 SkPathUtils_DEFINED +#define SkPathUtils_DEFINED + +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" + +class SkMatrix; +class SkPaint; +class SkPath; +struct SkRect; + +namespace skpathutils { + +/** Returns the filled equivalent of the stroked path. + + @param src SkPath read to create a filled version + @param paint SkPaint, from which attributes such as stroke cap, width, miter, and join, + as well as pathEffect will be used. + @param dst resulting SkPath; may be the same as src, but may not be nullptr + @param cullRect optional limit passed to SkPathEffect + @param resScale if > 1, increase precision, else if (0 < resScale < 1) reduce precision + to favor speed and size + @return true if the dst path was updated, false if it was not (e.g. if the path + represents hairline and cannot be filled). +*/ +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, + const SkRect *cullRect, SkScalar resScale = 1); + +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, + const SkRect *cullRect, const SkMatrix &ctm); + +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst); + +} + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h index b6422dd56e3ee..bb384dfab1b8c 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h @@ -243,8 +243,9 @@ class SK_API SkPicture : public SkRefCnt { void serialize(SkWStream*, const SkSerialProcs*, class SkRefCntSet* typefaces, bool textBlobsOnly=false) const; - static sk_sp MakeFromStream(SkStream*, const SkDeserialProcs*, - class SkTypefacePlayback*); + static sk_sp MakeFromStreamPriv(SkStream*, const SkDeserialProcs*, + class SkTypefacePlayback*, + int recursionLimit); friend class SkPictureData; /** Return true if the SkStream/Buffer represents a serialized picture, and diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h index af3926dd25f0f..d91d105000ef0 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h @@ -12,6 +12,8 @@ #include "include/core/SkPicture.h" #include "include/core/SkRefCnt.h" +#include + #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK namespace android { class Picture; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h index ce25665b01a6a..12779890f8859 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h @@ -8,20 +8,16 @@ #ifndef SkPixelRef_DEFINED #define SkPixelRef_DEFINED -#include "include/core/SkBitmap.h" -#include "include/core/SkImageInfo.h" -#include "include/core/SkPixmap.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/private/SkIDChangeListener.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkTo.h" #include +#include +#include -struct SkIRect; - -class GrTexture; class SkDiscardableMemory; /** \class SkPixelRef diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h index 7bc2aa05ac73e..ad4c7dd6d8464 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h @@ -9,11 +9,21 @@ #define SkPixmap_DEFINED #include "include/core/SkColor.h" +#include "include/core/SkColorType.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkRect.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkSamplingOptions.h" +#include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" + +#include +#include class SkColorSpace; -class SkData; +enum SkAlphaType : int; struct SkMask; /** \class SkPixmap @@ -702,39 +712,21 @@ class SK_API SkPixmap { */ bool erase(SkColor color) const { return this->erase(color, this->bounds()); } - /** Writes color to pixels bounded by subset; returns true on success. - if subset is nullptr, writes colors pixels inside bounds(). Returns false if - colorType() is kUnknown_SkColorType, if subset is not nullptr and does - not intersect bounds(), or if subset is nullptr and bounds() is empty. - - @param color sRGB unpremultiplied color to write - @param subset bounding integer SkRect of pixels to write; may be nullptr - @return true if pixels are changed - - example: https://fiddle.skia.org/c/@Pixmap_erase_3 - */ - bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const { - return this->erase(color, nullptr, subset); - } - /** Writes color to pixels bounded by subset; returns true on success. if subset is nullptr, writes colors pixels inside bounds(). Returns false if colorType() is kUnknown_SkColorType, if subset is not nullptr and does not intersect bounds(), or if subset is nullptr and bounds() is empty. @param color unpremultiplied color to write - @param cs SkColorSpace of color @param subset bounding integer SkRect of pixels to write; may be nullptr @return true if pixels are changed */ - bool erase(const SkColor4f& color, SkColorSpace* cs, const SkIRect* subset = nullptr) const; + bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const; private: const void* fPixels; size_t fRowBytes; SkImageInfo fInfo; - - friend class SkPixmapPriv; }; #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h index 92cb0b7f09994..a5e7fa09fbab5 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h @@ -8,9 +8,11 @@ #ifndef SkPoint_DEFINED #define SkPoint_DEFINED -#include "include/core/SkMath.h" #include "include/core/SkScalar.h" -#include "include/private/SkSafe32.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkSafe32.h" + +#include struct SkIPoint; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h index 05434c0942517..0bd4034fdcda6 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h @@ -10,7 +10,7 @@ #include "include/core/SkTypes.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/core/SkRefCnt.h" #include "include/gpu/GrBackendSurface.h" /** @@ -41,6 +41,6 @@ class SK_API SkPromiseImageTexture : public SkNVRefCnt { GrBackendTexture fBackendTexture; }; -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) #endif // SkPromiseImageTexture_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h index 099385168ff73..73bc4a95b99ec 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h @@ -10,8 +10,12 @@ #include "include/core/SkPoint.h" #include "include/core/SkRect.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" + +#include +#include -class SkPath; class SkMatrix; class SkString; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h index 9467a331c3e19..1ed7823c23773 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h @@ -9,12 +9,15 @@ #define SkRect_DEFINED #include "include/core/SkPoint.h" +#include "include/core/SkScalar.h" #include "include/core/SkSize.h" -#include "include/private/SkSafe32.h" -#include "include/private/SkTFitsIn.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkSafe32.h" +#include "include/private/base/SkTFitsIn.h" +#include #include -#include +#include struct SkRect; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h index fc687b3840171..668de14e1d1af 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h @@ -9,14 +9,14 @@ #define SkRefCnt_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkDebug.h" -#include // std::atomic, std::memory_order_* -#include // std::nullptr_t -#include // std::basic_ostream -#include // TODO: unused -#include // std::enable_if, std::is_convertible -#include // std::forward, std::swap +#include +#include +#include +#include +#include +#include /** \class SkRefCntBase @@ -174,7 +174,7 @@ class SkNVRefCnt { bool unique() const { return 1 == fRefCnt.load(std::memory_order_acquire); } void ref() const { (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed); } - void unref() const { + void unref() const { if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) { // restore the 1 for our destructor's assert SkDEBUGCODE(fRefCnt.store(1, std::memory_order_relaxed)); @@ -217,12 +217,7 @@ class SkNVRefCnt { * may be considered as trivially relocatable by the compiler so that destroying-move operations * i.e. move constructor followed by destructor can be optimized to memcpy. */ -#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::trivial_abi) -#define SK_SP_TRIVIAL_ABI [[clang::trivial_abi]] -#else -#define SK_SP_TRIVIAL_ABI -#endif -template class SK_SP_TRIVIAL_ABI sk_sp { +template class SK_TRIVIAL_ABI sk_sp { public: using element_type = T; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h index 463a39ff36d54..6f8aa25d54282 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h @@ -9,7 +9,7 @@ #define SkRegion_DEFINED #include "include/core/SkRect.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTypeTraits.h" class SkPath; class SkRgnBuilder; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h index 2a6bb3ec361ef..f3e11b34c2504 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h @@ -8,10 +8,8 @@ #ifndef SkScalar_DEFINED #define SkScalar_DEFINED -#include "include/private/SkFloatingPoint.h" - -#undef SK_SCALAR_IS_FLOAT -#define SK_SCALAR_IS_FLOAT 1 +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkFloatingPoint.h" typedef float SkScalar; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h index 87e10d847ce6c..a9a0386370cd9 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h @@ -8,9 +8,15 @@ #ifndef SkSerialProcs_DEFINED #define SkSerialProcs_DEFINED -#include "include/core/SkImage.h" -#include "include/core/SkPicture.h" -#include "include/core/SkTypeface.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" + +#include + +class SkData; +class SkImage; +class SkPicture; +class SkTypeface; /** * A serial-proc is asked to serialize the specified object (e.g. picture or image). @@ -22,30 +28,32 @@ * The default action for typefaces is to use Skia's internal format. */ -typedef sk_sp (*SkSerialPictureProc)(SkPicture*, void* ctx); -typedef sk_sp (*SkSerialImageProc)(SkImage*, void* ctx); -typedef sk_sp (*SkSerialTypefaceProc)(SkTypeface*, void* ctx); +using SkSerialPictureProc = sk_sp (*)(SkPicture*, void* ctx); +using SkSerialImageProc = sk_sp (*)(SkImage*, void* ctx); +using SkSerialTypefaceProc = sk_sp (*)(SkTypeface*, void* ctx); /** * Called with the encoded form of a picture (previously written with a custom * SkSerialPictureProc proc). Return a picture object, or nullptr indicating failure. */ -typedef sk_sp (*SkDeserialPictureProc)(const void* data, size_t length, void* ctx); +using SkDeserialPictureProc = sk_sp (*)(const void* data, size_t length, void* ctx); /** - * Called with the encoded from of an image. The proc can return an image object, or if it + * Called with the encoded form of an image. The proc can return an image object, or if it * returns nullptr, then Skia will take its default action to try to create an image from the data. * + * This will also be used to decode the internal mipmap layers that are saved on some images. + * * Note that unlike SkDeserialPictureProc and SkDeserialTypefaceProc, return nullptr from this * does not indicate failure, but is a signal for Skia to take its default action. */ -typedef sk_sp (*SkDeserialImageProc)(const void* data, size_t length, void* ctx); +using SkDeserialImageProc = sk_sp (*)(const void* data, size_t length, void* ctx); /** * Called with the encoded form of a typeface (previously written with a custom * SkSerialTypefaceProc proc). Return a typeface object, or nullptr indicating failure. */ -typedef sk_sp (*SkDeserialTypefaceProc)(const void* data, size_t length, void* ctx); +using SkDeserialTypefaceProc = sk_sp (*)(const void* data, size_t length, void* ctx); struct SK_API SkSerialProcs { SkSerialPictureProc fPictureProc = nullptr; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h index 1c05c6238cb59..be42a87b9a9c6 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h @@ -56,69 +56,6 @@ class SK_API SkShader : public SkFlattenable { return this->isAImage(nullptr, (SkTileMode*)nullptr) != nullptr; } - // TODO(skbug.com/8941): Have Android use SkAndroidFrameworkUtils, move types to SkShaderBase, - // and delete asAGradient(). -#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK -private: -#endif - - /** - * If the shader subclass can be represented as a gradient, asAGradient - * returns the matching GradientType enum (or kNone_GradientType if it - * cannot). Also, if info is not null, asAGradient populates info with - * the relevant (see below) parameters for the gradient. fColorCount - * is both an input and output parameter. On input, it indicates how - * many entries in fColors and fColorOffsets can be used, if they are - * non-NULL. After asAGradient has run, fColorCount indicates how - * many color-offset pairs there are in the gradient. If there is - * insufficient space to store all of the color-offset pairs, fColors - * and fColorOffsets will not be altered. fColorOffsets specifies - * where on the range of 0 to 1 to transition to the given color. - * The meaning of fPoint and fRadius is dependant on the type of gradient. - * - * None: - * info is ignored. - * Color: - * fColorOffsets[0] is meaningless. - * Linear: - * fPoint[0] and fPoint[1] are the end-points of the gradient - * Radial: - * fPoint[0] and fRadius[0] are the center and radius - * Conical: - * fPoint[0] and fRadius[0] are the center and radius of the 1st circle - * fPoint[1] and fRadius[1] are the center and radius of the 2nd circle - * Sweep: - * fPoint[0] is the center of the sweep. - */ - - enum GradientType { - kNone_GradientType, - kColor_GradientType, - kLinear_GradientType, - kRadial_GradientType, - kSweep_GradientType, - kConical_GradientType, - }; - - struct GradientInfo { - int fColorCount = 0; //!< In-out parameter, specifies passed size - // of fColors/fColorOffsets on input, and - // actual number of colors/offsets on - // output. - SkColor* fColors = nullptr; //!< The colors in the gradient. - SkScalar* fColorOffsets = nullptr; //!< The unit offset for color transitions. - SkPoint fPoint[2]; //!< Type specific, see above. - SkScalar fRadius[2]; //!< Type specific, see above. - SkTileMode fTileMode; - uint32_t fGradientFlags = 0; //!< see SkGradientShader::Flags - }; - - GradientType asAGradient(GradientInfo* info) const; - -#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK -public: -#endif - ////////////////////////////////////////////////////////////////////////// // Methods to create combinations or variants of shaders @@ -148,7 +85,7 @@ class SK_API SkShaders { static sk_sp Color(const SkColor4f&, sk_sp); static sk_sp Blend(SkBlendMode mode, sk_sp dst, sk_sp src); static sk_sp Blend(sk_sp, sk_sp dst, sk_sp src); - + static sk_sp CoordClamp(sk_sp, const SkRect& subset); private: SkShaders() = delete; }; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h index 79d673775e8d1..867f4eeb97b90 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h @@ -10,6 +10,8 @@ #include "include/core/SkScalar.h" +#include + struct SkISize { int32_t fWidth; int32_t fHeight; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h index 03eb3b5b0fb66..37cac632b1e8d 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h @@ -5,117 +5,9 @@ * found in the LICENSE file. */ -#ifndef SkSpan_DEFINED -#define SkSpan_DEFINED +// We want SkSpan to be a public API, but it is also fundamental to many of our internal types. +// Thus, we have a public file that clients can include. This file defers to the private copy +// so we do not have a dependency cycle from our "base" files to our "core" files. -#include -#include -#include -#include -#include -#include "include/private/SkTLogic.h" +#include "include/private/base/SkSpan_impl.h" // IWYU pragma: export -// Add macro to check the lifetime of initializer_list arguments. initializer_list has a very -// short life span, and can only be used as a parameter, and not as a variable. -#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::lifetimebound) -#define SK_CHECK_IL_LIFETIME [[clang::lifetimebound]] -#else -#define SK_CHECK_IL_LIFETIME -#endif - -/** - * SkSpan holds a reference to contiguous data of type T along with a count. SkSpan does not own - * the data itself but is merely a reference, therefore you must take care with the lifetime of - * the underlying data. - * - * SkSpan is a count and a pointer into existing array or data type that stores its data in - * contiguous memory like std::vector. Any container that works with std::size() and std::data() - * can be used. - * - * SkSpan makes a convenient parameter for a routine to accept array like things. This allows you to - * write the routine without overloads for all different container types. - * - * Example: - * void routine(SkSpan a) { ... } - * - * std::vector v = {1, 2, 3, 4, 5}; - * - * routine(a); - * - * A word of caution when working with initializer_list, initializer_lists have a lifetime that is - * limited to the current statement. The following is correct and safe: - * - * Example: - * routine({1,2,3,4,5}); - * - * The following is undefined, and will result in erratic execution: - * - * Bad Example: - * initializer_list l = {1, 2, 3, 4, 5}; // The data behind l dies at the ;. - * routine(l); - */ -template -class SkSpan { -public: - constexpr SkSpan() : fPtr{nullptr}, fSize{0} {} - constexpr SkSpan(T* ptr, size_t size) : fPtr{ptr}, fSize{size} { - SkASSERT(ptr || size == 0); // disallow nullptr + a nonzero size - SkASSERT(size < kMaxSize); - } - template ::value>::type> - constexpr SkSpan(const SkSpan& that) : fPtr(std::data(that)), fSize{std::size(that)} {} - constexpr SkSpan(const SkSpan& o) = default; - template constexpr SkSpan(T(&a)[N]) : SkSpan(a, N) { } - template - constexpr SkSpan(Container& c) : SkSpan{std::data(c), std::size(c)} { } - SkSpan(std::initializer_list il SK_CHECK_IL_LIFETIME) - : SkSpan(std::data(il), std::size(il)) {} - - constexpr SkSpan& operator=(const SkSpan& that) = default; - - constexpr T& operator [] (size_t i) const { - SkASSERT(i < this->size()); - return fPtr[i]; - } - constexpr T& front() const { return fPtr[0]; } - constexpr T& back() const { return fPtr[fSize - 1]; } - constexpr T* begin() const { return fPtr; } - constexpr T* end() const { return fPtr + fSize; } - constexpr auto rbegin() const { return std::make_reverse_iterator(this->end()); } - constexpr auto rend() const { return std::make_reverse_iterator(this->begin()); } - constexpr T* data() const { return this->begin(); } - constexpr size_t size() const { return fSize; } - constexpr bool empty() const { return fSize == 0; } - constexpr size_t size_bytes() const { return fSize * sizeof(T); } - constexpr SkSpan first(size_t prefixLen) const { - SkASSERT(prefixLen <= this->size()); - return SkSpan{fPtr, prefixLen}; - } - constexpr SkSpan last(size_t postfixLen) const { - SkASSERT(postfixLen <= this->size()); - return SkSpan{fPtr + (this->size() - postfixLen), postfixLen}; - } - constexpr SkSpan subspan(size_t offset) const { - return this->subspan(offset, this->size() - offset); - } - constexpr SkSpan subspan(size_t offset, size_t count) const { - SkASSERT(offset <= this->size()); - SkASSERT(count <= this->size() - offset); - return SkSpan{fPtr + offset, count}; - } - -private: - static const constexpr size_t kMaxSize = std::numeric_limits::max() / sizeof(T); - T* fPtr; - size_t fSize; -}; - -template -SkSpan(Container&) -> - SkSpan()))>>; - -template -SkSpan(std::initializer_list) -> - SkSpan>()))>>; - -#endif // SkSpan_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h index 768de9b5a33d0..c582c80a0528c 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h @@ -11,15 +11,16 @@ #include "include/core/SkData.h" #include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" -#include "include/private/SkTo.h" - -#include - -class SkStream; -class SkStreamRewindable; -class SkStreamSeekable; +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkTo.h" + +#include +#include +#include +#include +#include class SkStreamAsset; -class SkStreamMemory; /** * SkStream -- abstraction for a source of bytes. Subclasses can be backed by @@ -255,10 +256,10 @@ class SK_API SkWStream { bool writeText(const char text[]) { SkASSERT(text); - return this->write(text, strlen(text)); + return this->write(text, std::strlen(text)); } - bool newline() { return this->write("\n", strlen("\n")); } + bool newline() { return this->write("\n", std::strlen("\n")); } bool writeDecAsText(int32_t); bool writeBigDecAsText(int64_t, int minDigits = 0); @@ -296,8 +297,6 @@ class SK_API SkNullWStream : public SkWStream { //////////////////////////////////////////////////////////////////////////////////////// -#include - /** A stream that wraps a C FILE* file stream. */ class SK_API SkFILEStream : public SkStreamAsset { public: diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkString.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkString.h index e659910c6f00e..1b27fbf44b07c 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkString.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkString.h @@ -11,15 +11,16 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" -#include -#include #include +#include +#include +#include #include #include +#include /* Some helper functions for C strings */ static inline bool SkStrStartsWith(const char string[], const char prefixStr[]) { @@ -128,6 +129,7 @@ class SK_API SkString { bool isEmpty() const { return 0 == fRec->fLength; } size_t size() const { return (size_t) fRec->fLength; } + const char* data() const { return fRec->data(); } const char* c_str() const { return fRec->data(); } char operator[](size_t n) const { return this->c_str()[n]; } @@ -173,8 +175,8 @@ class SK_API SkString { SkString& operator=(SkString&&); SkString& operator=(const char text[]); - char* writable_str(); - char& operator[](size_t n) { return this->writable_str()[n]; } + char* data(); + char& operator[](size_t n) { return this->data()[n]; } void reset(); /** String contents are preserved on resize. (For destructive resize, `set(nullptr, length)`.) @@ -286,22 +288,4 @@ static inline void swap(SkString& a, SkString& b) { a.swap(b); } -enum SkStrSplitMode { - // Strictly return all results. If the input is ",," and the separator is ',' this will return - // an array of three empty strings. - kStrict_SkStrSplitMode, - - // Only nonempty results will be added to the results. Multiple separators will be - // coalesced. Separators at the beginning and end of the input will be ignored. If the input is - // ",," and the separator is ',', this will return an empty vector. - kCoalesce_SkStrSplitMode -}; - -// Split str on any characters in delimiters into out. (Think, strtok with a sane API.) -void SkStrSplit(const char* str, const char* delimiters, SkStrSplitMode splitMode, - SkTArray* out); -inline void SkStrSplit(const char* str, const char* delimiters, SkTArray* out) { - SkStrSplit(str, delimiters, kCoalesce_SkStrSplitMode, out); -} - #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h index b4796fcbfa6ca..1257d04a844b7 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h @@ -9,7 +9,7 @@ #define SkStrokeRec_DEFINED #include "include/core/SkPaint.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" class SkPath; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h index 98dcfdefcb3db..3673d172b6d02 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h @@ -9,41 +9,61 @@ #define SkSurface_DEFINED #include "include/core/SkImage.h" +#include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkSamplingOptions.h" +#include "include/core/SkScalar.h" #include "include/core/SkSurfaceProps.h" +#include "include/core/SkTypes.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrTypes.h" +#else +enum GrSurfaceOrigin: int; +#endif + +#if defined(SK_GRAPHITE) +#include "include/gpu/GpuTypes.h" +namespace skgpu::graphite { +class BackendTexture; +} #endif #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 #include +class GrDirectContext; #endif -#if SK_SUPPORT_GPU && defined(SK_METAL) +#if defined(SK_GANESH) && defined(SK_METAL) #include "include/gpu/mtl/GrMtlTypes.h" #endif +#include +#include +#include + +class GrBackendRenderTarget; +class GrBackendSemaphore; +class GrBackendTexture; +class GrRecordingContext; +class SkBitmap; class SkCanvas; class SkCapabilities; +class SkColorSpace; class SkDeferredDisplayList; class SkPaint; class SkSurfaceCharacterization; -class GrBackendRenderTarget; -class GrBackendSemaphore; -class GrBackendTexture; -class GrDirectContext; -class GrRecordingContext; -class GrRenderTarget; -enum GrSurfaceOrigin: int; +enum SkColorType : int; +struct SkIRect; +struct SkISize; namespace skgpu { class MutableTextureState; +enum class Budgeted : bool; } namespace skgpu::graphite { -class BackendTexture; class Recorder; } @@ -206,7 +226,7 @@ class SK_API SkSurface : public SkRefCnt { backend API (accounting only for use of the texture by this surface). If SkSurface creation fails textureReleaseProc is called before this function returns. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param backendTexture texture residing on GPU @@ -241,7 +261,7 @@ class SK_API SkSurface : public SkRefCnt { backend API (accounting only for use of the render target by this surface). If SkSurface creation fails releaseProc is called before this function returns. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param backendRenderTarget GPU intermediate memory buffer @@ -276,7 +296,7 @@ class SK_API SkSurface : public SkRefCnt { shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace; @@ -287,9 +307,11 @@ class SK_API SkSurface : public SkRefCnt { @param shouldCreateWithMips hint that SkSurface will host mip map images @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, const SkImageInfo& imageInfo, - int sampleCount, GrSurfaceOrigin surfaceOrigin, + int sampleCount, + GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps* surfaceProps, bool shouldCreateWithMips = false); @@ -314,10 +336,12 @@ class SK_API SkSurface : public SkRefCnt { fonts; may be nullptr @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, - const SkImageInfo& imageInfo, int sampleCount, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, + const SkImageInfo& imageInfo, + int sampleCount, const SkSurfaceProps* surfaceProps) { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) return MakeRenderTarget(context, budgeted, imageInfo, sampleCount, kBottomLeft_GrSurfaceOrigin, surfaceProps); #else @@ -339,9 +363,10 @@ class SK_API SkSurface : public SkRefCnt { of raster surface; width, or height, or both, may be zero @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, const SkImageInfo& imageInfo) { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) if (!imageInfo.width() || !imageInfo.height()) { return nullptr; } @@ -362,8 +387,7 @@ class SK_API SkSurface : public SkRefCnt { */ static sk_sp MakeRenderTarget(GrRecordingContext* context, const SkSurfaceCharacterization& characterization, - SkBudgeted budgeted); - + skgpu::Budgeted budgeted); #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 /** Private. @@ -398,7 +422,7 @@ class SK_API SkSurface : public SkRefCnt { ); #endif -#ifdef SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) /** * In Graphite, while clients hold a ref on an SkSurface, the backing gpu object does _not_ * count against the budget. Once an SkSurface is freed, the backing gpu object may or may @@ -408,7 +432,7 @@ class SK_API SkSurface : public SkRefCnt { static sk_sp MakeGraphite( skgpu::graphite::Recorder*, const SkImageInfo& imageInfo, - skgpu::graphite::Mipmapped = skgpu::graphite::Mipmapped::kNo, + skgpu::Mipmapped = skgpu::Mipmapped::kNo, const SkSurfaceProps* surfaceProps = nullptr); /** @@ -430,9 +454,9 @@ class SK_API SkSurface : public SkRefCnt { sk_sp colorSpace, const SkSurfaceProps* props); -#endif // SK_GRAPHITE_ENABLED +#endif // SK_GRAPHITE -#if SK_SUPPORT_GPU && defined(SK_METAL) +#if defined(SK_GANESH) && defined(SK_METAL) /** Creates SkSurface from CAMetalLayer. Returned SkSurface takes a reference on the CAMetalLayer. The ref on the layer will be released when the SkSurface is destroyed. @@ -525,7 +549,7 @@ class SK_API SkSurface : public SkRefCnt { /** Returns an ImageInfo describing the surface. */ - SkImageInfo imageInfo(); + virtual SkImageInfo imageInfo() const { return SkImageInfo::MakeUnknown(fWidth, fHeight); } /** Returns unique value identifying the content of SkSurface. Returned value changes each time the content changes. Content is changed by drawing, or by calling @@ -566,7 +590,7 @@ class SK_API SkSurface : public SkRefCnt { */ skgpu::graphite::Recorder* recorder(); -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) enum BackendHandleAccess { kFlushRead_BackendHandleAccess, //!< back-end object is readable kFlushWrite_BackendHandleAccess, //!< back-end object is writable @@ -669,7 +693,7 @@ class SK_API SkSurface : public SkRefCnt { /** Returns SkImage capturing SkSurface contents. Subsequent drawing to SkSurface contents are not captured. SkImage allocation is accounted for if SkSurface was created with - SkBudgeted::kYes. + skgpu::Budgeted::kYes. @return SkImage initialized with SkSurface contents @@ -690,6 +714,34 @@ class SK_API SkSurface : public SkRefCnt { */ sk_sp makeImageSnapshot(const SkIRect& bounds); +#if defined(SK_GRAPHITE) + /** + * The 'asImage' and 'makeImageCopy' API/entry points are currently only available for + * Graphite. + * + * In this API, SkSurface no longer supports copy-on-write behavior. Instead, when creating + * an image for a surface, the client must explicitly indicate if a copy should be made. + * In both of the below calls the resource backing the surface will never change. + * + * The 'asImage' entry point has some major ramifications for the mutability of the + * returned SkImage. Since the originating surface and the returned image share the + * same backing, care must be taken by the client to ensure that the contents of the image + * reflect the desired contents when it is consumed by the gpu. + * Note: if the backing GPU buffer isn't textureable this method will return null. Graphite + * will not attempt to make a copy. + * Note: For 'asImage', the mipmapping of the image will match that of the source surface. + * + * The 'makeImageCopy' entry point allows subsetting and the addition of mipmaps (since + * a copy is already being made). + * + * In Graphite, the legacy API call (i.e., makeImageSnapshot) will just always make a copy. + */ + sk_sp asImage(); + + sk_sp makeImageCopy(const SkIRect* subset = nullptr, + skgpu::Mipmapped mipmapped = skgpu::Mipmapped::kNo); +#endif + /** Draws SkSurface contents to canvas, with its top-left corner at (x, y). If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter, and SkBlendMode. @@ -834,36 +886,6 @@ class SK_API SkSurface : public SkRefCnt { using RescaleGamma = SkImage::RescaleGamma; using RescaleMode = SkImage::RescaleMode; - /** Makes surface pixel data available to caller, possibly asynchronously. - - Currently asynchronous reads are only supported on the GPU backend and only when the - underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all - other cases this operates synchronously. - - Data is read from the source sub-rectangle, then converted to the color space, color type, - and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the surface - causes failure. - - When the pixel data is ready the caller's ReadPixelsCallback is called with a - AsyncReadResult containing pixel data in the requested color type, alpha type, and color - space. The AsyncReadResult will have count() == 1. Upon failure the callback is called - with nullptr for AsyncReadResult. For a GPU surface this flushes work but a submit must - occur to guarantee a finite time before the callback is called. - - The data is valid for the lifetime of AsyncReadResult with the exception that if the - SkSurface is GPU-backed the data is immediately invalidated if the context is abandoned - or destroyed. - - @param info info of the requested pixels - @param srcRect subrectangle of surface to read - @param callback function to call with result of the read - @param context passed to callback - */ - void asyncReadPixels(const SkImageInfo& info, - const SkIRect& srcRect, - ReadPixelsCallback callback, - ReadPixelsContext context); - /** Makes surface pixel data available to caller, possibly asynchronously. It can also rescale the surface pixels. @@ -994,7 +1016,7 @@ class SK_API SkSurface : public SkRefCnt { kPresent, //!< back-end surface will be used for presenting to screen }; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** If a surface is GPU texture backed, is being drawn with MSAA, and there is a resolve texture, this call will insert a resolve command into the stream of gpu commands. In order for the resolve to actually have an effect, the work still needs to be flushed and submitted @@ -1100,7 +1122,7 @@ class SK_API SkSurface : public SkRefCnt { */ GrSemaphoresSubmitted flush(const GrFlushInfo& info, const skgpu::MutableTextureState* newState = nullptr); -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) void flush(); diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h index 91b10e87bf7a9..0b65a10d03c4b 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h @@ -17,7 +17,7 @@ class SkColorSpace; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrContextThreadSafeProxy.h" #include "include/gpu/GrTypes.h" @@ -118,7 +118,7 @@ class SK_API SkSurfaceCharacterization { bool isCompatible(const GrBackendTexture&) const; private: - friend class SkSurface_Gpu; // for 'set' & 'config' + friend class SkSurface_Ganesh; // for 'set' & 'config' friend class GrVkSecondaryCBDrawContext; // for 'set' & 'config' friend class GrContextThreadSafeProxy; // for private ctor friend class SkDeferredDisplayListRecorder; // for 'config' @@ -210,7 +210,7 @@ class SK_API SkSurfaceCharacterization { SkSurfaceProps fSurfaceProps; }; -#else// !SK_SUPPORT_GPU +#else// !defined(SK_GANESH) class GrBackendFormat; class SK_API SkSurfaceCharacterization { diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h index 7b07554e5be34..4790f258e4ad5 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h @@ -9,6 +9,7 @@ #define SkSurfaceProps_DEFINED #include "include/core/SkTypes.h" +#include "include/private/base/SkTo.h" /** * Description of how the LCD strips are arranged for each pixel. If this is unknown, or the @@ -53,7 +54,10 @@ class SK_API SkSurfaceProps { enum Flags { kUseDeviceIndependentFonts_Flag = 1 << 0, // Use internal MSAA to render to non-MSAA GPU surfaces. - kDynamicMSAA_Flag = 1 << 1 + kDynamicMSAA_Flag = 1 << 1, + // If set, all rendering will have dithering enabled + // Currently this only impacts GPU backends + kAlwaysDither_Flag = 1 << 2, }; /** Deprecated alias used by Chromium. Will be removed. */ static const Flags kUseDistanceFieldFonts_Flag = kUseDeviceIndependentFonts_Flag; @@ -76,6 +80,10 @@ class SK_API SkSurfaceProps { return SkToBool(fFlags & kUseDeviceIndependentFonts_Flag); } + bool isAlwaysDither() const { + return SkToBool(fFlags & kAlwaysDither_Flag); + } + bool operator==(const SkSurfaceProps& that) const { return fFlags == that.fFlags && fPixelGeometry == that.fPixelGeometry; } diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h index e010ea9cc788d..8f6cb01c045ff 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h @@ -12,7 +12,7 @@ #include "include/core/SkPaint.h" #include "include/core/SkRefCnt.h" #include "include/core/SkString.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include @@ -491,7 +491,7 @@ class SK_API SkTextBlobBuilder { friend class SkTextBlobPriv; friend class SkTextBlobBuilderPriv; - SkAutoTMalloc fStorage; + skia_private::AutoTMalloc fStorage; size_t fStorageSize; size_t fStorageUsed; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h new file mode 100644 index 0000000000000..e9b441378d0c4 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h @@ -0,0 +1,30 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkTextureCompressionType_DEFINED +#define SkTextureCompressionType_DEFINED +/* + * Skia | GL_COMPRESSED_* | MTLPixelFormat* | VK_FORMAT_*_BLOCK + * -------------------------------------------------------------------------------------- + * kETC2_RGB8_UNORM | ETC1_RGB8 | ETC2_RGB8 (iOS-only) | ETC2_R8G8B8_UNORM + * | RGB8_ETC2 | | + * -------------------------------------------------------------------------------------- + * kBC1_RGB8_UNORM | RGB_S3TC_DXT1_EXT | N/A | BC1_RGB_UNORM + * -------------------------------------------------------------------------------------- + * kBC1_RGBA8_UNORM | RGBA_S3TC_DXT1_EXT | BC1_RGBA (macOS-only)| BC1_RGBA_UNORM + */ +enum class SkTextureCompressionType { + kNone, + kETC2_RGB8_UNORM, + + kBC1_RGB8_UNORM, + kBC1_RGBA8_UNORM, + kLast = kBC1_RGBA8_UNORM, + kETC1_RGB8 = kETC2_RGB8_UNORM, +}; + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h index 3da2c8c7715b9..9135c7e113c0d 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h @@ -11,7 +11,7 @@ #define SkTime_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" #include diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h index d4a13877152d3..9e099d41e37f5 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h @@ -14,8 +14,8 @@ #include "include/core/SkFontTypes.h" #include "include/core/SkRect.h" #include "include/core/SkString.h" -#include "include/private/SkOnce.h" #include "include/private/SkWeakRefCnt.h" +#include "include/private/base/SkOnce.h" class SkData; class SkDescriptor; @@ -360,6 +360,12 @@ class SK_API SkTypeface : public SkWeakRefCnt { return this->onGetCTFontRef(); } + /* Skia reserves all tags that begin with a lower case letter and 0 */ + using FactoryId = SkFourByteTag; + static void Register( + FactoryId id, + sk_sp (*make)(std::unique_ptr, const SkFontArguments&)); + protected: explicit SkTypeface(const SkFontStyle& style, bool isFixedPitch = false); ~SkTypeface() override; @@ -435,7 +441,8 @@ class SK_API SkTypeface : public SkWeakRefCnt { * typefaces that contain a COLR table. */ bool glyphMaskNeedsCurrentColor() const; - friend class SkStrikeServerImpl; // glyphMaskNeedsCurrentColor + friend class SkStrikeServerImpl; // glyphMaskNeedsCurrentColor + friend class SkTypefaceProxyPrototype; // glyphMaskNeedsCurrentColor /** Retrieve detailed typeface metrics. Used by the PDF backend. */ std::unique_ptr getAdvancedMetrics() const; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h index 8f7a2c0982b68..5530cc4463b39 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h @@ -8,235 +8,25 @@ #ifndef SkTypes_DEFINED #define SkTypes_DEFINED -/** \file SkTypes.h -*/ - -// Pre-SkUserConfig.h setup. - -// Allows embedders that want to disable macros that take arguments to just -// define that symbol to be one of these -#define SK_NOTHING_ARG1(arg1) -#define SK_NOTHING_ARG2(arg1, arg2) -#define SK_NOTHING_ARG3(arg1, arg2, arg3) - -#if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && \ - !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) - - #ifdef __APPLE__ - #include - #endif - - #if defined(_WIN32) || defined(__SYMBIAN32__) - #define SK_BUILD_FOR_WIN - #elif defined(ANDROID) || defined(__ANDROID__) - #define SK_BUILD_FOR_ANDROID - #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || \ - defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || \ - defined(__DragonFly__) || defined(__Fuchsia__) || \ - defined(__GLIBC__) || defined(__GNU__) || defined(__unix__) - #define SK_BUILD_FOR_UNIX - #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR - #define SK_BUILD_FOR_IOS - #else - #define SK_BUILD_FOR_MAC - #endif - -#endif - -#if defined(SK_BUILD_FOR_WIN) && !defined(__clang__) - #if !defined(SK_RESTRICT) - #define SK_RESTRICT __restrict - #endif - #if !defined(SK_WARN_UNUSED_RESULT) - #define SK_WARN_UNUSED_RESULT - #endif -#endif - -#if !defined(SK_RESTRICT) - #define SK_RESTRICT __restrict__ -#endif - -#if !defined(SK_WARN_UNUSED_RESULT) - #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#endif - -#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) - #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) - #define SK_CPU_BENDIAN - #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) - #define SK_CPU_LENDIAN - #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ - defined(__PPC__) || defined(__PPC64__) || \ - defined(_MIPSEB) || defined(__ARMEB__) || \ - defined(__s390__) || \ - (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ - (defined(__ia64) && defined(__BIG_ENDIAN__)) - #define SK_CPU_BENDIAN - #else - #define SK_CPU_LENDIAN - #endif -#endif - -#if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) - #define SK_CPU_X86 1 -#endif - -/** - * SK_CPU_SSE_LEVEL - * - * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. - * On non-intel CPU this should be undefined. - */ -#define SK_CPU_SSE_LEVEL_SSE1 10 -#define SK_CPU_SSE_LEVEL_SSE2 20 -#define SK_CPU_SSE_LEVEL_SSE3 30 -#define SK_CPU_SSE_LEVEL_SSSE3 31 -#define SK_CPU_SSE_LEVEL_SSE41 41 -#define SK_CPU_SSE_LEVEL_SSE42 42 -#define SK_CPU_SSE_LEVEL_AVX 51 -#define SK_CPU_SSE_LEVEL_AVX2 52 -#define SK_CPU_SSE_LEVEL_SKX 60 - -// Are we in GCC/Clang? -#ifndef SK_CPU_SSE_LEVEL - // These checks must be done in descending order to ensure we set the highest - // available SSE level. - #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ - defined(__AVX512BW__) && defined(__AVX512VL__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX - #elif defined(__AVX2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 - #elif defined(__AVX__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX - #elif defined(__SSE4_2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42 - #elif defined(__SSE4_1__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41 - #elif defined(__SSSE3__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 - #elif defined(__SSE3__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 - #elif defined(__SSE2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #endif -#endif - -// Are we in VisualStudio? -#ifndef SK_CPU_SSE_LEVEL - // These checks must be done in descending order to ensure we set the highest - // available SSE level. 64-bit intel guarantees at least SSE2 support. - #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ - defined(__AVX512BW__) && defined(__AVX512VL__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX - #elif defined(__AVX2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 - #elif defined(__AVX__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX - #elif defined(_M_X64) || defined(_M_AMD64) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #elif defined(_M_IX86_FP) - #if _M_IX86_FP >= 2 - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #elif _M_IX86_FP == 1 - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 - #endif - #endif -#endif - -// ARM defines -#if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) - #define SK_CPU_ARM32 -#elif defined(__aarch64__) - #define SK_CPU_ARM64 -#endif - -// All 64-bit ARM chips have NEON. Many 32-bit ARM chips do too. -#if !defined(SK_ARM_HAS_NEON) && defined(__ARM_NEON) - #define SK_ARM_HAS_NEON -#endif - -#if defined(__ARM_FEATURE_CRC32) - #define SK_ARM_HAS_CRC32 -#endif - - -// DLL/.so exports. -#if !defined(SKIA_IMPLEMENTATION) - #define SKIA_IMPLEMENTATION 0 -#endif -#if !defined(SK_API) - #if defined(SKIA_DLL) - #if defined(_MSC_VER) - #if SKIA_IMPLEMENTATION - #define SK_API __declspec(dllexport) - #else - #define SK_API __declspec(dllimport) - #endif - #else - #define SK_API __attribute__((visibility("default"))) - #endif - #else - #define SK_API - #endif -#endif - -// SK_SPI is functionally identical to SK_API, but used within src to clarify that it's less stable -#if !defined(SK_SPI) - #define SK_SPI SK_API -#endif - +// All of these files should be independent of things users can set via the user config file. +// They should also be able to be included in any order. // IWYU pragma: begin_exports -#if defined (SK_USER_CONFIG_HEADER) - #include SK_USER_CONFIG_HEADER -#else - #include "include/config/SkUserConfig.h" -#endif -// IWYU pragma: end_exports -#include -#include - -// Post SkUserConfig.h checks and such. -#if !defined(SK_DEBUG) && !defined(SK_RELEASE) - #ifdef NDEBUG - #define SK_RELEASE - #else - #define SK_DEBUG - #endif -#endif +#include "include/private/base/SkFeatures.h" -#if defined(SK_DEBUG) && defined(SK_RELEASE) -# error "cannot define both SK_DEBUG and SK_RELEASE" -#elif !defined(SK_DEBUG) && !defined(SK_RELEASE) -# error "must define either SK_DEBUG or SK_RELEASE" -#endif - -#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) -# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" -#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) -# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" -#endif - -#if defined(SK_CPU_BENDIAN) && !defined(I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN) - #error "The Skia team is not endian-savvy enough to support big-endian CPUs." - #error "If you still want to use Skia," - #error "please define I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN." -#endif +// Load and verify defines from the user config file. +#include "include/private/base/SkLoadUserConfig.h" -#if !defined(SK_ATTRIBUTE) -# if defined(__clang__) || defined(__GNUC__) -# define SK_ATTRIBUTE(attr) __attribute__((attr)) -# else -# define SK_ATTRIBUTE(attr) -# endif -#endif +// Any includes or defines below can be configured by the user config file. +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkDebug.h" +// IWYU pragma: end_exports -#if !defined(SK_SUPPORT_GPU) -# define SK_SUPPORT_GPU 1 -#endif +#include +#include -#if SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GANESH) || defined(SK_GRAPHITE) # if !defined(SK_ENABLE_SKSL) # define SK_ENABLE_SKSL # endif @@ -248,45 +38,6 @@ # undef SK_DIRECT3D #endif -#if !defined(SkUNREACHABLE) -# if defined(_MSC_VER) && !defined(__clang__) -# include -# define FAST_FAIL_INVALID_ARG 5 -// See https://developercommunity.visualstudio.com/content/problem/1128631/code-flow-doesnt-see-noreturn-with-extern-c.html -// for why this is wrapped. Hopefully removable after msvc++ 19.27 is no longer supported. -[[noreturn]] static inline void sk_fast_fail() { __fastfail(FAST_FAIL_INVALID_ARG); } -# define SkUNREACHABLE sk_fast_fail() -# else -# define SkUNREACHABLE __builtin_trap() -# endif -#endif - -#if defined(SK_BUILD_FOR_GOOGLE3) - void SkDebugfForDumpStackTrace(const char* data, void* unused); - namespace base { - void DumpStackTrace(int skip_count, void w(const char*, void*), void* arg); - } -# define SK_DUMP_GOOGLE3_STACK() ::base::DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr) -#else -# define SK_DUMP_GOOGLE3_STACK() -#endif - -#ifndef SK_ABORT -# ifdef SK_BUILD_FOR_WIN - // This style lets Visual Studio follow errors back to the source file. -# define SK_DUMP_LINE_FORMAT "%s(%d)" -# else -# define SK_DUMP_LINE_FORMAT "%s:%d" -# endif -# define SK_ABORT(message, ...) \ - do { \ - SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \ - __FILE__, __LINE__, ##__VA_ARGS__); \ - SK_DUMP_GOOGLE3_STACK(); \ - sk_abort_no_print(); \ - } while (false) -#endif - // If SK_R32_SHIFT is set, we'll use that to choose RGBA or BGRA. // If not, we'll default to RGBA everywhere except BGRA on Windows. #if defined(SK_R32_SHIFT) @@ -306,7 +57,6 @@ #define SK_G32_SHIFT 8 #define SK_A32_SHIFT 24 - /** * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. */ @@ -332,48 +82,6 @@ #undef free #endif -#if !defined(SK_UNUSED) -# if !defined(__clang__) && defined(_MSC_VER) -# define SK_UNUSED __pragma(warning(suppress:4189)) -# else -# define SK_UNUSED SK_ATTRIBUTE(unused) -# endif -#endif - -/** - * If your judgment is better than the compiler's (i.e. you've profiled it), - * you can use SK_ALWAYS_INLINE to force inlining. E.g. - * inline void someMethod() { ... } // may not be inlined - * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined - */ -#if !defined(SK_ALWAYS_INLINE) -# if defined(SK_BUILD_FOR_WIN) -# define SK_ALWAYS_INLINE __forceinline -# else -# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline -# endif -#endif - -/** - * If your judgment is better than the compiler's (i.e. you've profiled it), - * you can use SK_NEVER_INLINE to prevent inlining. - */ -#if !defined(SK_NEVER_INLINE) -# if defined(SK_BUILD_FOR_WIN) -# define SK_NEVER_INLINE __declspec(noinline) -# else -# define SK_NEVER_INLINE SK_ATTRIBUTE(noinline) -# endif -#endif - -#ifndef SK_PRINTF_LIKE -# if defined(__clang__) || defined(__GNUC__) -# define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) -# else -# define SK_PRINTF_LIKE(A, B) -# endif -#endif - #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 0 #endif @@ -386,11 +94,6 @@ # define GR_TEST_UTILS 0 #endif -#if !SK_SUPPORT_GPU - #define SK_GPU_V1 0 // always false if Ganesh is disabled -#elif !defined(SK_GPU_V1) -# define SK_GPU_V1 1 // otherwise default to v1 enabled -#endif #if defined(SK_HISTOGRAM_ENUMERATION) || \ defined(SK_HISTOGRAM_BOOLEAN) || \ @@ -420,145 +123,44 @@ #define SK_HISTOGRAM_PERCENTAGE(name, percent_as_int) \ SK_HISTOGRAM_EXACT_LINEAR(name, percent_as_int, 101) -#ifndef SK_DISABLE_LEGACY_SHADERCONTEXT -#define SK_ENABLE_LEGACY_SHADERCONTEXT +// The top-level define SK_ENABLE_OPTIMIZE_SIZE can be used to remove several large features at once +#if defined(SK_ENABLE_OPTIMIZE_SIZE) +# define SK_FORCE_RASTER_PIPELINE_BLITTER +# define SK_DISABLE_SDF_TEXT #endif -#ifdef SK_ENABLE_API_AVAILABLE -#define SK_API_AVAILABLE API_AVAILABLE -#else -#define SK_API_AVAILABLE(...) +#ifndef SK_DISABLE_LEGACY_SHADERCONTEXT +# define SK_ENABLE_LEGACY_SHADERCONTEXT #endif #if defined(SK_BUILD_FOR_LIBFUZZER) || defined(SK_BUILD_FOR_AFL_FUZZ) +#if !defined(SK_BUILD_FOR_FUZZER) #define SK_BUILD_FOR_FUZZER #endif +#endif -/** Called internally if we hit an unrecoverable error. - The platform implementation must not return, but should either throw - an exception or otherwise exit. -*/ -[[noreturn]] SK_API extern void sk_abort_no_print(void); +/** + * Gr defines are set to 0 or 1, rather than being undefined or defined + */ -#ifndef SkDebugf - SK_API void SkDebugf(const char format[], ...) SK_PRINTF_LIKE(1, 2); +#if !defined(GR_CACHE_STATS) + #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) + #define GR_CACHE_STATS 1 + #else + #define GR_CACHE_STATS 0 + #endif #endif -// SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g. -// uint32_t foo(int x) { -// SkASSERT(x > 4); -// return x - 4; -// } -// and are also written to be compatible with constexpr functions: -// constexpr uint32_t foo(int x) { -// return SkASSERT(x > 4), -// x - 4; -// } -#define SkASSERT_RELEASE(cond) \ - static_cast( (cond) ? (void)0 : []{ SK_ABORT("assert(%s)", #cond); }() ) - -#ifdef SK_DEBUG - #define SkASSERT(cond) SkASSERT_RELEASE(cond) - #define SkASSERTF(cond, fmt, ...) static_cast( (cond) ? (void)0 : [&]{ \ - SkDebugf(fmt"\n", ##__VA_ARGS__); \ - SK_ABORT("assert(%s)", #cond); \ - }() ) - #define SkDEBUGFAIL(message) SK_ABORT("%s", message) - #define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__) - #define SkDEBUGCODE(...) __VA_ARGS__ - #define SkDEBUGF(...) SkDebugf(__VA_ARGS__) - #define SkAssertResult(cond) SkASSERT(cond) -#else - #define SkASSERT(cond) static_cast(0) - #define SkASSERTF(cond, fmt, ...) static_cast(0) - #define SkDEBUGFAIL(message) - #define SkDEBUGFAILF(fmt, ...) - #define SkDEBUGCODE(...) - #define SkDEBUGF(...) - - // unlike SkASSERT, this macro executes its condition in the non-debug build. - // The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT. - #define SkAssertResult(cond) if (cond) {} do {} while(false) +#if !defined(GR_GPU_STATS) + #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || GR_TEST_UTILS + #define GR_GPU_STATS 1 + #else + #define GR_GPU_STATS 0 + #endif #endif //////////////////////////////////////////////////////////////////////////////// -/** Fast type for unsigned 8 bits. Use for parameter passing and local - variables, not for storage -*/ -typedef unsigned U8CPU; - -/** Fast type for unsigned 16 bits. Use for parameter passing and local - variables, not for storage -*/ -typedef unsigned U16CPU; - -/** @return false or true based on the condition -*/ -template static constexpr bool SkToBool(const T& x) { - return (bool)x; -} - -static constexpr int16_t SK_MaxS16 = INT16_MAX; -static constexpr int16_t SK_MinS16 = -SK_MaxS16; - -static constexpr int32_t SK_MaxS32 = INT32_MAX; -static constexpr int32_t SK_MinS32 = -SK_MaxS32; -static constexpr int32_t SK_NaN32 = INT32_MIN; - -static constexpr int64_t SK_MaxS64 = INT64_MAX; -static constexpr int64_t SK_MinS64 = -SK_MaxS64; - -static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { - return (int32_t) ((uint32_t) value << shift); -} - -static inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) { - return (int64_t) ((uint64_t) value << shift); -} - -//////////////////////////////////////////////////////////////////////////////// - -/** @return the number of entries in an array (not a pointer) -*/ -// The SkArrayCountHelper template returns a type 'char (&)[N]', a reference to an array of -// char with N elements, where N is deduced using function parameter type deduction. This is then -// used in the sizeof operator in SK_ARRAY_COUNT. The sizeof operator ignores the reference, and -// just evaluates the size of the array type. -// -// DEPRECATED: use std::size() instead. -// Note: Rarely, std::size(z) can't deduce the type of z during compile time for static_assert -// while SK_ARRAY_COUNT can. It can't be deduced because z is part of class, and the class' this -// pointer is not a valid constexpr expression. Use SkASSERT instead. -template char (&SkArrayCountHelper(T (&array)[N]))[N]; -#define SK_ARRAY_COUNT(array) (sizeof(SkArrayCountHelper(array))) - -//////////////////////////////////////////////////////////////////////////////// - -template static constexpr T SkAlign2(T x) { return (x + 1) >> 1 << 1; } -template static constexpr T SkAlign4(T x) { return (x + 3) >> 2 << 2; } -template static constexpr T SkAlign8(T x) { return (x + 7) >> 3 << 3; } - -template static constexpr bool SkIsAlign2(T x) { return 0 == (x & 1); } -template static constexpr bool SkIsAlign4(T x) { return 0 == (x & 3); } -template static constexpr bool SkIsAlign8(T x) { return 0 == (x & 7); } - -template static constexpr T SkAlignPtr(T x) { - return sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x); -} -template static constexpr bool SkIsAlignPtr(T x) { - return sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x); -} - -/** - * align up to a power of 2 - */ -static inline constexpr size_t SkAlignTo(size_t x, size_t alignment) { - // The same as alignment && SkIsPow2(value), w/o a dependency cycle. - SkASSERT(alignment && (alignment & (alignment - 1)) == 0); - return (x + alignment - 1) & ~(alignment - 1); -} - typedef uint32_t SkFourByteTag; static inline constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d) { return (((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | (uint32_t)d); @@ -591,36 +193,5 @@ static constexpr uint32_t SK_InvalidGenID = 0; */ static constexpr uint32_t SK_InvalidUniqueID = 0; -static inline int32_t SkAbs32(int32_t value) { - SkASSERT(value != SK_NaN32); // The most negative int32_t can't be negated. - if (value < 0) { - value = -value; - } - return value; -} - -template static inline T SkTAbs(T value) { - if (value < 0) { - value = -value; - } - return value; -} - -//////////////////////////////////////////////////////////////////////////////// - -/** Indicates whether an allocation should count against a cache budget. -*/ -enum class SkBudgeted : bool { - kNo = false, - kYes = true -}; - -/** Indicates whether a backing store needs to be an exact match or can be - larger than is strictly necessary -*/ -enum class SkBackingFit { - kApprox, - kExact -}; #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h index fc53e9d01aaf8..2c3f784a42674 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h @@ -12,6 +12,8 @@ #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include + class SkData; struct SkPoint; class SkVerticesPriv; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h index a3cf210f37099..bbbae5d383d94 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h @@ -10,9 +10,13 @@ #include "include/codec/SkEncodedOrigin.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkMatrix.h" #include "include/core/SkSize.h" +#include "include/core/SkTypes.h" #include +#include +#include #include /** diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h index de04ab14dc3c9..2ecb9005df1af 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h @@ -8,14 +8,20 @@ #ifndef SkYUVAPixmaps_DEFINED #define SkYUVAPixmaps_DEFINED +#include "include/core/SkColorType.h" #include "include/core/SkData.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSize.h" +#include "include/core/SkTypes.h" #include "include/core/SkYUVAInfo.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" #include #include +#include +#include class GrImageContext; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h index bf131848baa12..16e953be5e5ed 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h @@ -12,7 +12,7 @@ #include "include/core/SkScalar.h" #include "include/core/SkString.h" #include "include/core/SkTime.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #define SKPDF_STRING(X) SKPDF_STRING_IMPL(X) #define SKPDF_STRING_IMPL(X) #X @@ -143,6 +143,17 @@ struct Metadata { */ SkExecutor* fExecutor = nullptr; + /** PDF streams may be compressed to save space. + Use this to specify the desired compression vs time tradeoff. + */ + enum class CompressionLevel : int { + Default = -1, + None = 0, + LowButFast = 1, + Average = 6, + HighButSlow = 9, + } fCompressionLevel = CompressionLevel::Default; + /** Preferred Subsetter. Only respected if both are compiled in. The Sfntly subsetter is deprecated. diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h index ee470f96d38b2..5092278f0def3 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h @@ -8,12 +8,13 @@ #ifndef SkColorMatrix_DEFINED #define SkColorMatrix_DEFINED -#include "include/core/SkImageInfo.h" #include "include/core/SkTypes.h" #include #include +enum SkYUVColorSpace : int; + class SK_API SkColorMatrix { public: constexpr SkColorMatrix() : SkColorMatrix(1, 0, 0, 0, 0, diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h index df08c96f59322..43a67e242e11e 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h @@ -62,10 +62,43 @@ class SK_API SkGradientShader { struct Interpolation { enum class InPremul : bool { kNo = false, kYes = true }; - InPremul fInPremul = InPremul::kNo; + enum class ColorSpace : uint8_t { + // Default Skia behavior: interpolate in the color space of the destination surface + kDestination, + + // https://www.w3.org/TR/css-color-4/#interpolation-space + kSRGBLinear, + kLab, + kOKLab, + kLCH, + kOKLCH, + kSRGB, + kHSL, + kHWB, + + kLastColorSpace = kHWB, + }; + static constexpr int kColorSpaceCount = static_cast(ColorSpace::kLastColorSpace) + 1; + + enum class HueMethod : uint8_t { + // https://www.w3.org/TR/css-color-4/#hue-interpolation + kShorter, + kLonger, + kIncreasing, + kDecreasing, + + kLastHueMethod = kDecreasing, + }; + static constexpr int kHueMethodCount = static_cast(HueMethod::kLastHueMethod) + 1; + + InPremul fInPremul = InPremul::kNo; + ColorSpace fColorSpace = ColorSpace::kDestination; + HueMethod fHueMethod = HueMethod::kShorter; // Only relevant for LCH, OKLCH, HSL, or HWB static Interpolation FromFlags(uint32_t flags) { - return {flags & kInterpolateColorsInPremul_Flag ? InPremul::kYes : InPremul::kNo}; + return {flags & kInterpolateColorsInPremul_Flag ? InPremul::kYes : InPremul::kNo, + ColorSpace::kDestination, + HueMethod::kShorter}; } }; @@ -76,8 +109,11 @@ class SK_API SkGradientShader { @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the start and end point. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >=2. The number of colors (and pos if not NULL) entries. @param mode The tiling mode @@ -95,8 +131,11 @@ class SK_API SkGradientShader { @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the start and end point. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >=2. The number of colors (and pos if not NULL) entries. @param mode The tiling mode @@ -123,8 +162,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the center and edge of the circle. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode The tiling mode */ @@ -141,8 +183,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the center and edge of the circle. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode The tiling mode */ @@ -214,8 +259,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, then the colors are distributed evenly within the angular range. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode Tiling mode: controls drawing outside of the gradient angular range. @param startAngle Start of the angular range, corresponding to pos == 0. @@ -250,8 +298,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, then the colors are distributed evenly within the angular range. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode Tiling mode: controls drawing outside of the gradient angular range. @param startAngle Start of the angular range, corresponding to pos == 0. diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h index 5665c607015c7..75d2cb0bcc54f 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h @@ -310,17 +310,6 @@ class SK_API SkImageFilters { static sk_sp Offset(SkScalar dx, SkScalar dy, sk_sp input, const CropRect& cropRect = {}); - /** - * Create a filter that fills the output with the given paint. - * @param paint The paint to fill - * @param cropRect Optional rectangle that will be filled. If null, the source bitmap's bounds - * are filled even though the source bitmap itself is not used. - * - * DEPRECATED: Use Shader() instead, since many features of SkPaint are ignored when filling - * the target output, and paint color/alpha can be emulated with SkShaders::Color(). - */ - static sk_sp Paint(const SkPaint& paint, const CropRect& cropRect = {}); - /** * Create a filter that produces the SkPicture as its output, drawn into targetRect. Note that * the targetRect is not the same as the SkIRect cropRect that many filters accept. Returns diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h index a8e0f4d7dc837..4d3450ee25878 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h @@ -16,8 +16,10 @@ #include "include/core/SkShader.h" #include "include/core/SkSpan.h" #include "include/core/SkString.h" -#include "include/private/SkOnce.h" +#include "include/core/SkTypes.h" #include "include/private/SkSLSampleUsage.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkTemplates.h" #include #include @@ -34,6 +36,7 @@ class SkRuntimeImageFilter; namespace SkSL { class DebugTrace; +class DebugTracePriv; class ErrorReporter; class FunctionDefinition; struct Program; @@ -43,7 +46,11 @@ struct ProgramSettings; namespace skvm { class Program; -} // namespace skvm +} + +namespace SkSL::RP { +class Program; +} /* * SkRuntimeEffect supports creating custom SkShader and SkColorFilter objects using Skia's SkSL @@ -126,9 +133,9 @@ class SK_API SkRuntimeEffect : public SkRefCnt { friend class SkRuntimeEffect; friend class SkRuntimeEffectPriv; - // Public SkSL does not allow access to sk_FragCoord. The semantics of that variable are - // confusing, and expose clients to implementation details of saveLayer and image filters. - bool usePrivateRTShaderModule = false; + // This flag allows Runtime Effects to access Skia implementation details like sk_FragCoord + // and functions with private identifiers (e.g. $rgb_to_hsl). + bool allowPrivateAccess = false; // TODO(skia:11209) - Replace this with a promised SkCapabilities? // This flag lifts the ES2 restrictions on Runtime Effects that are gated by the @@ -276,6 +283,7 @@ class SK_API SkRuntimeEffect : public SkRefCnt { kSamplesOutsideMain_Flag = 0x10, kUsesColorTransform_Flag = 0x20, kAlwaysOpaque_Flag = 0x40, + kAlphaUnchanged_Flag = 0x80, }; SkRuntimeEffect(std::unique_ptr baseProgram, @@ -301,15 +309,17 @@ class SK_API SkRuntimeEffect : public SkRefCnt { bool samplesOutsideMain() const { return (fFlags & kSamplesOutsideMain_Flag); } bool usesColorTransform() const { return (fFlags & kUsesColorTransform_Flag); } bool alwaysOpaque() const { return (fFlags & kAlwaysOpaque_Flag); } + bool isAlphaUnchanged() const { return (fFlags & kAlphaUnchanged_Flag); } const SkFilterColorProgram* getFilterColorProgram() const; + const SkSL::RP::Program* getRPProgram(SkSL::DebugTracePriv* debugTrace) const; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) friend class GrSkSLFP; // fBaseProgram, fSampleUsages friend class GrGLSLSkSLFP; // #endif - friend class SkRTShader; // fBaseProgram, fMain + friend class SkRTShader; // fBaseProgram, fMain, fSampleUsages, getRPProgram() friend class SkRuntimeBlender; // friend class SkRuntimeColorFilter; // @@ -319,6 +329,8 @@ class SK_API SkRuntimeEffect : public SkRefCnt { uint32_t fHash; std::unique_ptr fBaseProgram; + std::unique_ptr fRPProgram; + mutable SkOnce fCompileRPProgramOnce; const SkSL::FunctionDefinition& fMain; std::vector fUniforms; std::vector fChildren; @@ -415,6 +427,11 @@ class SkRuntimeEffectBuilder { BuilderUniform uniform(std::string_view name) { return { this, fEffect->findUniform(name) }; } BuilderChild child(std::string_view name) { return { this, fEffect->findChild(name) }; } + // Get access to the collated uniforms and children (in the order expected by APIs like + // makeShader on the effect): + sk_sp uniforms() { return fUniforms; } + SkSpan children() { return fChildren; } + protected: SkRuntimeEffectBuilder() = delete; explicit SkRuntimeEffectBuilder(sk_sp effect) @@ -432,10 +449,6 @@ class SkRuntimeEffectBuilder { SkRuntimeEffectBuilder& operator=(SkRuntimeEffectBuilder&&) = delete; SkRuntimeEffectBuilder& operator=(const SkRuntimeEffectBuilder&) = delete; - sk_sp uniforms() { return fUniforms; } - SkRuntimeEffect::ChildPtr* children() { return fChildren.data(); } - size_t numChildren() { return fChildren.size(); } - private: void* writableUniformData() { if (!fUniforms->unique()) { @@ -492,6 +505,23 @@ class SK_API SkRuntimeShaderBuilder : public SkRuntimeEffectBuilder { friend class SkRuntimeImageFilter; }; +/** + * SkRuntimeColorFilterBuilder makes it easy to setup and assign uniforms to runtime color filters. + */ +class SK_API SkRuntimeColorFilterBuilder : public SkRuntimeEffectBuilder { +public: + explicit SkRuntimeColorFilterBuilder(sk_sp); + ~SkRuntimeColorFilterBuilder(); + + SkRuntimeColorFilterBuilder(const SkRuntimeColorFilterBuilder&) = delete; + SkRuntimeColorFilterBuilder& operator=(const SkRuntimeColorFilterBuilder&) = delete; + + sk_sp makeColorFilter(); + +private: + using INHERITED = SkRuntimeEffectBuilder; +}; + /** * SkRuntimeBlendBuilder is a utility to simplify creation and uniform setup of runtime blenders. */ diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h index 657b9a98a96c7..8f76e8016c848 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h @@ -9,8 +9,12 @@ #define SkEncoder_DEFINED #include "include/core/SkPixmap.h" -#include "include/private/SkNoncopyable.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkNoncopyable.h" +#include "include/private/base/SkTemplates.h" + +#include +#include class SK_API SkEncoder : SkNoncopyable { public: @@ -53,7 +57,7 @@ class SK_API SkEncoder : SkNoncopyable { const SkPixmap& fSrc; int fCurrRow; - SkAutoTMalloc fStorage; + skia_private::AutoTMalloc fStorage; }; #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h new file mode 100644 index 0000000000000..b14836b2ab6aa --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h @@ -0,0 +1,36 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkICC_DEFINED +#define SkICC_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" + +#include + +class SkData; +struct skcms_ICCProfile; +struct skcms_Matrix3x3; +struct skcms_TransferFunction; + +SK_API sk_sp SkWriteICCProfile(const skcms_TransferFunction&, + const skcms_Matrix3x3& toXYZD50); + +SK_API sk_sp SkWriteICCProfile(const skcms_ICCProfile*, const char* description); + +// Utility function for populating the grid_16 member of skcms_A2B and skcms_B2A +// structures. This converts a point in XYZD50 to its representation in grid_16_lab. +// It will write 6 bytes. The behavior of this function matches how skcms will decode +// values, but might not match the specification, see https://crbug.com/skia/13807. +SK_API void SkICCFloatXYZD50ToGrid16Lab(const float* float_xyz, uint8_t* grid16_lab); + +// Utility function for popluating the table_16 member of skcms_Curve structure. +// This converts a float to its representation in table_16. It will write 2 bytes. +SK_API void SkICCFloatToTable16(const float f, uint8_t* table_16); + +#endif//SkICC_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h index f2107f1263a38..f7e8effa7fa5b 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h @@ -8,90 +8,121 @@ #ifndef SkJpegEncoder_DEFINED #define SkJpegEncoder_DEFINED -#include "include/encode/SkEncoder.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" -class SkJpegEncoderMgr; +#include + +class SkColorSpace; +class SkData; +class SkEncoder; +class SkPixmap; class SkWStream; +class SkImage; +class GrDirectContext; +class SkYUVAPixmaps; +struct skcms_ICCProfile; + +namespace SkJpegEncoder { -class SK_API SkJpegEncoder : public SkEncoder { -public: - - enum class AlphaOption { - kIgnore, - kBlendOnBlack, - }; - - enum class Downsample { - /** - * Reduction by a factor of two in both the horizontal and vertical directions. - */ - k420, - - /** - * Reduction by a factor of two in the horizontal direction. - */ - k422, - - /** - * No downsampling. - */ - k444, - }; - - struct Options { - /** - * |fQuality| must be in [0, 100] where 0 corresponds to the lowest quality. - */ - int fQuality = 100; - - /** - * Choose the downsampling factor for the U and V components. This is only - * meaningful if the |src| is not kGray, since kGray will not be encoded as YUV. - * - * Our default value matches the libjpeg-turbo default. - */ - Downsample fDownsample = Downsample::k420; - - /** - * Jpegs must be opaque. This instructs the encoder on how to handle input - * images with alpha. - * - * The default is to ignore the alpha channel and treat the image as opaque. - * Another option is to blend the pixels onto a black background before encoding. - * In the second case, the encoder supports linear or legacy blending. - */ - AlphaOption fAlphaOption = AlphaOption::kIgnore; - }; +enum class AlphaOption { + kIgnore, + kBlendOnBlack, +}; +enum class Downsample { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * Reduction by a factor of two in both the horizontal and vertical directions. */ - static bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + k420, /** - * Create a jpeg encoder that will encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * |dst| is unowned but must remain valid for the lifetime of the object. - * - * This returns nullptr on an invalid or unsupported |src|. + * Reduction by a factor of two in the horizontal direction. */ - static std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, - const Options& options); + k422, - ~SkJpegEncoder() override; + /** + * No downsampling. + */ + k444, +}; + +struct Options { + /** + * |fQuality| must be in [0, 100] where 0 corresponds to the lowest quality. + */ + int fQuality = 100; + + /** + * Choose the downsampling factor for the U and V components. This is only + * meaningful if the |src| is not kGray, since kGray will not be encoded as YUV. + * This is ignored in favor of |src|'s subsampling when |src| is an SkYUVAPixmaps. + * + * Our default value matches the libjpeg-turbo default. + */ + Downsample fDownsample = Downsample::k420; -protected: - bool onEncodeRows(int numRows) override; + /** + * Jpegs must be opaque. This instructs the encoder on how to handle input + * images with alpha. + * + * The default is to ignore the alpha channel and treat the image as opaque. + * Another option is to blend the pixels onto a black background before encoding. + * In the second case, the encoder supports linear or legacy blending. + */ + AlphaOption fAlphaOption = AlphaOption::kIgnore; -private: - SkJpegEncoder(std::unique_ptr, const SkPixmap& src); + /** + * Optional XMP metadata. + */ + const SkData* xmpMetadata = nullptr; - std::unique_ptr fEncoderMgr; - using INHERITED = SkEncoder; + /** + * An optional ICC profile to override the default behavior. + * + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. + */ + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; }; +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); +SK_API bool Encode(SkWStream* dst, + const SkYUVAPixmaps& src, + const SkColorSpace* srcColorSpace, + const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Create a jpeg encoder that will encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * |dst| is unowned but must remain valid for the lifetime of the object. + * + * This returns nullptr on an invalid or unsupported |src|. + */ +SK_API std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, const Options& options); +SK_API std::unique_ptr Make(SkWStream* dst, + const SkYUVAPixmaps& src, + const SkColorSpace* srcColorSpace, + const Options& options); +} // namespace SkJpegEncoder + #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h index ccfa292f747d7..b26befa323ef3 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h @@ -9,91 +9,109 @@ #define SkPngEncoder_DEFINED #include "include/core/SkDataTable.h" -#include "include/encode/SkEncoder.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" -class SkPngEncoderMgr; +// TODO(kjlubick) update clients to directly include this +#include "include/encode/SkEncoder.h" // IWYU pragma: keep + +#include + +class GrDirectContext; +class SkData; +class SkImage; +class SkPixmap; class SkWStream; +struct skcms_ICCProfile; + +namespace SkPngEncoder { + +enum class FilterFlag : int { + kZero = 0x00, + kNone = 0x08, + kSub = 0x10, + kUp = 0x20, + kAvg = 0x40, + kPaeth = 0x80, + kAll = kNone | kSub | kUp | kAvg | kPaeth, +}; -class SK_API SkPngEncoder : public SkEncoder { -public: - - enum class FilterFlag : int { - kZero = 0x00, - kNone = 0x08, - kSub = 0x10, - kUp = 0x20, - kAvg = 0x40, - kPaeth = 0x80, - kAll = kNone | kSub | kUp | kAvg | kPaeth, - }; - - struct Options { - /** - * Selects which filtering strategies to use. - * - * If a single filter is chosen, libpng will use that filter for every row. - * - * If multiple filters are chosen, libpng will use a heuristic to guess which filter - * will encode smallest, then apply that filter. This happens on a per row basis, - * different rows can use different filters. - * - * Using a single filter (or less filters) is typically faster. Trying all of the - * filters may help minimize the output file size. - * - * Our default value matches libpng's default. - */ - FilterFlag fFilterFlags = FilterFlag::kAll; - - /** - * Must be in [0, 9] where 9 corresponds to maximal compression. This value is passed - * directly to zlib. 0 is a special case to skip zlib entirely, creating dramatically - * larger pngs. - * - * Our default value matches libpng's default. - */ - int fZLibLevel = 6; - - /** - * Represents comments in the tEXt ancillary chunk of the png. - * The 2i-th entry is the keyword for the i-th comment, - * and the (2i + 1)-th entry is the text for the i-th comment. - */ - sk_sp fComments; - }; +inline FilterFlag operator|(FilterFlag x, FilterFlag y) { return (FilterFlag)((int)x | (int)y); } +struct Options { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * Selects which filtering strategies to use. + * + * If a single filter is chosen, libpng will use that filter for every row. + * + * If multiple filters are chosen, libpng will use a heuristic to guess which filter + * will encode smallest, then apply that filter. This happens on a per row basis, + * different rows can use different filters. + * + * Using a single filter (or less filters) is typically faster. Trying all of the + * filters may help minimize the output file size. * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * Our default value matches libpng's default. */ - static bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + FilterFlag fFilterFlags = FilterFlag::kAll; /** - * Create a png encoder that will encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * Must be in [0, 9] where 9 corresponds to maximal compression. This value is passed + * directly to zlib. 0 is a special case to skip zlib entirely, creating dramatically + * larger pngs. * - * |dst| is unowned but must remain valid for the lifetime of the object. - * - * This returns nullptr on an invalid or unsupported |src|. + * Our default value matches libpng's default. */ - static std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, - const Options& options); - - ~SkPngEncoder() override; - -protected: - bool onEncodeRows(int numRows) override; + int fZLibLevel = 6; - SkPngEncoder(std::unique_ptr, const SkPixmap& src); + /** + * Represents comments in the tEXt ancillary chunk of the png. + * The 2i-th entry is the keyword for the i-th comment, + * and the (2i + 1)-th entry is the text for the i-th comment. + */ + sk_sp fComments; - std::unique_ptr fEncoderMgr; - using INHERITED = SkEncoder; + /** + * An optional ICC profile to override the default behavior. + * + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. + */ + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; }; -static inline SkPngEncoder::FilterFlag operator|(SkPngEncoder::FilterFlag x, - SkPngEncoder::FilterFlag y) { - return (SkPngEncoder::FilterFlag)((int)x | (int)y); -} +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Create a png encoder that will encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * The primary use of this is incremental encoding of the pixels. + * + * |dst| is unowned but must remain valid for the lifetime of the object. + * + * This returns nullptr on an invalid or unsupported |src|. + */ +SK_API std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, const Options& options); + +} // namespace SkPngEncoder #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h index 1930e4099f84a..fe11044e73804 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h @@ -8,58 +8,85 @@ #ifndef SkWebpEncoder_DEFINED #define SkWebpEncoder_DEFINED -#include "include/core/SkSpan.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSpan.h" // IWYU pragma: keep #include "include/encode/SkEncoder.h" +#include "include/private/base/SkAPI.h" +class SkPixmap; class SkWStream; +class SkData; +class GrDirectContext; +class SkImage; +struct skcms_ICCProfile; namespace SkWebpEncoder { - enum class Compression { - kLossy, - kLossless, - }; - - struct SK_API Options { - /** - * |fCompression| determines whether we will use webp lossy or lossless compression. - * - * |fQuality| must be in [0.0f, 100.0f]. - * If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the - * encoding. Decreasing the quality will result in a smaller encoded image. - * If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort - * put into the encoding. Lower values will compress faster into larger files, - * while larger values will compress slower into smaller files. - * - * This scheme is designed to match the libwebp API. - */ - Compression fCompression = Compression::kLossy; - float fQuality = 100.0f; - }; +enum class Compression { + kLossy, + kLossless, +}; +struct SK_API Options { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * |fCompression| determines whether we will use webp lossy or lossless compression. + * + * |fQuality| must be in [0.0f, 100.0f]. + * If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the + * encoding. Decreasing the quality will result in a smaller encoded image. + * If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort + * put into the encoding. Lower values will compress faster into larger files, + * while larger values will compress slower into smaller files. * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * This scheme is designed to match the libwebp API. */ - SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + Compression fCompression = Compression::kLossy; + float fQuality = 100.0f; /** - * Encode the |src| frames to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * The size of the first frame will be used as the canvas size. If any other frame does - * not match the canvas size, this is an error. - * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * An optional ICC profile to override the default behavior. * - * Note: libwebp API also supports set background color, loop limit and customize - * lossy/lossless for each frame. These could be added later as needed. + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. */ - SK_API bool EncodeAnimated(SkWStream* dst, - SkSpan src, - const Options& options); + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; +}; + +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Encode the |src| frames to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * The size of the first frame will be used as the canvas size. If any other frame does + * not match the canvas size, this is an error. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + * + * Note: libwebp API also supports set background color, loop limit and customize + * lossy/lossless for each frame. These could be added later as needed. + */ +SK_API bool EncodeAnimated(SkWStream* dst, + SkSpan src, + const Options& options); } // namespace SkWebpEncoder #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h index 2eb88a8d433ce..e2e3961f8b9e5 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h @@ -26,16 +26,29 @@ enum class BackendApi : unsigned { kMock, }; +/** Indicates whether an allocation should count against a cache budget. */ +enum class Budgeted : bool { + kNo = false, + kYes = true, +}; + /** * Value passed into various callbacks to tell the client the result of operations connected to a * specific callback. The actual interpretation of kFailed and kSuccess are dependent on the * specific callbacks and are documented with the callback itself. */ enum class CallbackResult : bool { - kFailed = true, + kFailed = false, kSuccess = true, }; +/** + * Is the texture mipmapped or not + */ +enum class Mipmapped : bool { + kNo = false, + kYes = true, +}; /** * Is the data protected on the GPU or not. @@ -45,6 +58,15 @@ enum class Protected : bool { kYes = true, }; +/** + * Is a texture renderable or not + */ +enum class Renderable : bool { + kNo = false, + kYes = true, +}; + } // namespace skgpu + #endif // skgpu_GpuTypes_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h index 759cc1d39837a..37ab666d52ec4 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h @@ -35,6 +35,7 @@ class GrVkImageLayout; class GrGLTextureParameters; class GrColorFormatDesc; +enum class SkTextureCompressionType; namespace skgpu { class MutableTextureStateRef; @@ -57,7 +58,7 @@ class GrD3DResourceState; class SkString; #endif -#if !SK_SUPPORT_GPU +#if !defined(SK_GANESH) // SkSurfaceCharacterization always needs a minimal version of this class SK_API GrBackendFormat { @@ -124,7 +125,8 @@ class SK_API GrBackendFormat { } #endif - static GrBackendFormat MakeMock(GrColorType colorType, SkImage::CompressionType compression, + static GrBackendFormat MakeMock(GrColorType colorType, + SkTextureCompressionType compression, bool isStencilFormat = false); bool operator==(const GrBackendFormat& that) const; @@ -191,7 +193,7 @@ class SK_API GrBackendFormat { * kUnknown, the compression type is not kNone, or this is a mock stencil format. */ GrColorType asMockColorType() const; - SkImage::CompressionType asMockCompressionType() const; + SkTextureCompressionType asMockCompressionType() const; bool isMockStencilFormat() const; // If possible, copies the GrBackendFormat and forces the texture type to be Texture2D. If the @@ -228,7 +230,7 @@ class SK_API GrBackendFormat { GrBackendFormat(DXGI_FORMAT dxgiFormat); #endif - GrBackendFormat(GrColorType, SkImage::CompressionType, bool isStencilFormat); + GrBackendFormat(GrColorType, SkTextureCompressionType, bool isStencilFormat); #ifdef SK_DEBUG bool validateMock() const; @@ -259,9 +261,9 @@ class SK_API GrBackendFormat { DXGI_FORMAT fDxgiFormat; #endif struct { - GrColorType fColorType; - SkImage::CompressionType fCompressionType; - bool fIsStencilFormat; + GrColorType fColorType; + SkTextureCompressionType fCompressionType; + bool fIsStencilFormat; } fMock; }; GrTextureType fTextureType = GrTextureType::kNone; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h deleted file mode 100644 index 9fe6629dd7ead..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h +++ /dev/null @@ -1,53 +0,0 @@ - -/* - * Copyright 2010 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrConfig_DEFINED -#define GrConfig_DEFINED - -#include "include/core/SkTypes.h" - -/** - * Gr defines are set to 0 or 1, rather than being undefined or defined - */ - -#if !defined(GR_CACHE_STATS) - #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) - #define GR_CACHE_STATS 1 - #else - #define GR_CACHE_STATS 0 - #endif -#endif - -#if !defined(GR_GPU_STATS) - #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || GR_TEST_UTILS - #define GR_GPU_STATS 1 - #else - #define GR_GPU_STATS 0 - #endif -#endif - -#endif - -/** - * GR_STRING makes a string of X where X is expanded before conversion to a string - * if X itself contains macros. - */ -#define GR_STRING(X) GR_STRING_IMPL(X) -#define GR_STRING_IMPL(X) #X - -/** - * GR_CONCAT concatenates X and Y where each is expanded before - * contanenation if either contains macros. - */ -#define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y) -#define GR_CONCAT_IMPL(X,Y) X##Y - -/** - * Creates a string of the form "() : " - */ -#define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : " diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h index 28675297a1331..bf4ca409a8f6d 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h @@ -20,7 +20,7 @@ class SkExecutor; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) struct SK_API GrContextOptions { enum class Enable { /** Forces an option to be disabled. */ @@ -80,8 +80,9 @@ struct SK_API GrContextOptions { /** * Controls whether we check for GL errors after functions that allocate resources (e.g. - * glTexImage2D), for shader compilation success, and program link success. Ignored on - * backends other than GL. + * glTexImage2D), at the end of a GPU submission, or checking framebuffer completeness. The + * results of shader compilation and program linking are always checked, regardless of this + * option. Ignored on backends other than GL. */ Enable fSkipGLErrorChecks = Enable::kDefault; @@ -244,6 +245,12 @@ struct SK_API GrContextOptions { */ bool fSuppressMipmapSupport = false; + /** + * If true, the TessellationPathRenderer will not be used for path rendering. + * If false, will fallback to any driver workarounds, if set. + */ + bool fDisableTessellationPathRenderer = false; + /** * If true, and if supported, enables hardware tessellation in the caps. * DEPRECATED: This value is ignored; experimental hardware tessellation is always disabled. @@ -254,13 +261,7 @@ struct SK_API GrContextOptions { * If true, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp * rendering of all glyphs. This must be set to true to use Slugs. */ - #if defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_STRIKE_SERIALIZE) - bool fSupportBilerpFromGlyphAtlas = true; - #else bool fSupportBilerpFromGlyphAtlas = false; - #endif /** * Uses a reduced variety of shaders. May perform less optimally in steady state but can reduce @@ -273,6 +274,24 @@ struct SK_API GrContextOptions { */ bool fAllowMSAAOnNewIntel = false; + /** + * Currently on ARM Android we disable the use of GL TexStorage because of memory regressions. + * However, some clients may still want to use TexStorage. For example, TexStorage support is + * required for creating protected textures. + * + * This flag has no impact on non GL backends. + */ + bool fAlwaysUseTexStorageWhenAvailable = false; + + /** + * Optional callback that can be passed into the GrDirectContext which will be called when the + * GrDirectContext is about to be destroyed. When this call is made, it will be safe for the + * client to delete the GPU backend context that is backing the GrDirectContext. The + * GrDirectContextDestroyedContext will be passed back to the client in the callback. + */ + GrDirectContextDestroyedContext fContextDeleteContext = nullptr; + GrDirectContextDestroyedProc fContextDeleteProc = nullptr; + #if GR_TEST_UTILS /** * Private options that are only meant for testing within Skia's tools. diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h index 7e1ee65ffcdd5..eb755553647b9 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h @@ -10,9 +10,10 @@ #include "include/core/SkRefCnt.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/core/SkImageInfo.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/GrContextOptions.h" #include "include/gpu/GrTypes.h" @@ -25,6 +26,7 @@ class GrThreadSafeCache; class GrThreadSafePipelineBuilder; class SkSurfaceCharacterization; class SkSurfaceProps; +enum class SkTextureCompressionType; namespace sktext::gpu { class TextBlobRedrawCoordinator; } @@ -107,13 +109,13 @@ class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt fAbandoned{false}; }; -#else // !SK_SUPPORT_GPU +#else // !defined(SK_GANESH) class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt {}; #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h index 903623fb7161d..a22fc4fe5784c 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h @@ -8,46 +8,52 @@ #ifndef GrDirectContext_DEFINED #define GrDirectContext_DEFINED +#include "include/core/SkColor.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" +#include "include/gpu/GpuTypes.h" +#include "include/gpu/GrContextOptions.h" #include "include/gpu/GrRecordingContext.h" +#include "include/gpu/GrTypes.h" -#include "include/gpu/GrBackendSurface.h" - -// We shouldn't need this but currently Android is relying on this being include transitively. -#include "include/core/SkUnPreMultiply.h" +#include +#include +#include +#include +#include class GrAtlasManager; class GrBackendSemaphore; +class GrBackendFormat; +class GrBackendTexture; +class GrBackendRenderTarget; class GrClientMappedBufferManager; -class GrDirectContextPriv; class GrContextThreadSafeProxy; -struct GrD3DBackendContext; -class GrFragmentProcessor; +class GrDirectContextPriv; class GrGpu; -struct GrGLInterface; -struct GrMtlBackendContext; -struct GrMockOptions; -class GrPath; class GrResourceCache; class GrResourceProvider; -class GrSurfaceProxy; -class GrTextureProxy; -struct GrVkBackendContext; - +class SkData; class SkImage; -class SkString; -class SkSurfaceCharacterization; -class SkSurfaceProps; +class SkPixmap; class SkTaskGroup; class SkTraceMemoryDump; +enum SkColorType : int; +enum class SkTextureCompressionType; +struct GrGLInterface; +struct GrMockOptions; +struct GrVkBackendContext; // IWYU pragma: keep +struct GrD3DBackendContext; // IWYU pragma: keep +struct GrMtlBackendContext; // IWYU pragma: keep namespace skgpu { -class Swizzle; -namespace v1 { class SmallPathAtlasMgr; } -} - -namespace sktext::gpu { -class StrikeCache; + class MutableTextureState; +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + namespace ganesh { class SmallPathAtlasMgr; } +#endif } +namespace sktext { namespace gpu { class StrikeCache; } } +namespace wgpu { class Device; } // IWYU pragma: keep class SK_API GrDirectContext : public GrRecordingContext { public: @@ -387,7 +393,24 @@ class SK_API GrDirectContext : public GrRecordingContext { */ GrSemaphoresSubmitted flush(const GrFlushInfo& info); - void flush() { this->flush({}); } + void flush() { this->flush(GrFlushInfo()); } + + /** Flushes any pending uses of texture-backed images in the GPU backend. If the image is not + * texture-backed (including promise texture images) or if the GrDirectContext does not + * have the same context ID as the context backing the image then this is a no-op. + * If the image was not used in any non-culled draws in the current queue of work for the + * passed GrDirectContext then this is a no-op unless the GrFlushInfo contains semaphores or + * a finish proc. Those are respected even when the image has not been used. + * @param image the non-null image to flush. + * @param info flush options + */ + GrSemaphoresSubmitted flush(sk_sp image, const GrFlushInfo& info); + void flush(sk_sp image); + + /** Version of flush() that uses a default GrFlushInfo. Also submits the flushed work to the + GPU. + */ + void flushAndSubmit(sk_sp image); /** * Submit outstanding work to the gpu from all previously un-submitted flushes. The return @@ -548,10 +571,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(&srcData, 1, textureOrigin, renderable, isProtected, - finishedProc, finishedContext, label); - } + std::string_view label = {}); // Deprecated versions that do not take origin and assume top-left. GrBackendTexture createBackendTexture(const SkPixmap srcData[], @@ -560,30 +580,14 @@ class SK_API GrDirectContext : public GrRecordingContext { GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(srcData, - numLevels, - kTopLeft_GrSurfaceOrigin, - renderable, - isProtected, - finishedProc, - finishedContext, - label); - } + std::string_view label = {}); + GrBackendTexture createBackendTexture(const SkPixmap& srcData, GrRenderable renderable, GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(&srcData, - 1, - renderable, - isProtected, - finishedProc, - finishedContext, - label); - } + std::string_view label = {}); /** * If possible, updates a backend texture to be filled to a particular color. The client should @@ -662,17 +666,10 @@ class SK_API GrDirectContext : public GrRecordingContext { const SkPixmap srcData[], int numLevels, GrGpuFinishedProc finishedProc, - GrGpuFinishedContext finishedContext) { - return this->updateBackendTexture(texture, - srcData, - numLevels, - kTopLeft_GrSurfaceOrigin, - finishedProc, - finishedContext); - } + GrGpuFinishedContext finishedContext); /** - * Retrieve the GrBackendFormat for a given SkImage::CompressionType. This is + * Retrieve the GrBackendFormat for a given SkTextureCompressionType. This is * guaranteed to match the backend format used by the following * createCompressedBackendTexture methods that take a CompressionType. * @@ -698,7 +695,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrGpuFinishedContext finishedContext = nullptr); GrBackendTexture createCompressedBackendTexture(int width, int height, - SkImage::CompressionType, + SkTextureCompressionType, const SkColor4f& color, GrMipmapped, GrProtected = GrProtected::kNo, @@ -726,7 +723,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrGpuFinishedContext finishedContext = nullptr); GrBackendTexture createCompressedBackendTexture(int width, int height, - SkImage::CompressionType, + SkTextureCompressionType, const void* data, size_t dataSize, GrMipmapped, GrProtected = GrProtected::kNo, @@ -850,7 +847,9 @@ class SK_API GrDirectContext : public GrRecordingContext { bool init() override; GrAtlasManager* onGetAtlasManager() { return fAtlasManager.get(); } - skgpu::v1::SmallPathAtlasMgr* onGetSmallPathAtlasMgr(); +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + skgpu::ganesh::SmallPathAtlasMgr* onGetSmallPathAtlasMgr(); +#endif GrDirectContext* asDirectContext() override { return this; } @@ -868,6 +867,28 @@ class SK_API GrDirectContext : public GrRecordingContext { // bool is used for this signal. void syncAllOutstandingGpuWork(bool shouldExecuteWhileAbandoned); + // This delete callback needs to be the first thing on the GrDirectContext so that it is the + // last thing destroyed. The callback may signal the client to clean up things that may need + // to survive the lifetime of some of the other objects on the GrDirectCotnext. So make sure + // we don't call it until all else has been destroyed. + class DeleteCallbackHelper { + public: + DeleteCallbackHelper(GrDirectContextDestroyedContext context, + GrDirectContextDestroyedProc proc) + : fContext(context), fProc(proc) {} + + ~DeleteCallbackHelper() { + if (fProc) { + fProc(fContext); + } + } + + private: + GrDirectContextDestroyedContext fContext; + GrDirectContextDestroyedProc fProc; + }; + std::unique_ptr fDeleteCallbackHelper; + const DirectContextID fDirectContextID; // fTaskGroup must appear before anything that uses it (e.g. fGpu), so that it is destroyed // after all of its users. Clients of fTaskGroup will generally want to ensure that they call @@ -894,11 +915,11 @@ class SK_API GrDirectContext : public GrRecordingContext { std::unique_ptr fMappedBufferManager; std::unique_ptr fAtlasManager; - std::unique_ptr fSmallPathAtlasMgr; +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + std::unique_ptr fSmallPathAtlasMgr; +#endif friend class GrDirectContextPriv; - - using INHERITED = GrRecordingContext; }; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h index c57efc6016586..1aa995c79177a 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h @@ -13,7 +13,8 @@ #ifdef SK_GPU_WORKAROUNDS_HEADER #include SK_GPU_WORKAROUNDS_HEADER #else -// To regenerate this file, set gn arg "skia_generate_workarounds = true". +// To regenerate this file, set gn arg "skia_generate_workarounds = true" +// or invoke `bazel run //tools:generate_workarounds` // This is not rebuilt by default to avoid embedders having to have extra // build steps. #include "include/gpu/GrDriverBugWorkaroundsAutogen.h" diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h index f8b9c3f39230a..85cc77c051c8f 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h @@ -9,7 +9,8 @@ #define GrRecordingContext_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkTArray.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkTArray.h" #include "include/private/gpu/ganesh/GrImageContext.h" #if GR_GPU_STATS && GR_TEST_UTILS @@ -190,7 +191,7 @@ class GrRecordingContext : public GrImageContext { // of the programInfos matches the intended use. For example, in DDL-record mode it // is known that all the programInfos will have been allocated in an arena with the // same lifetime at the DDL itself. - virtual void detachProgramData(SkTArray*) {} + virtual void detachProgramData(skia_private::TArray*) {} sktext::gpu::TextBlobRedrawCoordinator* getTextBlobRedrawCoordinator(); const sktext::gpu::TextBlobRedrawCoordinator* getTextBlobRedrawCoordinator() const; @@ -223,7 +224,8 @@ class GrRecordingContext : public GrImageContext { #if GR_TEST_UTILS void dump(SkString* out) const; - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const; + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const; #endif private: @@ -236,14 +238,16 @@ class GrRecordingContext : public GrImageContext { #if GR_TEST_UTILS void dump(SkString*) const {} - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const {} + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const {} #endif #endif // GR_GPU_STATS } fStats; #if GR_GPU_STATS && GR_TEST_UTILS struct DMSAAStats { - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const; + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const; void dump() const; void merge(const DMSAAStats&); int fNumRenderPasses = 0; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h index f8895345d658a..177a35a9437f9 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h @@ -8,13 +8,18 @@ #ifndef GrTypes_DEFINED #define GrTypes_DEFINED -#include "include/core/SkMath.h" #include "include/core/SkTypes.h" -#include "include/gpu/GrConfig.h" +#include "include/private/base/SkTo.h" // IWYU pragma: keep +#include +#include class GrBackendSemaphore; -class SkImage; -class SkSurface; + +namespace skgpu { +enum class Mipmapped : bool; +enum class Protected : bool; +enum class Renderable : bool; +} //////////////////////////////////////////////////////////////////////////////// @@ -122,28 +127,20 @@ static constexpr GrBackendApi kMock_GrBackend = GrBackendApi::kMock; /** * Used to say whether a texture has mip levels allocated or not. */ -enum class GrMipmapped : bool { - kNo = false, - kYes = true -}; -/** Deprecated legacy alias of GrMipmapped. */ -using GrMipMapped = GrMipmapped; +/** Deprecated legacy alias of skgpu::Mipmapped. */ +using GrMipmapped = skgpu::Mipmapped; +/** Deprecated legacy alias of skgpu::Mipmapped. */ +using GrMipMapped = skgpu::Mipmapped; /* * Can a GrBackendObject be rendered to? */ -enum class GrRenderable : bool { - kNo = false, - kYes = true -}; +using GrRenderable = skgpu::Renderable; /* * Used to say whether texture is backed by protected memory. */ -enum class GrProtected : bool { - kNo = false, - kYes = true -}; +using GrProtected = skgpu::Protected; /////////////////////////////////////////////////////////////////////////////// @@ -188,6 +185,9 @@ typedef void (*GrGpuFinishedProc)(GrGpuFinishedContext finishedContext); typedef void* GrGpuSubmittedContext; typedef void (*GrGpuSubmittedProc)(GrGpuSubmittedContext submittedContext, bool success); +typedef void* GrDirectContextDestroyedContext; +typedef void (*GrDirectContextDestroyedProc)(GrDirectContextDestroyedContext destroyedContext); + /** * Struct to supply options to flush calls. * diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h index d2e890f780a1f..b595422e8692a 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h @@ -22,7 +22,7 @@ // prepared to rename those identifiers. #include "include/core/SkRefCnt.h" -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include #include @@ -184,7 +184,7 @@ struct GrD3DTextureResourceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; unsigned int fSampleQualityPattern = DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrD3DTextureResourceInfo() = default; @@ -195,7 +195,7 @@ struct GrD3DTextureResourceInfo { uint32_t sampleCount, uint32_t levelCount, unsigned int sampleQualityLevel, - GrProtected isProtected = GrProtected::kNo) + skgpu::Protected isProtected = skgpu::Protected::kNo) : fResource(resource) , fAlloc(alloc) , fResourceState(resourceState) @@ -239,7 +239,7 @@ struct GrD3DFenceInfo { struct GrD3DSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; DXGI_FORMAT fFormat = DXGI_FORMAT_UNKNOWN; unsigned int fSampleQualityPattern = DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h index 70a2f9f6d6c5d..fbd3dbaf55cb1 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h @@ -8,7 +8,7 @@ #ifndef GrDawnTypes_DEFINED #define GrDawnTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #ifdef Always #undef Always @@ -22,7 +22,7 @@ static constexpr int Success = 0; #undef None static constexpr int None = 0L; #endif -#include "webgpu/webgpu_cpp.h" +#include "webgpu/webgpu_cpp.h" // IWYU pragma: export struct GrDawnTextureInfo { wgpu::Texture fTexture; @@ -87,7 +87,7 @@ struct GrDawnRenderTargetInfo { struct GrDawnSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; wgpu::TextureFormat fFormat; }; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h new file mode 100644 index 0000000000000..68f13ce4b5119 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h @@ -0,0 +1,77 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrTextureGenerator_DEFINED +#define GrTextureGenerator_DEFINED + +#include "include/core/SkImageGenerator.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GrTypes.h" +#include "include/private/base/SkAPI.h" + +#include +#include + +class GrRecordingContext; +class GrSurfaceProxyView; +class SkImage; +enum class GrImageTexGenPolicy : int; +namespace skgpu { enum class Mipmapped : bool; } +struct SkImageInfo; + +class SK_API GrTextureGenerator : public SkImageGenerator { +public: + bool isTextureGenerator() const final { return true; } + + /** + * If the generator can natively/efficiently return its pixels as a GPU image (backed by a + * texture) this will return that image. If not, this will return NULL. + * + * Regarding the GrRecordingContext parameter: + * + * It must be non-NULL. The generator should only succeed if: + * - its internal context is the same + * - it can somehow convert its texture into one that is valid for the provided context. + * + * If the mipmapped parameter is kYes, the generator should try to create a TextureProxy that + * at least has the mip levels allocated and the base layer filled in. If this is not possible, + * the generator is allowed to return a non mipped proxy, but this will have some additional + * overhead in later allocating mips and copying of the base layer. + * + * GrImageTexGenPolicy determines whether or not a new texture must be created (and its budget + * status) or whether this may (but is not required to) return a pre-existing texture that is + * retained by the generator (kDraw). + */ + GrSurfaceProxyView generateTexture(GrRecordingContext*, + const SkImageInfo& info, + skgpu::Mipmapped mipmapped, + GrImageTexGenPolicy); + + virtual GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&, + skgpu::Mipmapped, GrImageTexGenPolicy) = 0; + + // Most internal SkImageGenerators produce textures and views that use kTopLeft_GrSurfaceOrigin. + // If the generator may produce textures with different origins (e.g. + // GrAHardwareBufferImageGenerator) it should override this function to return the correct + // origin. Implementations should be thread-safe. + virtual GrSurfaceOrigin origin() const { return kTopLeft_GrSurfaceOrigin; } + +protected: + GrTextureGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID); +}; + +namespace SkImages { +/** + * Like SkImages::DeferredFromGenerator except allows for the use of SkGaneshTextureGenerator. + * + * @param gen producer of textures + * @return created SkImage, or nullptr + */ +SK_API sk_sp DeferredFromTextureGenerator(std::unique_ptr gen); +} + +#endif // GrTextureGenerator_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h new file mode 100644 index 0000000000000..296d90d17e3f9 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h @@ -0,0 +1,385 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkImageGanesh_DEFINED +#define SkImageGanesh_DEFINED + +#include "include/core/SkImage.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GpuTypes.h" +#include "include/gpu/GrTypes.h" +#include "include/private/base/SkAPI.h" + +#include +#include + +class GrBackendFormat; +class GrBackendTexture; +class GrContextThreadSafeProxy; +class GrDirectContext; +class GrRecordingContext; +class GrYUVABackendTextureInfo; +class GrYUVABackendTextures; +class SkColorSpace; +class SkData; +class SkPixmap; +class SkPromiseImageTexture; +class SkYUVAPixmaps; +enum SkAlphaType : int; +enum SkColorType : int; +enum class SkTextureCompressionType; +struct SkISize; + +/** + * All factories in this file refer to the Ganesh GPU backend when they say GPU. + */ + +namespace SkImages { +/** Defines a callback function, taking one parameter of type GrBackendTexture with + no return value. Function is called when backend texture is to be released. +*/ +using BackendTextureReleaseProc = std::function; +/** User function called when supplied texture may be deleted. */ +using TextureReleaseProc = void (*)(ReleaseContext); + +/** Creates GPU-backed SkImage from backendTexture associated with context. + Skia will assume ownership of the resource and will release it when no longer needed. + A non-null SkImage is returned if format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @param context GPU context + @param backendTexture texture residing on GPU + @param textureOrigin origin of backendTexture + @param colorType color type of the resulting image + @param alphaType alpha type of the resulting image + @param colorSpace range of colors; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType); +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType, + SkAlphaType alphaType); +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace); + +/** Creates GPU-backed SkImage from the provided GPU texture associated with context. + GPU texture must stay valid and unchanged until textureReleaseProc is called by Skia. + Skia will call textureReleaseProc with the passed-in releaseContext when SkImage + is deleted or no longer refers to the texture. + A non-null SkImage is returned if format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @note When using a DDL recording context, textureReleaseProc will be called on the + GPU thread after the DDL is played back on the direct context. + @param context GPU context + @param backendTexture texture residing on GPU + @param colorSpace This describes the color space of this image's contents, as + seen after sampling. In general, if the format of the backend + texture is SRGB, some linear colorSpace should be supplied + (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the + backend texture is linear, then the colorSpace should include + a description of the transfer function as + well (e.g., SkColorSpace::MakeSRGB()). + @param textureReleaseProc function called when texture can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp BorrowTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); + +/** Creates a GPU-backed SkImage from pixmap. It is uploaded to GPU backend using context. + Created SkImage is available to other GPU contexts, and is available across thread + boundaries. All contexts must be in the same GPU share group, or otherwise + share resources. + When SkImage is no longer referenced, context releases texture memory + asynchronously. + SkColorSpace of SkImage is determined by pixmap.colorSpace(). + SkImage is returned referring to GPU backend if context is not nullptr, + format of data is recognized and supported, and if context supports moving + resources between contexts. Otherwise, pixmap pixel data is copied and SkImage + as returned in raster format if possible; nullptr may be returned. + Recognized GPU formats vary by platform and GPU backend. + @param context GPU context + @param pixmap SkImageInfo, pixel address, and row bytes + @param buildMips create SkImage as mip map if true + @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary + @return created SkImage, or nullptr +*/ +SK_API sk_sp CrossContextTextureFromPixmap(GrDirectContext* context, + const SkPixmap& pixmap, + bool buildMips, + bool limitToMaxTextureSize = false); + +/** Creates a GPU-backed SkImage from a GPU backend texture. The backend texture must stay + valid and unchanged until textureReleaseProc is called. The textureReleaseProc is + called when the SkImage is deleted or no longer refers to the texture and will be + passed the releaseContext. + An SkImage is returned if the format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @note When using a DDL recording context, textureReleaseProc will be called on the + GPU thread after the DDL is played back on the direct context. + @param context the GPU context + @param backendTexture a texture already allocated by the GPU + @param alphaType This characterizes the nature of the alpha values in the + backend texture. For opaque compressed formats (e.g., ETC1) + this should usually be set to kOpaq + ue_SkAlphaType. + @param colorSpace This describes the color space of this image's contents, as + seen after sampling. In general, if the format of the backend + texture is SRGB, some linear colorSpace should be supplied + (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the + backend texture is linear, then the colorSpace should include + a description of the transfer function as + well (e.g., SkColorSpace::MakeSRGB()). + @param textureReleaseProc function called when the backend texture can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromCompressedTexture(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, + SkAlphaType alphaType, + sk_sp colorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); + +/** Creates a GPU-backed SkImage from compressed data. + This method will return an SkImage representing the compressed data. + If the GPU doesn't support the specified compression method, the data + will be decompressed and then wrapped in a GPU-backed image. + Note: one can query the supported compression formats via + GrRecordingContext::compressedBackendFormat. + @param context GPU context + @param data compressed data to store in SkImage + @param width width of full SkImage + @param height height of full SkImage + @param type type of compression used + @param mipmapped does 'data' contain data for all the mipmap levels? + @param isProtected do the contents of 'data' require DRM protection (on Vulkan)? + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromCompressedTextureData(GrDirectContext* direct, + sk_sp data, + int width, + int height, + SkTextureCompressionType type, + GrMipmapped mipmapped = GrMipmapped::kNo, + GrProtected isProtected = GrProtected::kNo); + +/** Returns SkImage backed by GPU texture associated with context. Returned SkImage is + compatible with SkSurface created with dstColorSpace. The returned SkImage respects + mipmapped setting; if mipmapped equals skgpu::Mipmapped::kYes, the backing texture + allocates mip map levels. + The mipmapped parameter is effectively treated as kNo if MIP maps are not supported by the + GPU. + Returns original SkImage if the image is already texture-backed, the context matches, and + mipmapped is compatible with the backing GPU texture. skgpu::Budgeted is ignored in this + case. + Returns nullptr if context is nullptr, or if SkImage was created with another + GrDirectContext. + @param GrDirectContext the GrDirectContext in play, if it exists + @param SkImage a non-null pointer to an SkImage. + @param skgpu::Mipmapped Whether created SkImage texture must allocate mip map levels. + Defaults to no. + @param skgpu::Budgeted Whether to count a newly created texture for the returned image + counts against the context's budget. Defaults to yes. + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromImage(GrDirectContext*, + const SkImage*, + skgpu::Mipmapped = skgpu::Mipmapped::kNo, + skgpu::Budgeted = skgpu::Budgeted::kYes); +inline sk_sp TextureFromImage(GrDirectContext* ctx, + sk_sp img, + skgpu::Mipmapped m = skgpu::Mipmapped::kNo, + skgpu::Budgeted b = skgpu::Budgeted::kYes) { + return TextureFromImage(ctx, img.get(), m, b); +} + +/** Creates a GPU-backed SkImage from SkYUVAPixmaps. + The image will remain planar with each plane converted to a texture using the passed + GrRecordingContext. + SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. + The SkColorSpace of the resulting RGB values is specified by imageColorSpace. This will + be the SkColorSpace reported by the image and when drawn the RGB values will be converted + from this space into the destination space (if the destination is tagged). + Currently, this is only supported using the GPU backend and will fail if context is nullptr. + SkYUVAPixmaps does not need to remain valid after this returns. + @param context GPU context + @param pixmaps The planes as pixmaps with supported SkYUVAInfo that + specifies conversion to RGB. + @param buildMips create internal YUVA textures as mip map if kYes. This is + silently ignored if the context does not support mip maps. + @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary + @param imageColorSpace range of colors of the resulting image; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromYUVAPixmaps(GrRecordingContext* context, + const SkYUVAPixmaps& pixmaps, + GrMipmapped buildMips, + bool limitToMaxTextureSize, + sk_sp imageColorSpace); +SK_API sk_sp TextureFromYUVAPixmaps(GrRecordingContext* context, + const SkYUVAPixmaps& pixmaps, + GrMipmapped buildMips = GrMipmapped::kNo, + bool limitToMaxTextureSize = false); + +/** Creates a GPU-backed SkImage from YUV[A] planar textures. This requires that the textures + * stay valid for the lifetime of the image. The ReleaseContext can be used to know when it is + * safe to either delete or overwrite the textures. If ReleaseProc is provided it is also called + * before return on failure. + @param context GPU context + @param yuvaTextures A set of textures containing YUVA data and a description of the + data and transformation to RGBA. + @param imageColorSpace range of colors of the resulting image after conversion to RGB; + may be nullptr + @param textureReleaseProc called when the backend textures can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromYUVATextures(GrRecordingContext* context, + const GrYUVABackendTextures& yuvaTextures, + sk_sp imageColorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); +SK_API sk_sp TextureFromYUVATextures(GrRecordingContext* context, + const GrYUVABackendTextures& yuvaTextures); + +using PromiseImageTextureContext = void*; +using PromiseImageTextureFulfillProc = sk_sp (*)(PromiseImageTextureContext); +using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); + +/** Create a new GPU-backed SkImage that is very similar to an SkImage created by BorrowTextureFrom. + The difference is that the caller need not have created the texture nor populated it with the + image pixel data. Moreover, the SkImage may be created on a thread as the creation of the + image does not require access to the backend API or GrDirectContext. Instead of passing a + GrBackendTexture the client supplies a description of the texture consisting of + GrBackendFormat, width, height, and GrMipmapped state. The resulting SkImage can be drawn + to a SkDeferredDisplayListRecorder or directly to a GPU-backed SkSurface. + When the actual texture is required to perform a backend API draw, textureFulfillProc will + be called to receive a GrBackendTexture. The properties of the GrBackendTexture must match + those set during the SkImage creation, and it must refer to a valid existing texture in the + backend API context/device, and be populated with the image pixel data. The texture cannot + be deleted until textureReleaseProc is called. + There is at most one call to each of textureFulfillProc and textureReleaseProc. + textureReleaseProc is always called even if image creation fails or if the + image is never fulfilled (e.g. it is never drawn or all draws are clipped out) + @param gpuContextProxy the thread-safe proxy of the gpu context. required. + @param backendFormat format of promised gpu texture + @param dimensions width & height of promised gpu texture + @param mipmapped mip mapped state of promised gpu texture + @param origin surface origin of promised gpu texture + @param colorType color type of promised gpu texture + @param alphaType alpha type of promised gpu texture + @param colorSpace range of colors; may be nullptr + @param textureFulfillProc function called to get actual gpu texture + @param textureReleaseProc function called when texture can be deleted + @param textureContext state passed to textureFulfillProc and textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp PromiseTextureFrom(sk_sp gpuContextProxy, + const GrBackendFormat& backendFormat, + SkISize dimensions, + GrMipmapped mipmapped, + GrSurfaceOrigin origin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace, + PromiseImageTextureFulfillProc textureFulfillProc, + PromiseImageTextureReleaseProc textureReleaseProc, + PromiseImageTextureContext textureContext); + +/** This is similar to 'PromiseTextureFrom' but it creates a GPU-backed SkImage from YUV[A] data. + The source data may be planar (i.e. spread across multiple textures). In + the extreme Y, U, V, and A are all in different planes and thus the image is specified by + four textures. 'backendTextureInfo' describes the planar arrangement, texture formats, + conversion to RGB, and origin of the textures. Separate 'textureFulfillProc' and + 'textureReleaseProc' calls are made for each texture. Each texture has its own + PromiseImageTextureContext. If 'backendTextureInfo' is not valid then no release proc + calls are made. Otherwise, the calls will be made even on failure. 'textureContexts' has one + entry for each of the up to four textures, as indicated by 'backendTextureInfo'. + Currently the mip mapped property of 'backendTextureInfo' is ignored. However, in the + near future it will be required that if it is kYes then textureFulfillProc must return + a mip mapped texture for each plane in order to successfully draw the image. + @param gpuContextProxy the thread-safe proxy of the gpu context. required. + @param backendTextureInfo info about the promised yuva gpu texture + @param imageColorSpace range of colors; may be nullptr + @param textureFulfillProc function called to get actual gpu texture + @param textureReleaseProc function called when texture can be deleted + @param textureContexts state passed to textureFulfillProc and textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp PromiseTextureFromYUVA(sk_sp gpuContextProxy, + const GrYUVABackendTextureInfo& backendTextureInfo, + sk_sp imageColorSpace, + PromiseImageTextureFulfillProc textureFulfillProc, + PromiseImageTextureReleaseProc textureReleaseProc, + PromiseImageTextureContext textureContexts[]); + +/** Retrieves the existing backend texture. If SkImage is not a Ganesh-backend texture image + or otherwise does not have such a texture, false is returned. Otherwise, outTexture will + be set to the image's texture. + + If flushPendingGrContextIO is true, completes deferred I/O operations. + If origin in not nullptr, copies location of content drawn into SkImage. + @param outTexture Will be set to the underlying texture of the image if non-null. + @param flushPendingGrContextIO flag to flush outstanding requests + @param origin Will be set to the origin orientation of the image if non-null. + @return false if a Ganesh backend texture cannot be retrieved. +*/ +SK_API bool GetBackendTextureFromImage(const SkImage* img, + GrBackendTexture* outTexture, + bool flushPendingGrContextIO, + GrSurfaceOrigin* origin = nullptr); +inline bool GetBackendTextureFromImage(sk_sp img, + GrBackendTexture* outTexture, + bool flushPendingGrContextIO, + GrSurfaceOrigin* origin = nullptr) { + return GetBackendTextureFromImage(img.get(), outTexture, flushPendingGrContextIO, origin); +} + +/** Extracts the backendTexture from an existing SkImage. + If the image is not already GPU-backed, the raster data will be uploaded as a texture + and returned. + If this is the only reference to the image, the old image's texture will be + moved out of the passed in image. + If the image is shared (has a refcount > 1), the texture will be copied and then returned. + @param context GPU context + @param image image, either CPU-backed or GPU-backed + @param backendTexture Will be set to the underlying texture of the image. + @param backendTextureReleaseProc Called when the texture is released + @return false if image cannot be uploaded. +*/ +SK_API bool MakeBackendTextureFromImage(GrDirectContext* context, + sk_sp image, + GrBackendTexture* backendTexture, + BackendTextureReleaseProc* backendTextureReleaseProc); +// Legacy name +inline bool GetBackendTextureFromImage(GrDirectContext* context, + sk_sp image, + GrBackendTexture* backendTexture, + BackendTextureReleaseProc* backendTextureReleaseProc) { + return MakeBackendTextureFromImage(context, std::move(image), backendTexture, + backendTextureReleaseProc); +} + +} // namespace SkImages + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h index 1e2823f71a95b..0ae85f07a0349 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h @@ -10,7 +10,7 @@ #include "include/core/SkString.h" #include "include/gpu/gl/GrGLFunctions.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include @@ -66,13 +66,13 @@ class SK_API GrGLExtensions { */ void add(const char[]); - void reset() { fStrings.reset(); } + void reset() { fStrings.clear(); } void dumpJSON(SkJSONWriter*) const; private: bool fInitialized = false; - SkTArray fStrings; + skia_private::TArray fStrings; }; #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h index 59b9cd9e18d55..4e488abcad432 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h @@ -11,7 +11,7 @@ #include #include "include/gpu/gl/GrGLTypes.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkTLogic.h" extern "C" { diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h index 5d6e3bb2d5f3d..64ca419b9b16a 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h @@ -304,9 +304,6 @@ struct SK_API GrGLInterface : public SkRefCnt { GrGLFunction fVertexAttribPointer; GrGLFunction fViewport; - /* NV_framebuffer_mixed_samples */ - GrGLFunction fCoverageModulation; - /* ARB_sync */ GrGLFunction fFenceSync; GrGLFunction fIsSync; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h index d5167787c1e05..3af4802eaacc2 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h @@ -10,6 +10,7 @@ #define GrGLTypes_DEFINED #include "include/core/SkRefCnt.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/gl/GrGLConfig.h" /** @@ -198,7 +199,7 @@ struct GrGLFramebufferInfo { struct GrGLSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrGLenum fTarget = 0; GrGLenum fFormat = 0; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h index f12d22ebb4f04..82a662ab13fdf 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h @@ -8,29 +8,71 @@ #ifndef skgpu_graphite_BackendTexture_DEFINED #define skgpu_graphite_BackendTexture_DEFINED +#include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/graphite/TextureInfo.h" +#ifdef SK_DAWN +#include "include/gpu/graphite/dawn/DawnTypes.h" +#endif + #ifdef SK_METAL -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" #endif #ifdef SK_VULKAN #include "include/private/gpu/vk/SkiaVulkan.h" #endif +namespace skgpu { +class MutableTextureState; +class MutableTextureStateRef; +} + namespace skgpu::graphite { -class BackendTexture { +class SK_API BackendTexture { public: - BackendTexture() {} + BackendTexture(); +#ifdef SK_DAWN + // Create a BackendTexture from a WGPUTexture. Texture info will be + // queried from the texture. Comparing to WGPUTextureView, + // SkImage::readPixels(), SkSurface::readPixels() and + // SkSurface::writePixels() are implemented by direct buffer copy. They + // should be more efficient. For WGPUTextureView, those methods will use + // create an intermediate WGPUTexture, and use it to transfer pixels. + // Note: + // - for better performance, using WGPUTexture IS RECOMMENDED. + // - The BackendTexture will not call retain or release on the passed in + // WGPUTexture. Thus the client must keep the WGPUTexture valid until + // they are no longer using the BackendTexture. + BackendTexture(WGPUTexture texture); + // Create a BackendTexture from a WGPUTextureView. Texture dimensions and + // info have to be provided. + // Note: + // - this method is for importing WGPUTextureView from wgpu::SwapChain only. + // - The BackendTexture will not call retain or release on the passed in + // WGPUTextureView. Thus the client must keep the WGPUTextureView valid + // until they are no longer using the BackendTexture. + BackendTexture(SkISize dimensions, + const DawnTextureInfo& info, + WGPUTextureView textureView); +#endif #ifdef SK_METAL // The BackendTexture will not call retain or release on the passed in MtlHandle. Thus the // client must keep the MtlHandle valid until they are no longer using the BackendTexture. BackendTexture(SkISize dimensions, MtlHandle mtlTexture); #endif +#ifdef SK_VULKAN + BackendTexture(SkISize dimensions, + const VulkanTextureInfo&, + VkImageLayout, + uint32_t queueFamilyIndex, + VkImage); +#endif + BackendTexture(const BackendTexture&); ~BackendTexture(); @@ -47,15 +89,42 @@ class BackendTexture { const TextureInfo& info() const { return fInfo; } + // If the client changes any of the mutable backend of the GrBackendTexture they should call + // this function to inform Skia that those values have changed. The backend API specific state + // that can be set from this function are: + // + // Vulkan: VkImageLayout and QueueFamilyIndex + void setMutableState(const skgpu::MutableTextureState&); + +#ifdef SK_DAWN + WGPUTexture getDawnTexturePtr() const; + WGPUTextureView getDawnTextureViewPtr() const; +#endif #ifdef SK_METAL MtlHandle getMtlTexture() const; #endif +#ifdef SK_VULKAN + VkImage getVkImage() const; + VkImageLayout getVkImageLayout() const; + uint32_t getVkQueueFamilyIndex() const; +#endif + private: + sk_sp mutableState() const; + SkISize fDimensions; TextureInfo fInfo; + sk_sp fMutableState; + union { +#ifdef SK_DAWN + struct { + WGPUTexture fDawnTexture; + WGPUTextureView fDawnTextureView; + }; +#endif #ifdef SK_METAL MtlHandle fMtlTexture; #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h deleted file mode 100644 index a0c977b283bf5..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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 skgpu_graphite_CombinationBuilder_DEFINED -#define skgpu_graphite_CombinationBuilder_DEFINED - -#include "include/core/SkTypes.h" - -#ifdef SK_ENABLE_PRECOMPILE - -#include -#include -#include -#include "include/core/SkBlendMode.h" -#include "include/core/SkSpan.h" -#include "include/core/SkTileMode.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTHash.h" - -class SkArenaAllocWithReset; -class SkKeyContext; -class SkPaintParamsKeyBuilder; -class SkShaderCodeDictionary; -class SkUniquePaintParamsID; - -namespace skgpu::graphite { - -class CombinationBuilder; -class CombinationBuilderTestAccess; -class Context; -class Option; - -enum class ShaderType : uint32_t { - kSolidColor, - - kLinearGradient, - kRadialGradient, - kSweepGradient, - kConicalGradient, - - kLocalMatrix, - kImage, - kPorterDuffBlendShader, - kBlendShader, - - kLast = kBlendShader -}; - -static constexpr int kShaderTypeCount = static_cast(ShaderType::kLast) + 1; - -struct TileModePair { - SkTileMode fX; - SkTileMode fY; - - bool operator==(const TileModePair& other) const { return fX == other.fX && fY == other.fY; } - bool operator!=(const TileModePair& other) const { return !(*this == other); } -}; - -// TODO: add ShaderID and ColorFilterID too -class BlenderID { -public: - BlenderID() : fID(0) {} // 0 is an invalid blender ID - BlenderID(const BlenderID& src) : fID(src.fID) {} - - bool isValid() const { return fID > 0; } - - bool operator==(const BlenderID& other) const { return fID == other.fID; } - - BlenderID& operator=(const BlenderID& src) { - fID = src.fID; - return *this; - } - -private: - friend class ::SkShaderCodeDictionary; // for ctor and asUInt access - friend class CombinationBuilder; // for asUInt access - - BlenderID(uint32_t id) : fID(id) {} - - uint32_t asUInt() const { return fID; } - - uint32_t fID; -}; - -// When combination options are added to the combination builder an CombinationOption -// object is frequently returned. This allows options to be added, recursively, to the -// previously added options. -// Note: CombinationOptions are stable memory-wise so, once returned, they are valid -// until CombinationBuilder::reset is called. -class CombinationOption { -public: - CombinationOption addChildOption(int childIndex, ShaderType); - - CombinationOption addChildOption(int childIndex, ShaderType, - int minNumStops, int maxNumStops); - - CombinationOption addChildOption(int childIndex, ShaderType, - SkSpan tileModes); - - bool isValid() const { return fDataInArena; } - -private: - friend class CombinationBuilder; // for ctor - friend class CombinationBuilderTestAccess; - - CombinationOption(CombinationBuilder* builder, Option* dataInArena) - : fBuilder(builder) - , fDataInArena(dataInArena) {} - - ShaderType type() const; - int numChildSlots() const; - SkDEBUGCODE(int epoch() const;) - - CombinationBuilder* fBuilder; - Option* fDataInArena; -}; - -class CombinationBuilder { -public: - enum class BlendModeGroup { - kPorterDuff, // [ kClear .. kScreen ] - kAdvanced, // [ kOverlay .. kMultiply ] - kColorAware, // [ kHue .. kLuminosity ] - kAll - }; - - CombinationBuilder(SkShaderCodeDictionary*); - ~CombinationBuilder(); - - // Blend Modes - void addOption(SkBlendMode); - void addOption(SkBlendMode rangeStart, SkBlendMode rangeEnd); // inclusive - void addOption(BlendModeGroup); - - // TODO: have this variant return an CombinationOption object - void addOption(BlenderID); - - // Shaders - CombinationOption addOption(ShaderType); - CombinationOption addOption(ShaderType, int minNumStops, int maxNumStops); // inclusive - CombinationOption addOption(ShaderType, SkSpan tileModes); - - void reset(); - -private: - friend class Context; // for access to 'buildCombinations' - friend class CombinationOption; // for 'addOptionInternal' and 'arena' - friend class CombinationBuilderTestAccess; // for 'num*Combinations' and 'epoch' - - int numShaderCombinations() const; - int numBlendModeCombinations() const; - int numCombinations() { - return this->numShaderCombinations() * this->numBlendModeCombinations(); - } - - // 'desiredCombination' must be less than numCombinations - void createKey(const SkKeyContext&, int desiredCombination, SkPaintParamsKeyBuilder*); - -#ifdef SK_DEBUG - void dump() const; - int epoch() const { return fEpoch; } -#endif - - SkArenaAllocWithReset* arena() { return fArena.get(); } - - template - Option* allocInArena(Args&&... args); - - Option* addOptionInternal(ShaderType); - Option* addOptionInternal(ShaderType, int minNumStops, int maxNumStops); - Option* addOptionInternal(ShaderType, SkSpan tileModes); - - void buildCombinations(SkShaderCodeDictionary*, - const std::function&); - - SkShaderCodeDictionary* fDictionary; - std::unique_ptr fArena; - SkTArray fShaderOptions; - - uint32_t fBlendModes; - // TODO: store the SkBlender-based blenders in the arena - SkTHashSet fBlenders; - - SkDEBUGCODE(int fEpoch = 0;) -}; - -} // namespace skgpu::graphite - -#endif // SK_ENABLE_PRECOMPILE - -#endif // skgpu_graphite_CombinationBuilder_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h index c5ff91e6cb7e0..0fb6eee418687 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h @@ -8,36 +8,34 @@ #ifndef skgpu_graphite_Context_DEFINED #define skgpu_graphite_Context_DEFINED +#include "include/core/SkImage.h" #include "include/core/SkRefCnt.h" #include "include/core/SkShader.h" #include "include/gpu/graphite/ContextOptions.h" #include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/graphite/Recorder.h" -#include "include/private/SingleOwner.h" +#include "include/private/base/SingleOwner.h" +#include #include class SkRuntimeEffect; -namespace skgpu { struct VulkanBackendContext; } - namespace skgpu::graphite { class BackendTexture; +class Buffer; +class ClientMappedBufferManager; class Context; class ContextPriv; -struct DawnBackendContext; class GlobalCache; -struct MtlBackendContext; +class PaintOptions; +class PlotUploadTracker; class QueueManager; class Recording; class ResourceProvider; class SharedContext; - -#ifdef SK_ENABLE_PRECOMPILE -class BlenderID; -class CombinationBuilder; -#endif +class TextureProxy; class SK_API Context final { public: @@ -48,37 +46,30 @@ class SK_API Context final { ~Context(); -#ifdef SK_DAWN - static std::unique_ptr MakeDawn(const DawnBackendContext&, const ContextOptions&); -#endif -#ifdef SK_METAL - static std::unique_ptr MakeMetal(const MtlBackendContext&, const ContextOptions&); -#endif - -#ifdef SK_VULKAN - static std::unique_ptr MakeVulkan(const VulkanBackendContext&, const ContextOptions&); -#endif - BackendApi backend() const; std::unique_ptr makeRecorder(const RecorderOptions& = {}); - void insertRecording(const InsertRecordingInfo&); - void submit(SyncToCpu = SyncToCpu::kNo); + bool insertRecording(const InsertRecordingInfo&); + bool submit(SyncToCpu = SyncToCpu::kNo); + + void asyncReadPixels(const SkImage* image, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); + + void asyncReadPixels(const SkSurface* surface, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); /** * Checks whether any asynchronous work is complete and if so calls related callbacks. */ void checkAsyncWorkCompletion(); -#ifdef SK_ENABLE_PRECOMPILE - // TODO: add "ShaderID addUserDefinedShader(sk_sp)" here - // TODO: add "ColorFilterID addUserDefinedColorFilter(sk_sp)" here - BlenderID addUserDefinedBlender(sk_sp); - - void precompile(CombinationBuilder*); -#endif - /** * Called to delete the passed in BackendTexture. This should only be called if the * BackendTexture was created by calling Recorder::createBackendTexture on a Recorder created @@ -94,21 +85,83 @@ class SK_API Context final { ContextPriv priv(); const ContextPriv priv() const; // NOLINT(readability-const-return-type) + class ContextID { + public: + static Context::ContextID Next(); + + ContextID() : fID(SK_InvalidUniqueID) {} + + bool operator==(const ContextID& that) const { return fID == that.fID; } + bool operator!=(const ContextID& that) const { return !(*this == that); } + + void makeInvalid() { fID = SK_InvalidUniqueID; } + bool isValid() const { return fID != SK_InvalidUniqueID; } + + private: + constexpr ContextID(uint32_t id) : fID(id) {} + uint32_t fID; + }; + + ContextID contextID() const { return fContextID; } + protected: - Context(sk_sp, std::unique_ptr); + Context(sk_sp, std::unique_ptr, const ContextOptions&); private: friend class ContextPriv; + friend class ContextCtorAccessor; SingleOwner* singleOwner() const { return &fSingleOwner; } + // Must be called in Make() to handle one-time GPU setup operations that can possibly fail and + // require Context::Make() to return a nullptr. + bool finishInitialization(); + + void asyncReadPixels(const TextureProxy* textureProxy, + const SkImageInfo& srcImageInfo, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); + + // Inserts a texture to buffer transfer task, used by asyncReadPixels methods + struct PixelTransferResult { + using ConversionFn = void(void* dst, const void* mappedBuffer); + // If null then the transfer could not be performed. Otherwise this buffer will contain + // the pixel data when the transfer is complete. + sk_sp fTransferBuffer; + // RowBytes for transfer buffer data + size_t fRowBytes; + // If this is null then the transfer buffer will contain the data in the requested + // color type. Otherwise, when the transfer is done this must be called to convert + // from the transfer buffer's color type to the requested color type. + std::function fPixelConverter; + }; + PixelTransferResult transferPixels(const TextureProxy*, + const SkImageInfo& srcImageInfo, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect); + sk_sp fSharedContext; std::unique_ptr fResourceProvider; std::unique_ptr fQueueManager; + std::unique_ptr fMappedBufferManager; + std::unique_ptr fPlotUploadTracker; // In debug builds we guard against improper thread handling. This guard is passed to the // ResourceCache for the Context. mutable SingleOwner fSingleOwner; + +#if GRAPHITE_TEST_UTILS + // In test builds a Recorder may track the Context that was used to create it. + bool fStoreContextRefInRecorder = false; + // If this tracking is on, to allow the client to safely delete this Context or its Recorders + // in any order we must also track the Recorders created here. + std::vector fTrackedRecorders; +#endif + + // Needed for MessageBox handling + const ContextID fContextID; }; } // namespace skgpu::graphite diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h index d55351a774c1d..b9ac1b09d1619 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h @@ -8,6 +8,8 @@ #ifndef skgpu_graphite_ContextOptions_DEFINED #define skgpu_graphite_ContextOptions_DEFINED +#include "include/private/base/SkAPI.h" + namespace skgpu { class ShaderErrorHandler; } namespace skgpu::graphite { @@ -15,6 +17,13 @@ namespace skgpu::graphite { struct SK_API ContextOptions { ContextOptions() {} + /** + * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. + * This does not affect code path choices that are made for perfomance reasons nor does it + * override other ContextOption settings. + */ + bool fDisableDriverCorrectnessWorkarounds = false; + /** * If present, use this object to report shader compilation failures. If not, report failures * via SkDebugf and assert. @@ -55,18 +64,7 @@ struct SK_API ContextOptions { * fGlypheCacheTextureMaximumBytes. */ bool fAllowMultipleGlyphCacheTextures = true; - - /** - * If true, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp - * rendering of all glyphs. This must be set to true to use Slugs. - */ - #if defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_STRIKE_SERIALIZE) - bool fSupportBilerpFromGlyphAtlas = true; - #else bool fSupportBilerpFromGlyphAtlas = false; - #endif #if GRAPHITE_TEST_UTILS /** @@ -77,6 +75,12 @@ struct SK_API ContextOptions { * Maximum width and height of internal texture atlases. */ int fMaxTextureAtlasSize = 2048; + + /** + * If true, will store a pointer in Recorder that points back to the Context + * that created it. Used by readPixels() and other methods that normally require a Context. + */ + bool fStoreContextRefInRecorder = false; #endif }; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h index 474e5089fcf2a..231f2a5e1454d 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h @@ -8,14 +8,18 @@ #ifndef skgpu_graphite_GraphiteTypes_DEFINED #define skgpu_graphite_GraphiteTypes_DEFINED +#include "include/core/SkPoint.h" #include "include/core/SkTypes.h" #include "include/gpu/GpuTypes.h" #include +class SkSurface; + namespace skgpu::graphite { class Recording; +class Task; using GpuFinishedContext = void*; using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackResult); @@ -27,9 +31,33 @@ using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackRes * the Recording that they may be holding onto. If the Recording is successfully submitted to the * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All * other cases where some failure occured it will be called with CallbackResult::kFailed. + * + * The fTargetSurface, if provided, is used as a target for any draws recorded onto a deferred + * canvas returned from Recorder::makeDeferredCanvas. This target surface must be provided iff + * the Recording contains any such draws. It must be Graphite-backed and its backing texture's + * TextureInfo must match the info provided to the Recorder when making the deferred canvas. + * + * fTargetTranslation is an additional translation applied to draws targeting fTargetSurface. */ struct InsertRecordingInfo { Recording* fRecording = nullptr; + + SkSurface* fTargetSurface = nullptr; + SkIVector fTargetTranslation = {0, 0}; + + GpuFinishedContext fFinishedContext = nullptr; + GpuFinishedProc fFinishedProc = nullptr; +}; + +/** + * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or + * when there is a failure that caused it not to be submitted. The callback will always be called + * and the caller can use the callback to know it is safe to free any resources associated with + * the Recording that they may be holding onto. If the Recording is successfully submitted to the + * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All + * other cases where some failure occured it will be called with CallbackResult::kFailed. + */ +struct InsertFinishInfo { GpuFinishedContext fFinishedContext = nullptr; GpuFinishedProc fFinishedProc = nullptr; }; @@ -42,12 +70,34 @@ enum class SyncToCpu : bool { kNo = false }; -/** - * Is the texture mipmapped or not +/* + * For Promise Images - should the Promise Image be fulfilled every time a Recording that references + * it is inserted into the Context. */ -enum class Mipmapped : bool { - kNo = false, - kYes = true, +enum class Volatile : bool { + kNo = false, // only fulfilled once + kYes = true // fulfilled on every insertion call +}; + +/* + * Graphite's different rendering methods each only apply to certain types of draws. This + * enum supports decision-making regarding the different renderers and what is being drawn. + */ +enum DrawTypeFlags : uint8_t { + + kNone = 0b000, + + // SkCanvas:: drawSimpleText, drawString, drawGlyphs, drawTextBlob, drawSlug + kText = 0b001, + + // SkCanvas::drawVertices + kDrawVertices = 0b010, + + // All other canvas draw calls + kShape = 0b100, + + kMostCommon = kText | kShape, + kAll = kText | kDrawVertices | kShape }; } // namespace skgpu::graphite diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h index 748b678c5ffa9..3c071fe9ea3e7 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h @@ -13,7 +13,6 @@ namespace skgpu::graphite { -enum class Mipmapped : bool; class Recorder; /* @@ -23,9 +22,12 @@ class Recorder; * return a Graphite-backed version of the provided SkImage that meets the specified * requirements. * - * Skia requires that 'findOrCreate' return a Graphite-backed image that preserves the dimensions, - * number of channels and alpha type of the original image. The bit depth of the - * individual channels can change (e.g., 4444 -> 8888 is allowed). + * Skia requires that 'findOrCreate' return a Graphite-backed image that preserves the + * dimensions and alpha type of the original image. The bit depth of the + * individual channels can change (e.g., 4444 -> 8888 is allowed) as well as the channels - as + * long as the returned image has a superset of the original image's channels + * (e.g., 565 -> 8888 opaque is allowed). + * * Wrt mipmapping, the returned image can have different mipmap settings than requested. If * mipmapping was requested but not returned, the sampling level will be reduced to linear. * If the requirements are not met by the returned image (modulo the flexibility wrt mipmapping) diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h index 82cbd0f1698cf..6e911a4e72c72 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h @@ -11,17 +11,20 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/gpu/graphite/GraphiteTypes.h" -#include "include/private/SingleOwner.h" -#include "include/private/SkTHash.h" +#include "include/gpu/graphite/Recording.h" +#include "include/private/base/SingleOwner.h" +#include "include/private/base/SkTArray.h" #include +class SkCanvas; +struct SkImageInfo; class SkPixmap; -class SkRuntimeEffectDictionary; -class SkTextureDataBlock; -class SkUniformDataBlock; -namespace skgpu { class TokenTracker; } +namespace skgpu { +class RefCntedCallback; +class TokenTracker; +} namespace sktext::gpu { class StrikeCache; @@ -33,22 +36,26 @@ namespace skgpu::graphite { class AtlasManager; class BackendTexture; class Caps; +class Context; class Device; class DrawBufferManager; class GlobalCache; class ImageProvider; +class ProxyCache; class RecorderPriv; -class Recording; class ResourceProvider; +class RuntimeEffectDictionary; class SharedContext; class Task; class TaskGraph; +class TextureDataBlock; class TextureInfo; +class UniformDataBlock; class UploadBufferManager; template class PipelineDataCache; -using UniformDataCache = PipelineDataCache; -using TextureDataCache = PipelineDataCache; +using UniformDataCache = PipelineDataCache; +using TextureDataCache = PipelineDataCache; struct SK_API RecorderOptions final { RecorderOptions(); @@ -115,11 +122,23 @@ class SK_API Recorder final { */ void deleteBackendTexture(BackendTexture&); + // Adds a proc that will be moved to the Recording upon snap, subsequently attached to the + // CommandBuffer when the Recording is added, and called when that CommandBuffer is submitted + // and finishes. If the Recorder or Recording is deleted before the proc is added to the + // CommandBuffer, it will be called with result Failure. + void addFinishInfo(const InsertFinishInfo&); + + // Returns a canvas that will record to a proxy surface, which must be instantiated on replay. + // This can only be called once per Recording; subsequent calls will return null until a + // Recording is snapped. Additionally, the returned SkCanvas is only valid until the next + // Recording snap, at which point it is deleted. + SkCanvas* makeDeferredCanvas(const SkImageInfo&, const TextureInfo&); + // Provides access to functions that aren't part of the public API. RecorderPriv priv(); const RecorderPriv priv() const; // NOLINT(readability-const-return-type) -#if GR_TEST_UTILS +#if GRAPHITE_TEST_UTILS bool deviceIsRegistered(Device*); #endif @@ -156,7 +175,7 @@ class SK_API Recorder final { sk_sp fSharedContext; std::unique_ptr fResourceProvider; - std::unique_ptr fRuntimeEffectDict; + std::unique_ptr fRuntimeEffectDict; std::unique_ptr fGraph; std::unique_ptr fUniformDataCache; @@ -176,6 +195,17 @@ class SK_API Recorder final { // This guard is passed to the ResourceCache. // TODO: Should we also pass this to Device, DrawContext, and similar classes? mutable SingleOwner fSingleOwner; + + sk_sp fTargetProxyDevice; + std::unique_ptr fTargetProxyCanvas; + std::unique_ptr fTargetProxyData; + + skia_private::TArray> fFinishedProcs; + +#if GRAPHITE_TEST_UTILS + // For testing use only -- the Context used to create this Recorder + Context* fContext = nullptr; +#endif }; } // namespace skgpu::graphite diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h index b1cb770bf0667..4a60e5b936626 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h @@ -9,10 +9,17 @@ #define skgpu_graphite_Recording_DEFINED #include "include/core/SkRefCnt.h" +#include "include/private/SkChecksum.h" +#include "include/private/base/SkTArray.h" #include +#include #include +namespace skgpu { +class RefCntedCallback; +} + namespace skgpu::graphite { class CommandBuffer; @@ -20,18 +27,51 @@ class RecordingPriv; class Resource; class ResourceProvider; class TaskGraph; +class Texture; +class TextureInfo; +class TextureProxy; -class Recording final { +class SK_API Recording final { public: ~Recording(); RecordingPriv priv(); +#if GRAPHITE_TEST_UTILS + bool isTargetProxyInstantiated() const; +#endif + private: - friend class Recorder; // for ctor + friend class Recorder; // for ctor and LazyProxyData friend class RecordingPriv; - Recording(std::unique_ptr); + // LazyProxyData is used if this recording should be replayed to a target that is provided on + // replay, and it handles the target proxy's instantiation with the provided target. + class LazyProxyData { + public: + LazyProxyData(const TextureInfo&); + + TextureProxy* lazyProxy(); + sk_sp refLazyProxy(); + + bool lazyInstantiate(ResourceProvider*, sk_sp); + + private: + sk_sp fTarget; + sk_sp fTargetProxy; + }; + + struct ProxyHash { + std::size_t operator()(const sk_sp& proxy) const { + return SkGoodHash()(proxy.get()); + } + }; + + Recording(std::unique_ptr, + std::unordered_set, ProxyHash>&& nonVolatileLazyProxies, + std::unordered_set, ProxyHash>&& volatileLazyProxies, + std::unique_ptr targetProxyData, + skia_private::TArray>&& finishedProcs); bool addCommands(CommandBuffer*, ResourceProvider*); void addResourceRef(sk_sp); @@ -42,6 +82,13 @@ class Recording final { // Those refs are stored in the array here and will eventually be passed onto a CommandBuffer // when the Recording adds its commands. std::vector> fExtraResourceRefs; + + std::unordered_set, ProxyHash> fNonVolatileLazyProxies; + std::unordered_set, ProxyHash> fVolatileLazyProxies; + + std::unique_ptr fTargetProxyData; + + skia_private::TArray> fFinishedProcs; }; } // namespace skgpu::graphite diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h index 15f3081e55f73..9a30839ab43e8 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h @@ -10,8 +10,12 @@ #include "include/gpu/graphite/GraphiteTypes.h" +#ifdef SK_DAWN +#include "include/private/gpu/graphite/DawnTypesPriv.h" +#endif + #ifdef SK_METAL -#include "include/private/gpu/graphite/MtlTypesPriv.h" +#include "include/private/gpu/graphite/MtlGraphiteTypesPriv.h" #endif #ifdef SK_VULKAN @@ -20,15 +24,25 @@ namespace skgpu::graphite { -class TextureInfo { +class SK_API TextureInfo { public: TextureInfo() {} +#ifdef SK_DAWN + TextureInfo(const DawnTextureInfo& dawnInfo) + : fBackend(BackendApi::kDawn) + , fValid(true) + , fSampleCount(dawnInfo.fSampleCount) + , fMipmapped(dawnInfo.fMipmapped) + , fProtected(Protected::kNo) + , fDawnSpec(dawnInfo) {} +#endif + #ifdef SK_METAL TextureInfo(const MtlTextureInfo& mtlInfo) : fBackend(BackendApi::kMetal) , fValid(true) , fSampleCount(mtlInfo.fSampleCount) - , fLevelCount(mtlInfo.fLevelCount) + , fMipmapped(mtlInfo.fMipmapped) , fProtected(Protected::kNo) , fMtlSpec(mtlInfo) {} #endif @@ -38,7 +52,7 @@ class TextureInfo { : fBackend(BackendApi::kVulkan) , fValid(true) , fSampleCount(vkInfo.fSampleCount) - , fLevelCount(vkInfo.fLevelCount) + , fMipmapped(vkInfo.fMipmapped) , fProtected(Protected::kNo) , fVkSpec(vkInfo) { if (vkInfo.fFlags & VK_IMAGE_CREATE_PROTECTED_BIT) { @@ -58,15 +72,25 @@ class TextureInfo { BackendApi backend() const { return fBackend; } uint32_t numSamples() const { return fSampleCount; } - uint32_t numMipLevels() const { return fLevelCount; } + Mipmapped mipmapped() const { return fMipmapped; } Protected isProtected() const { return fProtected; } +#ifdef SK_DAWN + bool getDawnTextureInfo(DawnTextureInfo* info) const { + if (!this->isValid() || fBackend != BackendApi::kDawn) { + return false; + } + *info = DawnTextureSpecToTextureInfo(fDawnSpec, fSampleCount, fMipmapped); + return true; + } +#endif + #ifdef SK_METAL bool getMtlTextureInfo(MtlTextureInfo* info) const { if (!this->isValid() || fBackend != BackendApi::kMetal) { return false; } - *info = MtlTextureSpecToTextureInfo(fMtlSpec, fSampleCount, fLevelCount); + *info = MtlTextureSpecToTextureInfo(fMtlSpec, fSampleCount, fMipmapped); return true; } #endif @@ -76,12 +100,24 @@ class TextureInfo { if (!this->isValid() || fBackend != BackendApi::kVulkan) { return false; } - *info = VulkanTextureSpecToTextureInfo(fVkSpec, fSampleCount, fLevelCount); + *info = VulkanTextureSpecToTextureInfo(fVkSpec, fSampleCount, fMipmapped); return true; } #endif private: +#ifdef SK_DAWN + friend class DawnCaps; + friend class DawnCommandBuffer; + friend class DawnGraphicsPipeline; + friend class DawnResourceProvider; + friend class DawnTexture; + const DawnTextureSpec& dawnTextureSpec() const { + SkASSERT(fValid && fBackend == BackendApi::kDawn); + return fDawnSpec; + } +#endif + #ifdef SK_METAL friend class MtlCaps; friend class MtlGraphicsPipeline; @@ -105,10 +141,13 @@ class TextureInfo { bool fValid = false; uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + Mipmapped fMipmapped = Mipmapped::kNo; Protected fProtected = Protected::kNo; union { +#ifdef SK_DAWN + DawnTextureSpec fDawnSpec; +#endif #ifdef SK_METAL MtlTextureSpec fMtlSpec; #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h new file mode 100644 index 0000000000000..c3b80ae196e32 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h @@ -0,0 +1,139 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef skgpu_graphite_YUVABackendTextures_DEFINED +#define skgpu_graphite_YUVABackendTextures_DEFINED + +#include "include/core/SkSpan.h" +#include "include/core/SkYUVAInfo.h" +#include "include/gpu/graphite/BackendTexture.h" + +#include + +namespace skgpu::graphite { +class Recorder; + +/** + * A description of a set of BackendTextures that hold the planar data described by a SkYUVAInfo. + */ +class SK_API YUVABackendTextureInfo { +public: + static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; + + /** Default YUVABackendTextureInfo is invalid. */ + YUVABackendTextureInfo() = default; + YUVABackendTextureInfo(const YUVABackendTextureInfo&) = default; + YUVABackendTextureInfo& operator=(const YUVABackendTextureInfo&) = default; + + /** + * Initializes a YUVABackendTextureInfo to describe a set of textures that can store the + * planes indicated by the SkYUVAInfo. The texture dimensions are taken from the SkYUVAInfo's + * plane dimensions. All the described textures share a common origin. The planar image this + * describes will be mip mapped if all the textures are individually mip mapped as indicated + * by Mipmapped. This will produce an invalid result (return false from isValid()) if the + * passed formats' channels don't agree with SkYUVAInfo. + */ + YUVABackendTextureInfo(const Recorder*, + const SkYUVAInfo&, + const TextureInfo[kMaxPlanes], + Mipmapped); + + bool operator==(const YUVABackendTextureInfo&) const; + bool operator!=(const YUVABackendTextureInfo& that) const { return !(*this == that); } + + /** TextureInfo for the ith plane, or invalid if i >= numPlanes() */ + const TextureInfo& planeTextureInfo(int i) const { + SkASSERT(i >= 0); + return fPlaneTextureInfos[static_cast(i)]; + } + + const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } + + SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } + + Mipmapped mipmapped() const { return fMipmapped; } + + /** The number of planes, 0 if this YUVABackendTextureInfo is invalid. */ + int numPlanes() const { return fYUVAInfo.numPlanes(); } + + /** + * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture + * formats. + */ + bool isValid() const { return fYUVAInfo.isValid(); } + + /** + * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be + * valid if this->isValid(). + */ + SkYUVAInfo::YUVALocations toYUVALocations() const; + +private: + SkYUVAInfo fYUVAInfo; + std::array fPlaneTextureInfos; + std::array fPlaneChannelMasks; + Mipmapped fMipmapped = Mipmapped::kNo; +}; + +/** + * A set of BackendTextures that hold the planar data for an image described a SkYUVAInfo. + */ +class SK_API YUVABackendTextures { +public: + static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; + + YUVABackendTextures() = default; + YUVABackendTextures(const YUVABackendTextures&) = delete; + YUVABackendTextures& operator=(const YUVABackendTextures&) = delete; + + /** + * Initializes a YUVABackendTextures object from a set of textures that store the planes + * indicated by the SkYUVAInfo. This will produce an invalid result (return false from + * isValid()) if the passed texture formats' channels don't agree with SkYUVAInfo. + */ + YUVABackendTextures(const Recorder*, + const SkYUVAInfo&, + const BackendTexture[kMaxPlanes]); + + SkSpan planeTextures() const { + return SkSpan(fPlaneTextures); + } + + /** BackendTexture for the ith plane, or invalid if i >= numPlanes() */ + BackendTexture planeTexture(int i) const { + SkASSERT(i >= 0); + return fPlaneTextures[static_cast(i)]; + } + + const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } + + SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } + + /** The number of planes, 0 if this YUVABackendTextureInfo is invalid. */ + int numPlanes() const { return fYUVAInfo.numPlanes(); } + + /** + * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture + * formats. + */ + bool isValid() const { return fYUVAInfo.isValid(); } + + /** + * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be + * valid if this->isValid(). + */ + SkYUVAInfo::YUVALocations toYUVALocations() const; + +private: + SkYUVAInfo fYUVAInfo; + std::array fPlaneTextures; + std::array fPlaneChannelMasks; +}; + +} // End of namespace skgpu::graphite + +#endif // skgpu_graphite_YUVABackendTextures_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h new file mode 100644 index 0000000000000..291be756306e7 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h @@ -0,0 +1,40 @@ +/* + * 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 skgpu_graphite_DawnTypes_DEFINED +#define skgpu_graphite_DawnTypes_DEFINED + +#include "include/gpu/graphite/GraphiteTypes.h" +#include "webgpu/webgpu_cpp.h" + +namespace skgpu::graphite { + +struct DawnTextureInfo { + uint32_t fSampleCount = 1; + Mipmapped fMipmapped = Mipmapped::kNo; + + // wgpu::TextureDescriptor properties + wgpu::TextureFormat fFormat = wgpu::TextureFormat::Undefined; + wgpu::TextureUsage fUsage = wgpu::TextureUsage::None; + + DawnTextureInfo() = default; + DawnTextureInfo(const wgpu::Texture& texture); + DawnTextureInfo(uint32_t sampleCount, + Mipmapped mipmapped, + wgpu::TextureFormat format, + wgpu::TextureUsage usage) + : fSampleCount(sampleCount) + , fMipmapped(mipmapped) + , fFormat(format) + , fUsage(usage) {} +}; + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_DawnTypes_DEFINED + + diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h new file mode 100644 index 0000000000000..059d128ef59d6 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h @@ -0,0 +1,28 @@ +/* + * 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 skgpu_graphite_DawnUtils_DEFINED +#define skgpu_graphite_DawnUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; +struct DawnBackendContext; + +namespace ContextFactory { +SK_API std::unique_ptr MakeDawn(const DawnBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + + +#endif // skgpu_graphite_DawnUtils_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h index de5f917a9aa04..9d6d0192d170d 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h @@ -8,7 +8,7 @@ #ifndef skgpu_graphite_MtlBackendContext_DEFINED #define skgpu_graphite_MtlBackendContext_DEFINED -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" namespace skgpu::graphite { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h similarity index 85% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h index 5f4c4c8dccff6..bc04421643db2 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h @@ -5,9 +5,10 @@ * found in the LICENSE file. */ -#ifndef skgpu_graphite_MtlTypes_DEFINED -#define skgpu_graphite_MtlTypes_DEFINED +#ifndef skgpu_graphite_MtlGraphiteTypes_DEFINED +#define skgpu_graphite_MtlGraphiteTypes_DEFINED +#include "include/gpu/graphite/GraphiteTypes.h" #include "include/ports/SkCFObject.h" /////////////////////////////////////////////////////////////////////////////// @@ -38,7 +39,7 @@ using MtlHandle = const void*; struct MtlTextureInfo { uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + skgpu::Mipmapped fMipmapped = skgpu::Mipmapped::kNo; // Since we aren't in an Obj-C header we can't directly use Mtl types here. Each of these can // cast to their mapped Mtl types list below. @@ -50,13 +51,13 @@ struct MtlTextureInfo { MtlTextureInfo() = default; MtlTextureInfo(MtlHandle mtlTexture); MtlTextureInfo(uint32_t sampleCount, - uint32_t levelCount, + skgpu::Mipmapped mipmapped, MtlPixelFormat format, MtlTextureUsage usage, MtlStorageMode storageMode, bool framebufferOnly) : fSampleCount(sampleCount) - , fLevelCount(levelCount) + , fMipmapped(mipmapped) , fFormat(format) , fUsage(usage) , fStorageMode(storageMode) @@ -65,4 +66,4 @@ struct MtlTextureInfo { } // namespace skgpu::graphite -#endif // skgpu_graphite_MtlTypes_DEFINED +#endif // skgpu_graphite_MtlGraphiteTypes_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h new file mode 100644 index 0000000000000..cd7837f86c238 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.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 skgpu_graphite_MtlGraphiteUtils_DEFINED +#define skgpu_graphite_MtlGraphiteUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; +struct MtlBackendContext; + +namespace ContextFactory { +SK_API std::unique_ptr MakeMetal(const MtlBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_MtlGraphiteUtils_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h index 4e9802dbca9dc..bd448d2ca6c1e 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h @@ -8,13 +8,14 @@ #ifndef skgpu_graphite_VulkanGraphiteTypes_DEFINED #define skgpu_graphite_VulkanGraphiteTypes_DEFINED +#include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/vk/VulkanTypes.h" namespace skgpu::graphite { struct VulkanTextureInfo { uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + Mipmapped fMipmapped = Mipmapped::kNo; // VkImageCreateInfo properties // Currently the only supported flag is VK_IMAGE_CREATE_PROTECTED_BIT. Any other flag will not @@ -24,8 +25,6 @@ struct VulkanTextureInfo { VkImageTiling fImageTiling = VK_IMAGE_TILING_OPTIMAL; VkImageUsageFlags fImageUsageFlags = 0; VkSharingMode fSharingMode = VK_SHARING_MODE_EXCLUSIVE; - uint32_t fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED; - VkImageLayout fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; // Properties related to the image view and sampling. These are less inherent properties of the // VkImage but describe how the VkImage should be used within Skia. @@ -41,24 +40,20 @@ struct VulkanTextureInfo { VulkanTextureInfo() = default; VulkanTextureInfo(uint32_t sampleCount, - uint32_t levelCount, + Mipmapped mipmapped, VkImageCreateFlags flags, VkFormat format, VkImageTiling imageTiling, VkImageUsageFlags imageUsageFlags, VkSharingMode sharingMode, - uint32_t currentQueueFamily, - VkImageLayout imageLayout, VkImageAspectFlags aspectMask) : fSampleCount(sampleCount) - , fLevelCount(levelCount) + , fMipmapped(mipmapped) , fFlags(flags) , fFormat(format) , fImageTiling(imageTiling) , fImageUsageFlags(imageUsageFlags) , fSharingMode(sharingMode) - , fCurrentQueueFamily(currentQueueFamily) - , fImageLayout(imageLayout) , fAspectMask(aspectMask) {} }; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h new file mode 100644 index 0000000000000..0cfa0e9bf0a40 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h @@ -0,0 +1,28 @@ +/* + * 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 skgpu_graphite_VulkanGraphiteUtils_DEFINED +#define skgpu_graphite_VulkanGraphiteUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu { struct VulkanBackendContext; } + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; + +namespace ContextFactory { +SK_API std::unique_ptr MakeVulkan(const VulkanBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_VulkanGraphiteUtils_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h index ac866167bc679..b3e4b7b84268d 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h @@ -8,7 +8,8 @@ #ifndef GrMockOptions_DEFINED #define GrMockOptions_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/core/SkTextureCompressionType.h" +#include "include/gpu/GpuTypes.h" #include "include/private/gpu/ganesh/GrTypesPriv.h" class GrBackendFormat; @@ -16,17 +17,17 @@ class GrBackendFormat; struct GrMockTextureInfo { GrMockTextureInfo() : fColorType(GrColorType::kUnknown) - , fCompressionType(SkImage::CompressionType::kNone) + , fCompressionType(SkTextureCompressionType::kNone) , fID(0) {} GrMockTextureInfo(GrColorType colorType, - SkImage::CompressionType compressionType, + SkTextureCompressionType compressionType, int id) : fColorType(colorType) , fCompressionType(compressionType) , fID(id) { SkASSERT(fID); - if (fCompressionType != SkImage::CompressionType::kNone) { + if (fCompressionType != SkTextureCompressionType::kNone) { SkASSERT(colorType == GrColorType::kUnknown); } } @@ -39,10 +40,10 @@ struct GrMockTextureInfo { GrBackendFormat getBackendFormat() const; - SkImage::CompressionType compressionType() const { return fCompressionType; } + SkTextureCompressionType compressionType() const { return fCompressionType; } GrColorType colorType() const { - SkASSERT(fCompressionType == SkImage::CompressionType::kNone); + SkASSERT(fCompressionType == SkTextureCompressionType::kNone); return fColorType; } @@ -50,7 +51,7 @@ struct GrMockTextureInfo { private: GrColorType fColorType; - SkImage::CompressionType fCompressionType; + SkTextureCompressionType fCompressionType; int fID; }; @@ -82,12 +83,15 @@ struct GrMockRenderTargetInfo { struct GrMockSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrColorType fColorType = GrColorType::kUnknown; - SkImage::CompressionType fCompressionType = SkImage::CompressionType::kNone; + SkTextureCompressionType fCompressionType = SkTextureCompressionType::kNone; }; +static constexpr int kSkTextureCompressionTypeCount = + static_cast(SkTextureCompressionType::kLast) + 1; + /** * A pointer to this type is used as the GrBackendContext when creating a Mock GrContext. It can be * used to specify capability options for the mock context. If nullptr is used a default constructed @@ -105,9 +109,9 @@ struct GrMockOptions { fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888]; - fCompressedOptions[(int)SkImage::CompressionType::kETC2_RGB8_UNORM].fTexturable = true; - fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGB8_UNORM].fTexturable = true; - fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGBA8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kETC2_RGB8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kBC1_RGB8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kBC1_RGBA8_UNORM].fTexturable = true; } struct ConfigOptions { @@ -126,7 +130,7 @@ struct GrMockOptions { int fMaxWindowRectangles = 0; int fMaxVertexAttributes = 16; ConfigOptions fConfigOptions[kGrColorTypeCnt]; - ConfigOptions fCompressedOptions[SkImage::kCompressionTypeCount]; + ConfigOptions fCompressedOptions[kSkTextureCompressionTypeCount]; // GrShaderCaps options. bool fIntegerSupport = false; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h index f7a232e3c6cea..7c0d620e06412 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h @@ -8,7 +8,7 @@ #ifndef GrMtlTypes_DEFINED #define GrMtlTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include "include/ports/SkCFObject.h" /** @@ -49,7 +49,7 @@ struct GrMtlTextureInfo { struct GrMtlSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; // Since we aren't in an Obj-C header we can't directly use Mtl types here. Each of these can // cast to their mapped Mtl types list below. diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h index b166e59920676..23c1b0deaf4a5 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h @@ -72,7 +72,7 @@ struct SK_API GrVkBackendContext { bool fOwnsInstanceAndDevice = false; // Indicates that we are working with protected content and all CommandPool and Queue operations // should be done in a protected context. - GrProtected fProtectedContext = GrProtected::kNo; + skgpu::Protected fProtectedContext = skgpu::Protected::kNo; }; #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h index 9d0a4c2c60133..ae680a8af5521 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h @@ -9,7 +9,7 @@ #ifndef GrVkTypes_DEFINED #define GrVkTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/vk/VulkanTypes.h" using GrVkBackendMemory = skgpu::VulkanBackendMemory; @@ -72,7 +72,7 @@ struct GrVkImageInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; uint32_t fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrVkYcbcrConversionInfo fYcbcrConversionInfo; VkSharingMode fSharingMode = VK_SHARING_MODE_EXCLUSIVE; #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK @@ -137,7 +137,7 @@ struct GrVkDrawableInfo { struct GrVkSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; VkImageTiling fImageTiling = VK_IMAGE_TILING_OPTIMAL; VkFormat fFormat = VK_FORMAT_UNDEFINED; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h index 445fd53908333..90a40c0e674d8 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h @@ -10,7 +10,7 @@ #include "include/core/SkString.h" #include "include/gpu/vk/VulkanTypes.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" namespace skgpu { @@ -48,7 +48,7 @@ class SK_API VulkanExtensions { #ifdef SK_DEBUG void dump() const { SkDebugf("**Vulkan Extensions**\n"); - for (int i = 0; i < fExtensions.count(); ++i) { + for (int i = 0; i < fExtensions.size(); ++i) { SkDebugf("%s. Version: %d\n", fExtensions[i].fName.c_str(), fExtensions[i].fSpecVersion); } @@ -59,7 +59,7 @@ class SK_API VulkanExtensions { private: void getSpecVersions(VulkanGetProc getProc, VkInstance, VkPhysicalDevice); - SkTArray fExtensions; + skia_private::TArray fExtensions; }; } // namespace skgpu diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h index 9d73fdf4bdf65..ebaa28ed1b4b0 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h @@ -35,7 +35,7 @@ class VulkanMemoryAllocator : public SkRefCnt { }; enum class BufferUsage { - // Buffers that will only be accessed from the device (large const buffers). Will always be + // Buffers that will only be accessed from the device (large const buffers) will always be // in device local memory. kGpuOnly, // Buffers that typically will be updated multiple times by the host and read on the gpu @@ -103,12 +103,10 @@ class VulkanMemoryAllocator : public SkRefCnt { virtual void freeMemory(const skgpu::VulkanBackendMemory&) = 0; - // Returns the total amount of memory that is allocated and in use by an allocation for this - // allocator. - virtual uint64_t totalUsedMemory() const = 0; - - // Returns the total amount of memory that is allocated by this allocator. - virtual uint64_t totalAllocatedMemory() const = 0; + // Returns the total amount of memory that is allocated as well as total + // amount of memory in use by an allocation from this allocator. + // Return 1st param is total allocated memory, 2nd is total used memory. + virtual std::pair totalAllocatedAndUsedMemory() const = 0; }; } // namespace skgpu diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h index 18c71562e08c0..47d2b3118fbf6 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h @@ -9,8 +9,8 @@ #include "include/core/SkPath.h" #include "include/core/SkTypes.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkTDArray.h" struct SkRect; @@ -102,7 +102,7 @@ class SK_API SkOpBuilder { bool resolve(SkPath* result); private: - SkTArray fPathRefs; + skia_private::TArray fPathRefs; SkTDArray fOps; static bool FixWinding(SkPath* path); diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h new file mode 100644 index 0000000000000..6a22365af433b --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h @@ -0,0 +1,22 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkFontMgr_data_DEFINED +#define SkFontMgr_data_DEFINED + +#include "include/core/SkData.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSpan.h" +#include "include/core/SkTypes.h" + +class SkFontMgr; + +/** Create a custom font manager which wraps a collection of SkData-stored fonts. + * This font manager uses FreeType for rendering. + */ +SK_API sk_sp SkFontMgr_New_Custom_Data(SkSpan>); + +#endif // SkFontMgr_data_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h index 73210bc9a546b..99a1813456f09 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h @@ -13,9 +13,9 @@ #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" #include "include/ports/SkRemotableFontMgr.h" -#include "include/private/SkMutex.h" -#include "include/private/SkOnce.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkTArray.h" class SkData; class SkFontStyle; @@ -34,18 +34,18 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { protected: int onCountFamilies() const override; void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onCreateStyleSet(int index) const override; + sk_sp onCreateStyleSet(int index) const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkTypeface* onMatchFamilyStyle(const char familyName[], - const SkFontStyle& fontStyle) const override; + sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle& fontStyle) const override; - SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], - const SkFontStyle&, - const char* bcp47[], - int bcp47Count, - SkUnichar character) const override; + sk_sp onMatchFamilyStyleCharacter(const char familyName[], + const SkFontStyle&, + const char* bcp47[], + int bcp47Count, + SkUnichar character) const override; sk_sp onMakeFromStreamIndex(std::unique_ptr, int ttcIndex) const override; sk_sp onMakeFromStreamArgs(std::unique_ptr stream, @@ -55,7 +55,7 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { sk_sp onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override; private: - SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const; + sk_sp createTypefaceFromFontId(const SkFontIdentity& fontId) const; sk_sp fImpl; sk_sp fProxy; @@ -93,7 +93,7 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { * typefaces with that data id. By storing the index next to the typeface, * this data cache also acts as a typeface cache. */ - mutable SkTArray fDataCache; + mutable skia_private::TArray fDataCache; mutable SkMutex fDataCacheMutex; friend class SkStyleSet_Indirect; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h index 8017b77cd9a76..eacb6bde9c540 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h @@ -11,7 +11,7 @@ #include "include/core/SkFontStyle.h" #include "include/core/SkRefCnt.h" #include "include/core/SkTypes.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" class SkDataTable; class SkStreamAsset; @@ -48,7 +48,7 @@ class SK_API SkRemotableFontIdentitySet : public SkRefCnt { friend SkRemotableFontIdentitySet* sk_remotable_font_identity_set_new(); int fCount; - SkAutoTArray fData; + skia_private::AutoTArray fData; using INHERITED = SkRefCnt; }; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h index 8437e7a5143ac..0f0d21ad2a67c 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h @@ -8,6 +8,7 @@ #ifndef SkTypeface_win_DEFINED #define SkTypeface_win_DEFINED +#include "include/core/SkRefCnt.h" #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" @@ -26,7 +27,7 @@ typedef LOGFONTA LOGFONT; * corresponding typeface for the specified logfont. The caller is responsible * for calling unref() when it is finished. */ -SK_API SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT&); +SK_API sk_sp SkCreateTypefaceFromLOGFONT(const LOGFONT&); /** * Copy the LOGFONT associated with this typeface into the lf parameter. Note diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h index 235649feec3e3..e703b622bf363 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h @@ -10,17 +10,22 @@ #include "include/core/SkString.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" #include "include/private/SkOpts_spi.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkTLogic.h" #include #include +#include -class SkChecksum : SkNoncopyable { +class SkChecksum { public: + SkChecksum() = default; + // Make noncopyable + SkChecksum(const SkChecksum&) = delete; + SkChecksum& operator=(const SkChecksum&) = delete; + /** - * uint32_t -> uint32_t hash, useful for when you're about to trucate this hash but you + * uint32_t -> uint32_t hash, useful for when you're about to truncate this hash but you * suspect its low bits aren't well mixed. * * This is the Murmur3 finalizer. @@ -35,7 +40,7 @@ class SkChecksum : SkNoncopyable { } /** - * uint32_t -> uint32_t hash, useful for when you're about to trucate this hash but you + * uint32_t -> uint32_t hash, useful for when you're about to truncate this hash but you * suspect its low bits aren't well mixed. * * This version is 2-lines cheaper than Mix, but seems to be sufficient for the font cache. @@ -52,12 +57,14 @@ class SkChecksum : SkNoncopyable { // It should be both reasonably fast and high quality. struct SkGoodHash { template - std::enable_if_t operator()(const K& k) const { + std::enable_if_t::value && sizeof(K) == 4, uint32_t> + operator()(const K& k) const { return SkChecksum::Mix(*(const uint32_t*)&k); } template - std::enable_if_t operator()(const K& k) const { + std::enable_if_t::value && sizeof(K) != 4, uint32_t> + operator()(const K& k) const { return SkOpts::hash_fn(&k, sizeof(K), 0); } @@ -74,4 +81,22 @@ struct SkGoodHash { } }; +// The default hashing behavior in SkGoodHash requires the type to have a unique object +// representation (i.e. all bits in contribute to its identity so can be hashed directly). This is +// false when a struct has padding for alignment (which can be avoided by using +// SK_BEGIN|END_REQUIRE_DENSE) or if the struct has floating point members since there are multiple +// bit representations for NaN. +// +// Often Skia code has externally removed the possibility of NaN so the bit representation of a +// non-NaN float will still hash correctly. SkForceDirectHash produces the same as SkGoodHash +// for K's that do not satisfy std::has_unique_object_representation. It should be used sparingly +// and it's use may highlight design issues with the key's data that might warrant an explicitly +// implemented hash function. +template +struct SkForceDirectHash { + uint32_t operator()(const K& k) const { + return SkOpts::hash_fn(&k, sizeof(K), 0); + } +}; + #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h index 5761df2c0b5d4..1bef596a3628f 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h @@ -10,8 +10,7 @@ #include "include/core/SkColor.h" #include "include/core/SkColorPriv.h" -#include "include/private/SkTo.h" -#include "include/private/SkVx.h" +#include "include/private/base/SkTo.h" //////////////////////////////////////////////////////////////////////////////////////////// // Convert a 16bit pixel to a 32bit pixel @@ -374,30 +373,6 @@ static inline SkPMColor SkPixel4444ToPixel32(U16CPU c) { return d | (d << 4); } -static inline skvx::float4 swizzle_rb(const skvx::float4& x) { - return skvx::shuffle<2, 1, 0, 3>(x); -} - -static inline skvx::float4 swizzle_rb_if_bgra(const skvx::float4& x) { -#ifdef SK_PMCOLOR_IS_BGRA - return swizzle_rb(x); -#else - return x; -#endif -} - -static inline skvx::float4 Sk4f_fromL32(uint32_t px) { - return skvx::cast(skvx::byte4::Load(&px)) * (1 / 255.0f); -} - -static inline uint32_t Sk4f_toL32(const skvx::float4& px) { - uint32_t l32; - // For the expected positive color values, the +0.5 before the pin and cast effectively rounds - // to the nearest int without having to call round() or lrint(). - skvx::cast(pin(px * 255.f + 0.5f, skvx::float4(0.f), skvx::float4(255.f))).store(&l32); - return l32; -} - using SkPMColor4f = SkRGBA4f; constexpr SkPMColor4f SK_PMColor4fTRANSPARENT = { 0, 0, 0, 0 }; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h new file mode 100644 index 0000000000000..8cf511a10c265 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h @@ -0,0 +1,97 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkGainmapInfo_DEFINED +#define SkGainmapInfo_DEFINED + +#include "include/core/SkColor.h" + +/** + * Gainmap rendering parameters. Suppose our display has HDR to SDR ratio of H and we wish to + * display an image with gainmap on this display. Let B be the pixel value from the base image + * in a color space that has the primaries of the base image and a linear transfer function. Let + * G be the pixel value from the gainmap. Let D be the output pixel in the same color space as B. + * The value of D is computed as follows: + * + * First, let W be a weight parameter determing how much the gainmap will be applied. + * W = clamp((log(H) - log(fDisplayRatioSdr)) / + * (log(fDisplayRatioHdr) - log(fDisplayRatioSdr), 0, 1) + * + * Next, let L be the gainmap value in log space. We compute this from the value G that was + * sampled from the texture as follows: + * L = mix(log(fGainmapRatioMin), log(fGainmapRatioMax), pow(G, fGainmapGamma)) + * + * Finally, apply the gainmap to compute D, the displayed pixel. If the base image is SDR then + * compute: + * D = (B + fEpsilonSdr) * exp(L * W) - fEpsilonHdr + * If the base image is HDR then compute: + * D = (B + fEpsilonHdr) * exp(L * (W - 1)) - fEpsilonSdr + * + * In the above math, log() is a natural logarithm and exp() is natural exponentiation. Note, + * however, that the base used for the log() and exp() functions does not affect the results of + * the computation (it cancels out, as long as the same base is used throughout). + */ +struct SkGainmapInfo { + /** + * Parameters for converting the gainmap from its image encoding to log space. These are + * specified per color channel. The alpha value is unused. + */ + SkColor4f fGainmapRatioMin = {1.f, 1.f, 1.f, 1.0}; + SkColor4f fGainmapRatioMax = {2.f, 2.f, 2.f, 1.0}; + SkColor4f fGainmapGamma = {1.f, 1.f, 1.f, 1.f}; + + /** + * Parameters sometimes used in gainmap computation to avoid numerical instability. + */ + SkColor4f fEpsilonSdr = {0.f, 0.f, 0.f, 1.0}; + SkColor4f fEpsilonHdr = {0.f, 0.f, 0.f, 1.0}; + + /** + * If the output display's HDR to SDR ratio is less or equal than fDisplayRatioSdr then the SDR + * rendition is displayed. If the output display's HDR to SDR ratio is greater or equal than + * fDisplayRatioHdr then the HDR rendition is displayed. If the output display's HDR to SDR + * ratio is between these values then an interpolation between the two is displayed using the + * math above. + */ + float fDisplayRatioSdr = 1.f; + float fDisplayRatioHdr = 2.f; + + /** + * Whether the base image is the SDR image or the HDR image. + */ + enum class BaseImageType { + kSDR, + kHDR, + }; + BaseImageType fBaseImageType = BaseImageType::kSDR; + + inline bool operator==(const SkGainmapInfo& other) { + return fGainmapRatioMin == other.fGainmapRatioMin && + fGainmapRatioMax == other.fGainmapRatioMax && fGainmapGamma == other.fGainmapGamma && + fEpsilonSdr == other.fEpsilonSdr && fEpsilonHdr == other.fEpsilonHdr && + fDisplayRatioSdr == other.fDisplayRatioSdr && + fDisplayRatioHdr == other.fDisplayRatioHdr && fBaseImageType == other.fBaseImageType; + } + inline bool operator!=(const SkGainmapInfo& other) { return !(*this == other); } + + // TODO(ccameron): Remove these parameters once we are certain they are not used in Android. + enum class Type { + kUnknown, + kMultiPicture, + kJpegR_Linear, + kJpegR_HLG, + kJpegR_PQ, + kHDRGM, + }; + SkColor4f fLogRatioMin = {0.f, 0.f, 0.f, 1.0}; + SkColor4f fLogRatioMax = {1.f, 1.f, 1.f, 1.0}; + float fHdrRatioMin = 1.f; + float fHdrRatioMax = 50.f; + Type fType = Type::kUnknown; +}; + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h new file mode 100644 index 0000000000000..f490ab96a4cfc --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h @@ -0,0 +1,53 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkGainmapShader_DEFINED +#define SkGainmapShader_DEFINED + +#include "include/core/SkRefCnt.h" + +class SkColorSpace; +class SkShader; +class SkImage; +struct SkGainmapInfo; +struct SkRect; +struct SkSamplingOptions; + +/** + * A gainmap shader will apply a gainmap to an base image using the math described alongside the + * definition of SkGainmapInfo. + */ +class SK_API SkGainmapShader { +public: + /** + * Make a gainmap shader. + * + * When sampling the base image baseImage, the rectangle baseRect will be sampled to map to + * the rectangle dstRect. Sampling will be done according to baseSamplingOptions. + * + * When sampling the gainmap image gainmapImage, the rectangle gainmapRect will be sampled to + * map to the rectangle dstRect. Sampling will be done according to gainmapSamplingOptions. + * + * The gainmap will be applied according to the HDR to SDR ratio specified in dstHdrRatio. + * + * This shader must know the color space of the canvas that it will be rendered to. This color + * space must be specified in dstColorSpace. + * TODO(ccameron): Remove the need for dstColorSpace. + */ + static sk_sp Make(const sk_sp& baseImage, + const SkRect& baseRect, + const SkSamplingOptions& baseSamplingOptions, + const sk_sp& gainmapImage, + const SkRect& gainmapRect, + const SkSamplingOptions& gainmapSamplingOptions, + const SkGainmapInfo& gainmapInfo, + const SkRect& dstRect, + float dstHdrRatio, + sk_sp dstColorSpace); +}; + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h deleted file mode 100644 index 0888869607db7..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkHalf_DEFINED -#define SkHalf_DEFINED - -#include "include/core/SkTypes.h" -#include "include/private/SkVx.h" - -// 16-bit floating point value -// format is 1 bit sign, 5 bits exponent, 10 bits mantissa -// only used for storage -typedef uint16_t SkHalf; - -static constexpr uint16_t SK_HalfMin = 0x0400; // 2^-14 (minimum positive normal value) -static constexpr uint16_t SK_HalfMax = 0x7bff; // 65504 -static constexpr uint16_t SK_HalfEpsilon = 0x1400; // 2^-10 -static constexpr uint16_t SK_Half1 = 0x3C00; // 1 - -// convert between half and single precision floating point -float SkHalfToFloat(SkHalf h); -SkHalf SkFloatToHalf(float f); - -// Convert between half and single precision floating point, -// assuming inputs and outputs are both finite, and may -// flush values which would be denormal half floats to zero. -static inline skvx::float4 SkHalfToFloat_finite_ftz(uint64_t rgba) { - return skvx::from_half(skvx::half4::Load(&rgba)); -} -static inline skvx::half4 SkFloatToHalf_finite_ftz(const skvx::float4& c) { - return skvx::to_half(c); -} - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h index f7a5900e0e1ff..8ebb6ca18e53f 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h @@ -9,8 +9,9 @@ #define SkIDChangeListener_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkThreadAnnotations.h" #include @@ -65,7 +66,7 @@ class SkIDChangeListener : public SkRefCnt { private: mutable SkMutex fMutex; - SkTDArray fListeners SK_GUARDED_BY(fMutex); // pointers are reffed + skia_private::STArray<1, sk_sp> fListeners SK_GUARDED_BY(fMutex); }; private: diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h deleted file mode 100644 index 70b9d715f06b6..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkImageInfoPriv_DEFINED -#define SkImageInfoPriv_DEFINED - -#include "include/core/SkColor.h" -#include "include/core/SkImageInfo.h" - -static inline uint32_t SkColorTypeChannelFlags(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: return 0; - case kAlpha_8_SkColorType: return kAlpha_SkColorChannelFlag; - case kRGB_565_SkColorType: return kRGB_SkColorChannelFlags; - case kARGB_4444_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGB_888x_SkColorType: return kRGB_SkColorChannelFlags; - case kBGRA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_1010102_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGB_101010x_SkColorType: return kRGB_SkColorChannelFlags; - case kBGRA_1010102_SkColorType: return kRGBA_SkColorChannelFlags; - case kBGR_101010x_SkColorType: return kRGB_SkColorChannelFlags; - case kGray_8_SkColorType: return kGray_SkColorChannelFlag; - case kRGBA_F16Norm_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_F16_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_F32_SkColorType: return kRGBA_SkColorChannelFlags; - case kR8G8_unorm_SkColorType: return kRG_SkColorChannelFlags; - case kA16_unorm_SkColorType: return kAlpha_SkColorChannelFlag; - case kR16G16_unorm_SkColorType: return kRG_SkColorChannelFlags; - case kA16_float_SkColorType: return kAlpha_SkColorChannelFlag; - case kR16G16_float_SkColorType: return kRG_SkColorChannelFlags; - case kR16G16B16A16_unorm_SkColorType: return kRGBA_SkColorChannelFlags; - case kSRGBA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kR8_unorm_SkColorType: return kRed_SkColorChannelFlag; - } - SkUNREACHABLE; -} - -static inline bool SkColorTypeIsAlphaOnly(SkColorType ct) { - return SkColorTypeChannelFlags(ct) == kAlpha_SkColorChannelFlag; -} - -static inline bool SkAlphaTypeIsValid(unsigned value) { - return value <= kLastEnum_SkAlphaType; -} - -static int SkColorTypeShiftPerPixel(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: return 0; - case kAlpha_8_SkColorType: return 0; - case kRGB_565_SkColorType: return 1; - case kARGB_4444_SkColorType: return 1; - case kRGBA_8888_SkColorType: return 2; - case kRGB_888x_SkColorType: return 2; - case kBGRA_8888_SkColorType: return 2; - case kRGBA_1010102_SkColorType: return 2; - case kRGB_101010x_SkColorType: return 2; - case kBGRA_1010102_SkColorType: return 2; - case kBGR_101010x_SkColorType: return 2; - case kGray_8_SkColorType: return 0; - case kRGBA_F16Norm_SkColorType: return 3; - case kRGBA_F16_SkColorType: return 3; - case kRGBA_F32_SkColorType: return 4; - case kR8G8_unorm_SkColorType: return 1; - case kA16_unorm_SkColorType: return 1; - case kR16G16_unorm_SkColorType: return 2; - case kA16_float_SkColorType: return 1; - case kR16G16_float_SkColorType: return 2; - case kR16G16B16A16_unorm_SkColorType: return 3; - case kSRGBA_8888_SkColorType: return 2; - case kR8_unorm_SkColorType: return 0; - } - SkUNREACHABLE; -} - -static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { - return (size_t)(width * SkColorTypeBytesPerPixel(ct)); -} - -static inline bool SkColorTypeIsValid(unsigned value) { - return value <= kLastEnum_SkColorType; -} - -static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) { - if (kUnknown_SkColorType == ct) { - return 0; - } - return (size_t)y * rowBytes + ((size_t)x << SkColorTypeShiftPerPixel(ct)); -} - -static inline bool SkColorTypeIsNormalized(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: - case kAlpha_8_SkColorType: - case kRGB_565_SkColorType: - case kARGB_4444_SkColorType: - case kRGBA_8888_SkColorType: - case kRGB_888x_SkColorType: - case kBGRA_8888_SkColorType: - case kRGBA_1010102_SkColorType: - case kRGB_101010x_SkColorType: - case kBGRA_1010102_SkColorType: - case kBGR_101010x_SkColorType: - case kGray_8_SkColorType: - case kRGBA_F16Norm_SkColorType: - case kR8G8_unorm_SkColorType: - case kA16_unorm_SkColorType: - case kA16_float_SkColorType: /*subtle... alpha is always [0,1]*/ - case kR16G16_unorm_SkColorType: - case kR16G16B16A16_unorm_SkColorType: - case kSRGBA_8888_SkColorType: - case kR8_unorm_SkColorType: - return true; - - case kRGBA_F16_SkColorType: - case kRGBA_F32_SkColorType: - case kR16G16_float_SkColorType: - return false; - } - SkUNREACHABLE; -} - -static inline int SkColorTypeMaxBitsPerChannel(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: - return 0; - - case kARGB_4444_SkColorType: - return 4; - - case kRGB_565_SkColorType: - return 6; - - case kAlpha_8_SkColorType: - case kRGBA_8888_SkColorType: - case kRGB_888x_SkColorType: - case kBGRA_8888_SkColorType: - case kGray_8_SkColorType: - case kR8G8_unorm_SkColorType: - case kSRGBA_8888_SkColorType: - case kR8_unorm_SkColorType: - return 8; - - case kRGBA_1010102_SkColorType: - case kRGB_101010x_SkColorType: - case kBGRA_1010102_SkColorType: - case kBGR_101010x_SkColorType: - return 10; - - case kRGBA_F16Norm_SkColorType: - case kA16_unorm_SkColorType: - case kA16_float_SkColorType: - case kR16G16_unorm_SkColorType: - case kR16G16B16A16_unorm_SkColorType: - case kRGBA_F16_SkColorType: - case kR16G16_float_SkColorType: - return 16; - - case kRGBA_F32_SkColorType: - return 32; - } - SkUNREACHABLE; -} - -/** - * Returns true if |info| contains a valid colorType and alphaType. - */ -static inline bool SkColorInfoIsValid(const SkColorInfo& info) { - return info.colorType() != kUnknown_SkColorType && info.alphaType() != kUnknown_SkAlphaType; -} - -/** - * Returns true if |info| contains a valid combination of width, height and colorInfo. - */ -static inline bool SkImageInfoIsValid(const SkImageInfo& info) { - if (info.width() <= 0 || info.height() <= 0) { - return false; - } - - const int kMaxDimension = SK_MaxS32 >> 2; - if (info.width() > kMaxDimension || info.height() > kMaxDimension) { - return false; - } - - return SkColorInfoIsValid(info.colorInfo()); -} - -/** - * Returns true if Skia has defined a pixel conversion from the |src| to the |dst|. - * Returns false otherwise. - */ -static inline bool SkImageInfoValidConversion(const SkImageInfo& dst, const SkImageInfo& src) { - return SkImageInfoIsValid(dst) && SkImageInfoIsValid(src); -} -#endif // SkImageInfoPriv_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h new file mode 100644 index 0000000000000..756de78b23101 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h @@ -0,0 +1,71 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkJpegGainmapEncoder_DEFINED +#define SkJpegGainmapEncoder_DEFINED + +#include "include/encode/SkJpegEncoder.h" + +class SkPixmap; +class SkWStream; +struct SkGainmapInfo; + +class SK_API SkJpegGainmapEncoder { +public: + /** + * Encode a JpegR image to |dst|. + * + * The base image is specified by |base|, and |baseOptions| controls the encoding behavior for + * the base image. + * + * The gainmap image is specified by |gainmap|, and |gainmapOptions| controls the encoding + * behavior for the gainmap image. + * + * The rendering behavior of the gainmap image is provided in |gainmapInfo|. Not all gainmap + * based images are compatible with JpegR. If the image is not compatible with JpegR, then + * convert the gainmap to a format that is capable with JpegR. This conversion may result in + * less precise quantization of the gainmap image. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ + static bool EncodeJpegR(SkWStream* dst, + const SkPixmap& base, + const SkJpegEncoder::Options& baseOptions, + const SkPixmap& gainmap, + const SkJpegEncoder::Options& gainmapOptions, + const SkGainmapInfo& gainmapInfo); + + /** + * Encode an HDRGM image to |dst|. + * + * The base image is specified by |base|, and |baseOptions| controls the encoding behavior for + * the base image. + * + * The gainmap image is specified by |gainmap|, and |gainmapOptions| controls the encoding + * behavior for the gainmap image. + * + * The rendering behavior of the gainmap image is provided in |gainmapInfo|. + * + * If |baseOptions| or |gainmapOptions| specify XMP metadata, then that metadata will be + * overwritten. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ + static bool EncodeHDRGM(SkWStream* dst, + const SkPixmap& base, + const SkJpegEncoder::Options& baseOptions, + const SkPixmap& gainmap, + const SkJpegEncoder::Options& gainmapOptions, + const SkGainmapInfo& gainmapInfo); + + /** + * Write a Multi Picture Format containing the |imageCount| images specified by |images|. + */ + static bool MakeMPF(SkWStream* dst, const SkData** images, size_t imageCount); +}; + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h new file mode 100644 index 0000000000000..0b8f6ce1f7577 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h @@ -0,0 +1,61 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkJpegMetadataDecoder_DEFINED +#define SkJpegMetadataDecoder_DEFINED + +#include "include/core/SkData.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +#include +#include + +struct SkGainmapInfo; + +/** + * An interface that can be used to extract metadata from an encoded JPEG file. + * TODO(https://crbug.com/1404000): Add interface for ICC profile and EXIF extraction. + */ +class SK_API SkJpegMetadataDecoder { +public: + SkJpegMetadataDecoder() {} + virtual ~SkJpegMetadataDecoder() {} + + SkJpegMetadataDecoder(const SkJpegMetadataDecoder&) = delete; + SkJpegMetadataDecoder& operator=(const SkJpegMetadataDecoder&) = delete; + + /** + * A segment from a JPEG file. This is usually populated from a jpeg_marker_struct. + */ + struct SK_API Segment { + Segment(uint8_t marker, sk_sp data) : fMarker(marker), fData(std::move(data)) {} + + // The segment's marker. + uint8_t fMarker = 0; + + // The segment's parameters (not including the marker and parameter length). + sk_sp fData; + }; + + /** + * Create metadata for the specified segments from a JPEG file's header (defined as all segments + * before the first StartOfScan). This may return nullptr. + */ + static std::unique_ptr Make(std::vector headerSegments); + + /** + * Given a JPEG encoded image |baseImageData|, return in |outGainmapImageData| the JPEG encoded + * gainmap image and return in |outGainmapInfo| its gainmap rendering parameters. Return true if + * both output variables were successfully populated, otherwise return false. + */ + virtual bool findGainmapImage(sk_sp baseImageData, + sk_sp& outGainmapImagedata, + SkGainmapInfo& outGainmapInfo) = 0; +}; + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h index e57dc1433ff50..6e888b77c84c3 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h @@ -8,7 +8,9 @@ #ifndef SkOpts_spi_DEFINED #define SkOpts_spi_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" + +#include // These are exposed as SK_SPI (e.g. SkParagraph), the rest of SkOpts is // declared in src/core diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h index e72651dce7842..c0e0f08aa1bd9 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h @@ -8,36 +8,25 @@ #ifndef SkPathRef_DEFINED #define SkPathRef_DEFINED -#include "include/core/SkMatrix.h" #include "include/core/SkPoint.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" #include "include/private/SkIDChangeListener.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" -#include "include/private/SkTemplates.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkTo.h" #include -#include +#include +#include #include +#include -class SkRBuffer; -class SkWBuffer; +class SkMatrix; class SkRRect; -enum class SkPathConvexity { - kConvex, - kConcave, - kUnknown, -}; - -enum class SkPathFirstDirection { - kCW, // == SkPathDirection::kCW - kCCW, // == SkPathDirection::kCCW - kUnknown, -}; - // These are computed from a stream of verbs struct SkPathVerbAnalysis { bool valid; @@ -64,7 +53,13 @@ SkPathVerbAnalysis sk_path_analyze_verbs(const uint8_t verbs[], int count); class SK_API SkPathRef final : public SkNVRefCnt { public: - SkPathRef(SkTDArray points, SkTDArray verbs, SkTDArray weights, + // See https://bugs.chromium.org/p/skia/issues/detail?id=13817 for how these sizes were + // determined. + using PointsArray = skia_private::STArray<4, SkPoint>; + using VerbsArray = skia_private::STArray<4, uint8_t>; + using ConicWeightsArray = skia_private::STArray<2, SkScalar>; + + SkPathRef(PointsArray points, VerbsArray verbs, ConicWeightsArray weights, unsigned segmentMask) : fPoints(std::move(points)) , fVerbs(std::move(verbs)) @@ -320,24 +315,15 @@ class SK_API SkPathRef final : public SkNVRefCnt { bool operator== (const SkPathRef& ref) const; - /** - * Writes the path points and verbs to a buffer. - */ - void writeToBuffer(SkWBuffer* buffer) const; - - /** - * Gets the number of bytes that would be written in writeBuffer() - */ - uint32_t writeSize() const; - void interpolate(const SkPathRef& ending, SkScalar weight, SkPathRef* out) const; /** * Gets an ID that uniquely identifies the contents of the path ref. If two path refs have the * same ID then they have the same verbs and points. However, two path refs may have the same * contents but different genIDs. + * skbug.com/1762 for background on why fillType is necessary (for now). */ - uint32_t genID() const; + uint32_t genID(uint8_t fillType) const; void addGenIDChangeListener(sk_sp); // Threadsafe. int genIDChangeListenerCount(); // Threadsafe @@ -346,6 +332,15 @@ class SK_API SkPathRef final : public SkNVRefCnt { bool isValid() const; SkDEBUGCODE(void validate() const { SkASSERT(this->isValid()); } ) + /** + * Resets this SkPathRef to a clean state. + */ + void reset(); + + bool isInitialEmptyPathRef() const { + return fGenerationID == kEmptyGenID; + } + private: enum SerializationOffsets { kLegacyRRectOrOvalStartIdx_SerializationShift = 28, // requires 3 bits, ignored. @@ -356,7 +351,7 @@ class SK_API SkPathRef final : public SkNVRefCnt { kSegmentMask_SerializationShift = 0 // requires 4 bits (deprecated) }; - SkPathRef() { + SkPathRef(int numVerbs = 0, int numPoints = 0) { fBoundsIsDirty = true; // this also invalidates fIsFinite fGenerationID = kEmptyGenID; fSegmentMask = 0; @@ -365,6 +360,10 @@ class SK_API SkPathRef final : public SkNVRefCnt { // The next two values don't matter unless fIsOval or fIsRRect are true. fRRectOrOvalIsCCW = false; fRRectOrOvalStartIdx = 0xAC; + if (numPoints > 0) + fPoints.reserve_back(numPoints); + if (numVerbs > 0) + fVerbs.reserve_back(numVerbs); SkDEBUGCODE(fEditorsAttached.store(0);) SkDEBUGCODE(this->validate();) } @@ -397,15 +396,20 @@ class SK_API SkPathRef final : public SkNVRefCnt { /** Makes additional room but does not change the counts or change the genID */ void incReserve(int additionalVerbs, int additionalPoints) { SkDEBUGCODE(this->validate();) - fPoints.reserve(fPoints.size() + additionalPoints); - fVerbs.reserve(fVerbs.size() + additionalVerbs); + // Use reserve() so that if there is not enough space, the array will grow with some + // additional space. This ensures repeated calls to grow won't always allocate. + if (additionalPoints > 0) + fPoints.reserve(fPoints.size() + additionalPoints); + if (additionalVerbs > 0) + fVerbs.reserve(fVerbs.size() + additionalVerbs); SkDEBUGCODE(this->validate();) } - /** Resets the path ref with verbCount verbs and pointCount points, all uninitialized. Also - * allocates space for reserveVerb additional verbs and reservePoints additional points.*/ - void resetToSize(int verbCount, int pointCount, int conicCount, - int reserveVerbs = 0, int reservePoints = 0) { + /** + * Resets all state except that of the verbs, points, and conic-weights. + * Intended to be called from other functions that reset state. + */ + void commonReset() { SkDEBUGCODE(this->validate();) this->callGenIDChangeListeners(); fBoundsIsDirty = true; // this also invalidates fIsFinite @@ -414,12 +418,25 @@ class SK_API SkPathRef final : public SkNVRefCnt { fSegmentMask = 0; fIsOval = false; fIsRRect = false; + } - fPoints.reserve(pointCount + reservePoints); - fPoints.resize(pointCount); - fVerbs.reserve(verbCount + reserveVerbs); - fVerbs.resize(verbCount); - fConicWeights.resize(conicCount); + /** Resets the path ref with verbCount verbs and pointCount points, all uninitialized. Also + * allocates space for reserveVerb additional verbs and reservePoints additional points.*/ + void resetToSize(int verbCount, int pointCount, int conicCount, + int reserveVerbs = 0, int reservePoints = 0) { + commonReset(); + // Use reserve_back() so the arrays are sized to exactly fit the data. + const int pointDelta = pointCount + reservePoints - fPoints.size(); + if (pointDelta > 0) { + fPoints.reserve_back(pointDelta); + } + fPoints.resize_back(pointCount); + const int verbDelta = verbCount + reserveVerbs - fVerbs.size(); + if (verbDelta > 0) { + fVerbs.reserve_back(verbDelta); + } + fVerbs.resize_back(verbCount); + fConicWeights.resize_back(conicCount); SkDEBUGCODE(this->validate();) } @@ -489,9 +506,9 @@ class SK_API SkPathRef final : public SkNVRefCnt { mutable SkRect fBounds; - SkTDArray fPoints; - SkTDArray fVerbs; - SkTDArray fConicWeights; + PointsArray fPoints; + VerbsArray fVerbs; + ConicWeightsArray fConicWeights; enum { kEmptyGenID = 1, // GenID reserved for path ref with zero points and zero verbs. diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h index 6e50a5b262594..058b231b138a3 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h @@ -11,7 +11,7 @@ #include #include "include/core/SkTypes.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" using SKSL_INT = int64_t; using SKSL_FLOAT = float; @@ -21,17 +21,17 @@ namespace SkSL { class Expression; class Statement; -using ComponentArray = SkSTArray<4, int8_t>; // for Swizzles +using ComponentArray = skia_private::STArray<4, int8_t>; // for Swizzles -class ExpressionArray : public SkSTArray<2, std::unique_ptr> { +class ExpressionArray : public skia_private::STArray<2, std::unique_ptr> { public: - using SkSTArray::SkSTArray; + using STArray::STArray; /** Returns a new ExpressionArray containing a clone of every element. */ ExpressionArray clone() const; }; -using StatementArray = SkSTArray<2, std::unique_ptr>; +using StatementArray = skia_private::STArray<2, std::unique_ptr>; // Functions larger than this (measured in IR nodes) will not be inlined. This growth factor // accounts for the number of calls being inlined--i.e., a function called five times (that is, with diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h deleted file mode 100644 index c11a56614c42b..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_IRNODE -#define SKSL_IRNODE - -#include "include/private/SkSLString.h" -#include "include/private/SkTArray.h" -#include "include/sksl/SkSLPosition.h" -#include "src/sksl/SkSLLexer.h" -#include "src/sksl/SkSLModifiersPool.h" -#include "src/sksl/SkSLPool.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Expression; -class FunctionDeclaration; -class FunctionDefinition; -class Statement; -class Symbol; -class SymbolTable; -class Type; -class Variable; -class VariableReference; -enum class VariableRefKind : int8_t; -enum class VariableStorage : int8_t; - -/** - * Represents a node in the intermediate representation (IR) tree. The IR is a fully-resolved - * version of the program (all types determined, everything validated), ready for code generation. - */ -class IRNode : public Poolable { -public: - virtual ~IRNode() {} - - virtual std::string description() const = 0; - - // No copy construction or assignment - IRNode(const IRNode&) = delete; - IRNode& operator=(const IRNode&) = delete; - - // position of this element within the program being compiled, for error reporting purposes - Position fPosition; - -protected: - IRNode(Position position, int kind) - : fPosition(position) - , fKind(kind) {} - - int fKind; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h deleted file mode 100644 index 1b00f0e7c67ed..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_LAYOUT -#define SKSL_LAYOUT - -#include "include/private/SkSLString.h" - -namespace SkSL { - -/** - * Represents a layout block appearing before a variable declaration, as in: - * - * layout (location = 0) int x; - */ -struct Layout { - enum Flag { - kOriginUpperLeft_Flag = 1 << 0, - kPushConstant_Flag = 1 << 1, - kBlendSupportAllEquations_Flag = 1 << 2, - kColor_Flag = 1 << 3, - - // These flags indicate if the qualifier appeared, regardless of the accompanying value. - kLocation_Flag = 1 << 4, - kOffset_Flag = 1 << 5, - kBinding_Flag = 1 << 6, - kIndex_Flag = 1 << 7, - kSet_Flag = 1 << 8, - kBuiltin_Flag = 1 << 9, - kInputAttachmentIndex_Flag = 1 << 10, - }; - - Layout(int flags, int location, int offset, int binding, int index, int set, int builtin, - int inputAttachmentIndex) - : fFlags(flags) - , fLocation(location) - , fOffset(offset) - , fBinding(binding) - , fIndex(index) - , fSet(set) - , fBuiltin(builtin) - , fInputAttachmentIndex(inputAttachmentIndex) {} - - Layout() - : fFlags(0) - , fLocation(-1) - , fOffset(-1) - , fBinding(-1) - , fIndex(-1) - , fSet(-1) - , fBuiltin(-1) - , fInputAttachmentIndex(-1) {} - - static Layout builtin(int builtin) { - Layout result; - result.fBuiltin = builtin; - return result; - } - - std::string description() const { - std::string result; - auto separator = [firstSeparator = true]() mutable -> std::string { - if (firstSeparator) { - firstSeparator = false; - return ""; - } else { - return ", "; - }}; - if (fLocation >= 0) { - result += separator() + "location = " + std::to_string(fLocation); - } - if (fOffset >= 0) { - result += separator() + "offset = " + std::to_string(fOffset); - } - if (fBinding >= 0) { - result += separator() + "binding = " + std::to_string(fBinding); - } - if (fIndex >= 0) { - result += separator() + "index = " + std::to_string(fIndex); - } - if (fSet >= 0) { - result += separator() + "set = " + std::to_string(fSet); - } - if (fBuiltin >= 0) { - result += separator() + "builtin = " + std::to_string(fBuiltin); - } - if (fInputAttachmentIndex >= 0) { - result += separator() + "input_attachment_index = " + - std::to_string(fInputAttachmentIndex); - } - if (fFlags & kOriginUpperLeft_Flag) { - result += separator() + "origin_upper_left"; - } - if (fFlags & kBlendSupportAllEquations_Flag) { - result += separator() + "blend_support_all_equations"; - } - if (fFlags & kPushConstant_Flag) { - result += separator() + "push_constant"; - } - if (fFlags & kColor_Flag) { - result += separator() + "color"; - } - if (result.size() > 0) { - result = "layout (" + result + ")"; - } - return result; - } - - bool operator==(const Layout& other) const { - return fFlags == other.fFlags && - fLocation == other.fLocation && - fOffset == other.fOffset && - fBinding == other.fBinding && - fIndex == other.fIndex && - fSet == other.fSet && - fBuiltin == other.fBuiltin && - fInputAttachmentIndex == other.fInputAttachmentIndex; - } - - bool operator!=(const Layout& other) const { - return !(*this == other); - } - - int fFlags; - int fLocation; - int fOffset; - int fBinding; - int fIndex; - int fSet; - // builtin comes from SPIR-V and identifies which particular builtin value this object - // represents. - int fBuiltin; - // input_attachment_index comes from Vulkan/SPIR-V to connect a shader variable to the a - // corresponding attachment on the subpass in which the shader is being used. - int fInputAttachmentIndex; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h deleted file mode 100644 index 732810b7da71c..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_MODIFIERS -#define SKSL_MODIFIERS - -#include "include/private/SkSLLayout.h" - -#include -#include -#include - -namespace SkSL { - -class Context; -class Position; - -/** - * A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration. - */ -struct Modifiers { - /** - * OpenGL requires modifiers to be in a strict order: - * - invariant-qualifier: (invariant) - * - interpolation-qualifier: flat, noperspective, (smooth) - * - storage-qualifier: const, uniform - * - parameter-qualifier: in, out, inout - * - precision-qualifier: highp, mediump, lowp - * - * SkSL does not have `invariant` or `smooth`. - */ - - enum Flag { - kNo_Flag = 0, - // Real GLSL modifiers - kFlat_Flag = 1 << 0, - kNoPerspective_Flag = 1 << 1, - kConst_Flag = 1 << 2, - kUniform_Flag = 1 << 3, - kIn_Flag = 1 << 4, - kOut_Flag = 1 << 5, - kHighp_Flag = 1 << 6, - kMediump_Flag = 1 << 7, - kLowp_Flag = 1 << 8, - kReadOnly_Flag = 1 << 9, - kWriteOnly_Flag = 1 << 10, - kBuffer_Flag = 1 << 11, - // We use the Metal name for this one (corresponds to the GLSL 'shared' modifier) - kThreadgroup_Flag = 1 << 12, - // SkSL extensions, not present in GLSL - kExport_Flag = 1 << 13, - kES3_Flag = 1 << 14, - kPure_Flag = 1 << 15, - kInline_Flag = 1 << 16, - kNoInline_Flag = 1 << 17, - }; - - Modifiers() - : fLayout(Layout()) - , fFlags(0) {} - - Modifiers(const Layout& layout, int flags) - : fLayout(layout) - , fFlags(flags) {} - - std::string description() const { - return fLayout.description() + DescribeFlags(fFlags) + " "; - } - - static std::string DescribeFlags(int flags) { - // SkSL extensions - std::string result; - if (flags & kExport_Flag) { - result += "$export "; - } - if (flags & kES3_Flag) { - result += "$es3 "; - } - if (flags & kPure_Flag) { - result += "$pure "; - } - if (flags & kInline_Flag) { - result += "inline "; - } - if (flags & kNoInline_Flag) { - result += "noinline "; - } - - // Real GLSL qualifiers (must be specified in order in GLSL 4.1 and below) - if (flags & kFlat_Flag) { - result += "flat "; - } - if (flags & kNoPerspective_Flag) { - result += "noperspective "; - } - if (flags & kConst_Flag) { - result += "const "; - } - if (flags & kUniform_Flag) { - result += "uniform "; - } - if ((flags & kIn_Flag) && (flags & kOut_Flag)) { - result += "inout "; - } else if (flags & kIn_Flag) { - result += "in "; - } else if (flags & kOut_Flag) { - result += "out "; - } - if (flags & kHighp_Flag) { - result += "highp "; - } - if (flags & kMediump_Flag) { - result += "mediump "; - } - if (flags & kLowp_Flag) { - result += "lowp "; - } - if (flags & kReadOnly_Flag) { - result += "readonly "; - } - if (flags & kWriteOnly_Flag) { - result += "writeonly "; - } - if (flags & kBuffer_Flag) { - result += "buffer "; - } - - // We're using a non-GLSL name for this one; the GLSL equivalent is "shared" - if (flags & kThreadgroup_Flag) { - result += "threadgroup "; - } - - if (!result.empty()) { - result.pop_back(); - } - return result; - } - - bool operator==(const Modifiers& other) const { - return fLayout == other.fLayout && fFlags == other.fFlags; - } - - bool operator!=(const Modifiers& other) const { - return !(*this == other); - } - - /** - * Verifies that only permitted modifiers and layout flags are included. Reports errors and - * returns false in the event of a violation. - */ - bool checkPermitted(const Context& context, - Position pos, - int permittedModifierFlags, - int permittedLayoutFlags) const; - - Layout fLayout; - int fFlags; -}; - -} // namespace SkSL - -namespace std { - -template <> -struct hash { - size_t operator()(const SkSL::Modifiers& key) const { - return (size_t) key.fFlags ^ ((size_t) key.fLayout.fFlags << 8) ^ - ((size_t) key.fLayout.fBuiltin << 16); - } -}; - -} // namespace std - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h deleted file mode 100644 index 8eb0a31aadab6..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_PROGRAMELEMENT -#define SKSL_PROGRAMELEMENT - -#include "include/private/SkSLIRNode.h" - -#include - -namespace SkSL { - -/** - * Represents a top-level element (e.g. function or global variable) in a program. - */ -class ProgramElement : public IRNode { -public: - enum class Kind { - kExtension = 0, - kFunction, - kFunctionPrototype, - kGlobalVar, - kInterfaceBlock, - kModifiers, - kStructDefinition, - - kFirst = kExtension, - kLast = kStructDefinition - }; - - ProgramElement(Position pos, Kind kind) - : INHERITED(pos, (int) kind) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - Kind kind() const { - return (Kind) fKind; - } - - /** - * Use is to check the type of a program element. - * e.g. replace `el.kind() == ProgramElement::Kind::kExtension` with `el.is()`. - */ - template - bool is() const { - return this->kind() == T::kProgramElementKind; - } - - /** - * Use as to downcast program elements. e.g. replace `(Extension&) el` with - * `el.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - - virtual std::unique_ptr clone() const = 0; - -private: - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h deleted file mode 100644 index c240cb7376e60..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSLProgramKind_DEFINED -#define SkSLProgramKind_DEFINED - -#include - -namespace SkSL { - -/** - * SkSL supports several different program kinds. - */ -enum class ProgramKind : int8_t { - kFragment, - kVertex, - kCompute, - kGraphiteFragment, - kGraphiteVertex, - kRuntimeColorFilter, // Runtime effect only suitable as SkColorFilter - kRuntimeShader, // " " " " " SkShader - kRuntimeBlender, // " " " " " SkBlender - kPrivateRuntimeShader, // Runtime shader with public restrictions lifted - kMeshVertex, // Vertex portion of a custom mesh - kMeshFragment, // Fragment " " " " " - kGeneric, -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h index a8d67a025a82d..39d9e258180e8 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h @@ -10,8 +10,6 @@ #include "include/core/SkTypes.h" -#include - namespace SkSL { /** @@ -77,8 +75,6 @@ class SampleUsage { bool isUniformMatrix() const { return fKind == Kind::kUniformMatrix; } bool isFragCoord() const { return fKind == Kind::kFragCoord; } - std::string constructor() const; - private: Kind fKind = Kind::kNone; bool fHasPerspective = false; // Only valid if fKind is kUniformMatrix diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h deleted file mode 100644 index 43a1fdc8f3757..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_STATEMENT -#define SKSL_STATEMENT - -#include "include/private/SkSLIRNode.h" -#include "include/private/SkSLSymbol.h" - -namespace SkSL { - -/** - * Abstract supertype of all statements. - */ -class Statement : public IRNode { -public: - enum Kind { - kBlock = (int) Symbol::Kind::kLast + 1, - kBreak, - kContinue, - kDiscard, - kDo, - kExpression, - kFor, - kIf, - kNop, - kReturn, - kSwitch, - kSwitchCase, - kVarDeclaration, - - kFirst = kBlock, - kLast = kVarDeclaration, - }; - - Statement(Position pos, Kind kind) - : INHERITED(pos, (int) kind) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - Kind kind() const { - return (Kind) fKind; - } - - /** - * Use is to check the type of a statement. - * e.g. replace `s.kind() == Statement::Kind::kReturn` with `s.is()`. - */ - template - bool is() const { - return this->fKind == T::kStatementKind; - } - - /** - * Use as to downcast statements. - * e.g. replace `(ReturnStatement&) s` with `s.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - - virtual bool isEmpty() const { - return false; - } - - virtual std::unique_ptr clone() const = 0; - -private: - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h deleted file mode 100644 index 4458a2f0f5b45..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_STRING -#define SKSL_STRING - -#include "include/core/SkTypes.h" -#include "include/private/SkSLDefines.h" - -#include -#include -#include - -namespace SkSL { - -bool stod(std::string_view s, SKSL_FLOAT* value); -bool stoi(std::string_view s, SKSL_INT* value); - -namespace String { - -std::string printf(const char* fmt, ...) SK_PRINTF_LIKE(1, 2); -void appendf(std::string* str, const char* fmt, ...) SK_PRINTF_LIKE(2, 3); -void vappendf(std::string* str, const char* fmt, va_list va) SK_PRINTF_LIKE(2, 0); - -} // namespace String -} // namespace SkSL - -namespace skstd { - -// We use a custom to_string(float|double) which ignores locale settings and writes `1.0` instead -// of `1.00000`. -std::string to_string(float value); -std::string to_string(double value); - -} // namespace skstd - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h deleted file mode 100644 index d7b40c8d11ae7..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_SYMBOL -#define SKSL_SYMBOL - -#include "include/private/SkSLIRNode.h" -#include "include/private/SkSLProgramElement.h" - -namespace SkSL { - -/** - * Represents a symboltable entry. - */ -class Symbol : public IRNode { -public: - enum class Kind { - kExternal = (int) ProgramElement::Kind::kLast + 1, - kField, - kFunctionDeclaration, - kType, - kVariable, - - kFirst = kExternal, - kLast = kVariable - }; - - Symbol(Position pos, Kind kind, std::string_view name, const Type* type = nullptr) - : INHERITED(pos, (int) kind) - , fName(name) - , fType(type) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - ~Symbol() override {} - - const Type& type() const { - SkASSERT(fType); - return *fType; - } - - Kind kind() const { - return (Kind) fKind; - } - - std::string_view name() const { - return fName; - } - - /** - * Don't call this directly--use SymbolTable::renameSymbol instead! - */ - void setName(std::string_view newName) { - fName = newName; - } - - /** - * Use is to check the type of a symbol. - * e.g. replace `sym.kind() == Symbol::Kind::kVariable` with `sym.is()`. - */ - template - bool is() const { - return this->kind() == T::kSymbolKind; - } - - /** - * Use as to downcast symbols. e.g. replace `(Variable&) sym` with `sym.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - -private: - std::string_view fName; - const Type* fType; - - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h deleted file mode 100644 index 144b28a4a3b3a..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSafe_math_DEFINED -#define SkSafe_math_DEFINED - -// This file protects against known bugs in ucrt\math.h. -// Namely, that header defines inline methods without marking them static, -// which makes it very easy to cause ODR violations and ensuing chaos. -// -// TODO: other headers? Here are some potential problem headers: -// $ grep -R __inline * | grep -v static | cut -f 1 -d: | sort | uniq -// corecrt.h -// corecrt_stdio_config.h -// ctype.h -// fenv.h -// locale.h -// malloc.h -// math.h -// tchar.h -// wchar.h -// I took a quick look through other headers outside math.h. -// Nothing looks anywhere near as likely to be used by Skia as math.h. - -#if defined(_MSC_VER) && !defined(_INC_MATH) - // Our strategy here is to simply inject "static" into the headers - // where it should have been written, just before __inline. - // - // Most inline-but-not-static methods in math.h are 32-bit only, - // but not all of them (see frexpf, hypothf, ldexpf...). So to - // be safe, 32- and 64-bit builds both get this treatment. - - #define __inline static __inline - #include - #undef __inline - - #if !defined(_INC_MATH) - #error Hmm. Looks like math.h has changed its header guards. - #endif - - #define INC_MATH_IS_SAFE_NOW - -#else - #include - -#endif - -#endif//SkSafe_math_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h index e1d5011681e5f..3816dc9dff022 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h @@ -9,7 +9,7 @@ #define SkSpinlock_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkThreadAnnotations.h" #include class SK_CAPABILITY("mutex") SkSpinlock { diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h deleted file mode 100644 index bf2f3da25eb60..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkStringView_DEFINED -#define SkStringView_DEFINED - -#include -#include - -namespace skstd { - -// C++20 additions -inline constexpr bool starts_with(std::string_view str, std::string_view prefix) { - if (prefix.length() > str.length()) { - return false; - } - return prefix.length() == 0 || !memcmp(str.data(), prefix.data(), prefix.length()); -} - -inline constexpr bool starts_with(std::string_view str, std::string_view::value_type c) { - return !str.empty() && str.front() == c; -} - -inline constexpr bool ends_with(std::string_view str, std::string_view suffix) { - if (suffix.length() > str.length()) { - return false; - } - return suffix.length() == 0 || !memcmp(str.data() + str.length() - suffix.length(), - suffix.data(), suffix.length()); -} - -inline constexpr bool ends_with(std::string_view str, std::string_view::value_type c) { - return !str.empty() && str.back() == c; -} - -// C++23 additions -inline constexpr bool contains(std::string_view str, std::string_view needle) { - return str.find(needle) != std::string_view::npos; -} - -inline constexpr bool contains(std::string_view str, std::string_view::value_type c) { - return str.find(c) != std::string_view::npos; -} - -} // namespace skstd - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h deleted file mode 100644 index 5082669c4f3d6..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h +++ /dev/null @@ -1,655 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkTArray_DEFINED -#define SkTArray_DEFINED - -#include "include/core/SkMath.h" -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkSafe32.h" -#include "include/private/SkTLogic.h" -#include "include/private/SkTemplates.h" -#include "include/private/SkTo.h" - -#include -#include -#include -#include -#include -#include - -/** SkTArray implements a typical, mostly std::vector-like array. - Each T will be default-initialized on allocation, and ~T will be called on destruction. - - MEM_MOVE controls the behavior when a T needs to be moved (e.g. when the array is resized) - - true: T will be bit-copied via memcpy. - - false: T will be moved via move-constructors. - - Modern implementations of std::vector will generally provide similar performance - characteristics when used with appropriate care. Consider using std::vector in new code. -*/ -template ::value> class SkTArray { -private: - enum ReallocType { kExactFit, kGrowing, kShrinking }; - -public: - using value_type = T; - - /** - * Creates an empty array with no initial storage - */ - SkTArray() { this->init(0); } - - /** - * Creates an empty array that will preallocate space for reserveCount - * elements. - */ - explicit SkTArray(int reserveCount) : SkTArray() { this->reserve_back(reserveCount); } - - /** - * Copies one array to another. The new array will be heap allocated. - */ - SkTArray(const SkTArray& that) - : SkTArray(that.fItemArray, that.fCount) {} - - SkTArray(SkTArray&& that) { - if (that.fOwnMemory) { - fItemArray = that.fItemArray; - fCount = that.fCount; - fAllocCount = that.fAllocCount; - fOwnMemory = true; - fReserved = that.fReserved; - - that.fItemArray = nullptr; - that.fCount = 0; - that.fAllocCount = 0; - that.fOwnMemory = true; - that.fReserved = false; - } else { - this->init(that.fCount); - that.move(fItemArray); - that.fCount = 0; - } - } - - /** - * Creates a SkTArray by copying contents of a standard C array. The new - * array will be heap allocated. Be careful not to use this constructor - * when you really want the (void*, int) version. - */ - SkTArray(const T* array, int count) { - this->init(count); - this->copy(array); - } - /** - * Creates a SkTArray by copying contents of an initializer list. - */ - SkTArray(std::initializer_list data) - : SkTArray(data.begin(), data.size()) {} - - SkTArray& operator=(const SkTArray& that) { - if (this == &that) { - return *this; - } - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(that.count(), kExactFit); - fCount = that.fCount; - this->copy(that.fItemArray); - return *this; - } - SkTArray& operator=(SkTArray&& that) { - if (this == &that) { - return *this; - } - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(that.count(), kExactFit); - fCount = that.fCount; - that.move(fItemArray); - that.fCount = 0; - return *this; - } - - ~SkTArray() { - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - if (fOwnMemory) { - sk_free(fItemArray); - } - } - - /** - * Resets to count() == 0 and resets any reserve count. - */ - void reset() { - this->pop_back_n(fCount); - fReserved = false; - } - - /** - * Resets to count() = n newly constructed T objects and resets any reserve count. - */ - void reset(int n) { - SkASSERT(n >= 0); - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - // Set fCount to 0 before calling checkRealloc so that no elements are moved. - fCount = 0; - this->checkRealloc(n, kExactFit); - fCount = n; - for (int i = 0; i < this->count(); ++i) { - new (fItemArray + i) T; - } - fReserved = false; - } - - /** - * Resets to a copy of a C array and resets any reserve count. - */ - void reset(const T* array, int count) { - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(count, kExactFit); - fCount = count; - this->copy(array); - fReserved = false; - } - - /** - * Ensures there is enough reserved space for n additional elements. The is guaranteed at least - * until the array size grows above n and subsequently shrinks below n, any version of reset() - * is called, or reserve_back() is called again. - */ - void reserve_back(int n) { - SkASSERT(n >= 0); - if (n > 0) { - this->checkRealloc(n, kExactFit); - fReserved = fOwnMemory; - } else { - fReserved = false; - } - } - - void removeShuffle(int n) { - SkASSERT(n < this->count()); - int newCount = fCount - 1; - fCount = newCount; - fItemArray[n].~T(); - if (n != newCount) { - this->move(n, newCount); - } - } - - /** - * Number of elements in the array. - */ - int count() const { return fCount; } - - /** - * Is the array empty. - */ - bool empty() const { return !fCount; } - - /** - * Adds 1 new default-initialized T value and returns it by reference. Note - * the reference only remains valid until the next call that adds or removes - * elements. - */ - T& push_back() { - void* newT = this->push_back_raw(1); - return *new (newT) T; - } - - /** - * Version of above that uses a copy constructor to initialize the new item - */ - T& push_back(const T& t) { - void* newT = this->push_back_raw(1); - return *new (newT) T(t); - } - - /** - * Version of above that uses a move constructor to initialize the new item - */ - T& push_back(T&& t) { - void* newT = this->push_back_raw(1); - return *new (newT) T(std::move(t)); - } - - /** - * Construct a new T at the back of this array. - */ - template T& emplace_back(Args&&... args) { - void* newT = this->push_back_raw(1); - return *new (newT) T(std::forward(args)...); - } - - /** - * Allocates n more default-initialized T values, and returns the address of - * the start of that new range. Note: this address is only valid until the - * next API call made on the array that might add or remove elements. - */ - T* push_back_n(int n) { - SkASSERT(n >= 0); - void* newTs = this->push_back_raw(n); - for (int i = 0; i < n; ++i) { - new (static_cast(newTs) + i * sizeof(T)) T; - } - return static_cast(newTs); - } - - /** - * Version of above that uses a copy constructor to initialize all n items - * to the same T. - */ - T* push_back_n(int n, const T& t) { - SkASSERT(n >= 0); - void* newTs = this->push_back_raw(n); - for (int i = 0; i < n; ++i) { - new (static_cast(newTs) + i * sizeof(T)) T(t); - } - return static_cast(newTs); - } - - /** - * Version of above that uses a copy constructor to initialize the n items - * to separate T values. - */ - T* push_back_n(int n, const T t[]) { - SkASSERT(n >= 0); - this->checkRealloc(n, kGrowing); - for (int i = 0; i < n; ++i) { - new (fItemArray + fCount + i) T(t[i]); - } - fCount += n; - return fItemArray + fCount - n; - } - - /** - * Version of above that uses the move constructor to set n items. - */ - T* move_back_n(int n, T* t) { - SkASSERT(n >= 0); - this->checkRealloc(n, kGrowing); - for (int i = 0; i < n; ++i) { - new (fItemArray + fCount + i) T(std::move(t[i])); - } - fCount += n; - return fItemArray + fCount - n; - } - - /** - * Removes the last element. Not safe to call when count() == 0. - */ - void pop_back() { - SkASSERT(fCount > 0); - --fCount; - fItemArray[fCount].~T(); - this->checkRealloc(0, kShrinking); - } - - /** - * Removes the last n elements. Not safe to call when count() < n. - */ - void pop_back_n(int n) { - SkASSERT(n >= 0); - SkASSERT(this->count() >= n); - fCount -= n; - for (int i = 0; i < n; ++i) { - fItemArray[fCount + i].~T(); - } - this->checkRealloc(0, kShrinking); - } - - /** - * Pushes or pops from the back to resize. Pushes will be default - * initialized. - */ - void resize_back(int newCount) { - SkASSERT(newCount >= 0); - - if (newCount > this->count()) { - this->push_back_n(newCount - fCount); - } else if (newCount < this->count()) { - this->pop_back_n(fCount - newCount); - } - } - - /** Swaps the contents of this array with that array. Does a pointer swap if possible, - otherwise copies the T values. */ - void swap(SkTArray& that) { - using std::swap; - if (this == &that) { - return; - } - if (fOwnMemory && that.fOwnMemory) { - swap(fItemArray, that.fItemArray); - - auto count = fCount; - fCount = that.fCount; - that.fCount = count; - - auto allocCount = fAllocCount; - fAllocCount = that.fAllocCount; - that.fAllocCount = allocCount; - } else { - // This could be more optimal... - SkTArray copy(std::move(that)); - that = std::move(*this); - *this = std::move(copy); - } - } - - T* begin() { - return fItemArray; - } - const T* begin() const { - return fItemArray; - } - T* end() { - return fItemArray ? fItemArray + fCount : nullptr; - } - const T* end() const { - return fItemArray ? fItemArray + fCount : nullptr; - } - T* data() { return fItemArray; } - const T* data() const { return fItemArray; } - size_t size() const { return (size_t)fCount; } - void resize(size_t count) { this->resize_back((int)count); } - - /** - * Get the i^th element. - */ - T& operator[] (int i) { - SkASSERT(i < this->count()); - SkASSERT(i >= 0); - return fItemArray[i]; - } - - const T& operator[] (int i) const { - SkASSERT(i < this->count()); - SkASSERT(i >= 0); - return fItemArray[i]; - } - - T& at(int i) { return (*this)[i]; } - const T& at(int i) const { return (*this)[i]; } - - /** - * equivalent to operator[](0) - */ - T& front() { SkASSERT(fCount > 0); return fItemArray[0];} - - const T& front() const { SkASSERT(fCount > 0); return fItemArray[0];} - - /** - * equivalent to operator[](count() - 1) - */ - T& back() { SkASSERT(fCount); return fItemArray[fCount - 1];} - - const T& back() const { SkASSERT(fCount > 0); return fItemArray[fCount - 1];} - - /** - * equivalent to operator[](count()-1-i) - */ - T& fromBack(int i) { - SkASSERT(i >= 0); - SkASSERT(i < this->count()); - return fItemArray[fCount - i - 1]; - } - - const T& fromBack(int i) const { - SkASSERT(i >= 0); - SkASSERT(i < this->count()); - return fItemArray[fCount - i - 1]; - } - - bool operator==(const SkTArray& right) const { - int leftCount = this->count(); - if (leftCount != right.count()) { - return false; - } - for (int index = 0; index < leftCount; ++index) { - if (fItemArray[index] != right.fItemArray[index]) { - return false; - } - } - return true; - } - - bool operator!=(const SkTArray& right) const { - return !(*this == right); - } - - int capacity() const { - return fAllocCount; - } - -protected: - /** - * Creates an empty array that will use the passed storage block until it - * is insufficiently large to hold the entire array. - */ - template - SkTArray(SkAlignedSTStorage* storage) { - this->initWithPreallocatedStorage(0, storage->get(), N); - } - - /** - * Copy a C array, using preallocated storage if preAllocCount >= - * count. Otherwise storage will only be used when array shrinks - * to fit. - */ - template - SkTArray(const T* array, int count, SkAlignedSTStorage* storage) { - this->initWithPreallocatedStorage(count, storage->get(), N); - this->copy(array); - } - -private: - // We disable Control-Flow Integrity sanitization (go/cfi) when casting item-array buffers. - // CFI flags this code as dangerous because we are casting `buffer` to a T* while the buffer's - // contents might still be uninitialized memory. When T has a vtable, this is especially risky - // because we could hypothetically access a virtual method on fItemArray and jump to an - // unpredictable location in memory. Of course, SkTArray won't actually use fItemArray in this - // way, and we don't want to construct a T before the user requests one. There's no real risk - // here, so disable CFI when doing these casts. - SK_ATTRIBUTE(no_sanitize("cfi")) - static T* TCast(void* buffer) { - return (T*)buffer; - } - - void init(int count) { - fCount = SkToU32(count); - if (!count) { - fAllocCount = 0; - fItemArray = nullptr; - } else { - fAllocCount = SkToU32(std::max(count, kMinHeapAllocCount)); - fItemArray = TCast(sk_malloc_throw((size_t)fAllocCount, sizeof(T))); - } - fOwnMemory = true; - fReserved = false; - } - - void initWithPreallocatedStorage(int count, void* preallocStorage, int preallocCount) { - SkASSERT(count >= 0); - SkASSERT(preallocCount > 0); - SkASSERT(preallocStorage); - fCount = SkToU32(count); - fItemArray = nullptr; - fReserved = false; - if (count > preallocCount) { - fAllocCount = SkToU32(std::max(count, kMinHeapAllocCount)); - fItemArray = TCast(sk_malloc_throw(fAllocCount, sizeof(T))); - fOwnMemory = true; - } else { - fAllocCount = SkToU32(preallocCount); - fItemArray = TCast(preallocStorage); - fOwnMemory = false; - } - } - - /** In the following move and copy methods, 'dst' is assumed to be uninitialized raw storage. - * In the following move methods, 'src' is destroyed leaving behind uninitialized raw storage. - */ - void copy(const T* src) { - // Some types may be trivially copyable, in which case we *could* use memcopy; but - // MEM_MOVE == true implies that the type is trivially movable, and not necessarily - // trivially copyable (think sk_sp<>). So short of adding another template arg, we - // must be conservative and use copy construction. - for (int i = 0; i < this->count(); ++i) { - new (fItemArray + i) T(src[i]); - } - } - - template std::enable_if_t move(int dst, int src) { - memcpy(static_cast(&fItemArray[dst]), - static_cast(&fItemArray[src]), - sizeof(T)); - } - template std::enable_if_t move(void* dst) { - sk_careful_memcpy(dst, fItemArray, fCount * sizeof(T)); - } - - template std::enable_if_t move(int dst, int src) { - new (&fItemArray[dst]) T(std::move(fItemArray[src])); - fItemArray[src].~T(); - } - template std::enable_if_t move(void* dst) { - for (int i = 0; i < this->count(); ++i) { - new (static_cast(dst) + sizeof(T) * (size_t)i) T(std::move(fItemArray[i])); - fItemArray[i].~T(); - } - } - - static constexpr int kMinHeapAllocCount = 8; - - // Helper function that makes space for n objects, adjusts the count, but does not initialize - // the new objects. - void* push_back_raw(int n) { - this->checkRealloc(n, kGrowing); - void* ptr = fItemArray + fCount; - fCount += n; - return ptr; - } - - void checkRealloc(int delta, ReallocType reallocType) { - SkASSERT(fCount >= 0); - SkASSERT(fAllocCount >= 0); - SkASSERT(-delta <= this->count()); - - // Move into 64bit math temporarily, to avoid local overflows - int64_t newCount = fCount + delta; - - // We allow fAllocCount to be in the range [newCount, 3*newCount]. We also never shrink - // when we're currently using preallocated memory, would allocate less than - // kMinHeapAllocCount, or a reserve count was specified that has yet to be exceeded. - bool mustGrow = newCount > fAllocCount; - bool shouldShrink = fAllocCount > 3 * newCount && fOwnMemory && !fReserved; - if (!mustGrow && !shouldShrink) { - return; - } - - int64_t newAllocCount = newCount; - if (reallocType != kExactFit) { - // Whether we're growing or shrinking, leave at least 50% extra space for future growth. - newAllocCount += ((newCount + 1) >> 1); - // Align the new allocation count to kMinHeapAllocCount. - static_assert(SkIsPow2(kMinHeapAllocCount), "min alloc count not power of two."); - newAllocCount = (newAllocCount + (kMinHeapAllocCount - 1)) & ~(kMinHeapAllocCount - 1); - } - - // At small sizes the old and new alloc count can both be kMinHeapAllocCount. - if (newAllocCount == fAllocCount) { - return; - } - - fAllocCount = SkToU32(Sk64_pin_to_s32(newAllocCount)); - SkASSERT(fAllocCount >= newCount); - T* newItemArray = TCast(sk_malloc_throw((size_t)fAllocCount, sizeof(T))); - this->move(newItemArray); - if (fOwnMemory) { - sk_free(fItemArray); - } - fItemArray = newItemArray; - fOwnMemory = true; - fReserved = false; - } - - T* fItemArray; - uint32_t fOwnMemory : 1; - uint32_t fCount : 31; - uint32_t fReserved : 1; - uint32_t fAllocCount : 31; -}; - -template static inline void swap(SkTArray& a, SkTArray& b) { - a.swap(b); -} - -template constexpr int SkTArray::kMinHeapAllocCount; - -/** - * Subclass of SkTArray that contains a preallocated memory block for the array. - */ -template ::value> -class SkSTArray : private SkAlignedSTStorage, public SkTArray { -private: - using STORAGE = SkAlignedSTStorage; - using INHERITED = SkTArray; - -public: - SkSTArray() - : STORAGE{}, INHERITED(static_cast(this)) {} - - SkSTArray(const T* array, int count) - : STORAGE{}, INHERITED(array, count, static_cast(this)) {} - - SkSTArray(std::initializer_list data) - : SkSTArray(data.begin(), data.size()) {} - - explicit SkSTArray(int reserveCount) - : SkSTArray() { - this->reserve_back(reserveCount); - } - - SkSTArray (const SkSTArray& that) : SkSTArray() { *this = that; } - explicit SkSTArray(const INHERITED& that) : SkSTArray() { *this = that; } - SkSTArray ( SkSTArray&& that) : SkSTArray() { *this = std::move(that); } - explicit SkSTArray( INHERITED&& that) : SkSTArray() { *this = std::move(that); } - - SkSTArray& operator=(const SkSTArray& that) { - INHERITED::operator=(that); - return *this; - } - SkSTArray& operator=(const INHERITED& that) { - INHERITED::operator=(that); - return *this; - } - - SkSTArray& operator=(SkSTArray&& that) { - INHERITED::operator=(std::move(that)); - return *this; - } - SkSTArray& operator=(INHERITED&& that) { - INHERITED::operator=(std::move(that)); - return *this; - } -}; - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h deleted file mode 100644 index 2cd89fd2f4df5..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 SkUniquePaintParamsID_DEFINED -#define SkUniquePaintParamsID_DEFINED - -#include "include/core/SkTypes.h" - -// This class boils down to a unique uint that can be used instead of a variable length -// key derived from a PaintParams. -class SkUniquePaintParamsID { -public: - explicit SkUniquePaintParamsID(uint32_t id) : fID(id) { - SkASSERT(id != SK_InvalidUniqueID); - } - - static SkUniquePaintParamsID InvalidID() { return SkUniquePaintParamsID(); } - - SkUniquePaintParamsID() : fID(SK_InvalidUniqueID) {} - - bool operator==(const SkUniquePaintParamsID &that) const { return fID == that.fID; } - bool operator!=(const SkUniquePaintParamsID &that) const { return !(*this == that); } - - bool isValid() const { return fID != SK_InvalidUniqueID; } - uint32_t asUInt() const { return fID; } - -private: - uint32_t fID; -}; - -#endif // SkUniquePaintParamsID_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h deleted file mode 100644 index 74cdabffe2d0c..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h +++ /dev/null @@ -1,1026 +0,0 @@ -/* - * Copyright 2019 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKVX_DEFINED -#define SKVX_DEFINED - -// skvx::Vec are SIMD vectors of N T's, a v1.5 successor to SkNx. -// -// This time we're leaning a bit less on platform-specific intrinsics and a bit -// more on Clang/GCC vector extensions, but still keeping the option open to -// drop in platform-specific intrinsics, actually more easily than before. -// -// We've also fixed a few of the caveats that used to make SkNx awkward to work -// with across translation units. skvx::Vec always has N*sizeof(T) size -// and alignment and is safe to use across translation units freely. -// (Ideally we'd only align to T, but that tanks ARMv7 NEON codegen.) - -// Please try to keep this file independent of Skia headers. -#include // std::min, std::max -#include // assert() -#include // ceilf, floorf, truncf, roundf, sqrtf, etc. -#include // intXX_t -#include // memcpy() -#include // std::initializer_list -#include // std::index_sequence - -// Users may disable SIMD with SKNX_NO_SIMD, which may be set via compiler flags. -// The gn build has no option which sets SKNX_NO_SIMD. -// Use SKVX_USE_SIMD internally to avoid confusing double negation. -// Do not use 'defined' in a macro expansion. -#if !defined(SKNX_NO_SIMD) - #define SKVX_USE_SIMD 1 -#else - #define SKVX_USE_SIMD 0 -#endif - -#if SKVX_USE_SIMD - #if defined(__SSE__) || defined(__AVX__) || defined(__AVX2__) - #include - #elif defined(__ARM_NEON) - #include - #elif defined(__wasm_simd128__) - #include - #endif -#endif - -// To avoid ODR violations, all methods must be force-inlined... -#if defined(_MSC_VER) - #define SKVX_ALWAYS_INLINE __forceinline -#else - #define SKVX_ALWAYS_INLINE __attribute__((always_inline)) -#endif - -// ... and all standalone functions must be static. Please use these helpers: -#define SI static inline -#define SIT template < typename T> SI -#define SIN template SI -#define SINT template SI -#define SINTU template ::value>> SI - -namespace skvx { - -template -struct alignas(N*sizeof(T)) Vec; - -template -SI Vec shuffle(const Vec&); - -template -SI D bit_pun(const S&); - -// All Vec have the same simple memory layout, the same as `T vec[N]`. -template -struct alignas(N*sizeof(T)) VecStorage { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - - Vec lo, hi; -}; - -template -struct VecStorage<4,T> { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y, T z, T w) : lo(x,y), hi(z, w) {} - SKVX_ALWAYS_INLINE VecStorage(Vec<2,T> xy, T z, T w) : lo(xy), hi(z,w) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y, Vec<2,T> zw) : lo(x,y), hi(zw) {} - SKVX_ALWAYS_INLINE VecStorage(Vec<2,T> xy, Vec<2,T> zw) : lo(xy), hi(zw) {} - - SKVX_ALWAYS_INLINE Vec<2,T>& xy() { return lo; } - SKVX_ALWAYS_INLINE Vec<2,T>& zw() { return hi; } - SKVX_ALWAYS_INLINE T& x() { return lo.lo.val; } - SKVX_ALWAYS_INLINE T& y() { return lo.hi.val; } - SKVX_ALWAYS_INLINE T& z() { return hi.lo.val; } - SKVX_ALWAYS_INLINE T& w() { return hi.hi.val; } - - SKVX_ALWAYS_INLINE Vec<2,T> xy() const { return lo; } - SKVX_ALWAYS_INLINE Vec<2,T> zw() const { return hi; } - SKVX_ALWAYS_INLINE T x() const { return lo.lo.val; } - SKVX_ALWAYS_INLINE T y() const { return lo.hi.val; } - SKVX_ALWAYS_INLINE T z() const { return hi.lo.val; } - SKVX_ALWAYS_INLINE T w() const { return hi.hi.val; } - - // Exchange-based swizzles. These should take 1 cycle on NEON and 3 (pipelined) cycles on SSE. - SKVX_ALWAYS_INLINE Vec<4,T> yxwz() const { return shuffle<1,0,3,2>(bit_pun>(*this)); } - SKVX_ALWAYS_INLINE Vec<4,T> zwxy() const { return shuffle<2,3,0,1>(bit_pun>(*this)); } - - Vec<2,T> lo, hi; -}; - -template -struct VecStorage<2,T> { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y) : lo(x), hi(y) {} - - SKVX_ALWAYS_INLINE T& x() { return lo.val; } - SKVX_ALWAYS_INLINE T& y() { return hi.val; } - - SKVX_ALWAYS_INLINE T x() const { return lo.val; } - SKVX_ALWAYS_INLINE T y() const { return hi.val; } - - // This exchange-based swizzle should take 1 cycle on NEON and 3 (pipelined) cycles on SSE. - SKVX_ALWAYS_INLINE Vec<2,T> yx() const { return shuffle<1,0>(bit_pun>(*this)); } - - SKVX_ALWAYS_INLINE Vec<4,T> xyxy() const { - return Vec<4,T>(bit_pun>(*this), bit_pun>(*this)); - } - - Vec<1,T> lo, hi; -}; - -template -struct alignas(N*sizeof(T)) Vec : public VecStorage { - static_assert((N & (N-1)) == 0, "N must be a power of 2."); - static_assert(sizeof(T) >= alignof(T), "What kind of unusual T is this?"); - - // Methods belong here in the class declaration of Vec only if: - // - they must be here, like constructors or operator[]; - // - they'll definitely never want a specialized implementation. - // Other operations on Vec should be defined outside the type. - - SKVX_ALWAYS_INLINE Vec() = default; - - using VecStorage::VecStorage; - - // NOTE: Vec{x} produces x000..., whereas Vec(x) produces xxxx.... since this constructor fills - // unspecified lanes with 0s, whereas the single T constructor fills all lanes with the value. - SKVX_ALWAYS_INLINE Vec(std::initializer_list xs) { - T vals[N] = {0}; - memcpy(vals, xs.begin(), std::min(xs.size(), (size_t)N)*sizeof(T)); - - this->lo = Vec::Load(vals + 0); - this->hi = Vec::Load(vals + N/2); - } - - SKVX_ALWAYS_INLINE T operator[](int i) const { return ilo[i] : this->hi[i-N/2]; } - SKVX_ALWAYS_INLINE T& operator[](int i) { return ilo[i] : this->hi[i-N/2]; } - - SKVX_ALWAYS_INLINE static Vec Load(const void* ptr) { - Vec v; - memcpy(&v, ptr, sizeof(Vec)); - return v; - } - SKVX_ALWAYS_INLINE void store(void* ptr) const { - memcpy(ptr, this, sizeof(Vec)); - } -}; - -template -struct Vec<1,T> { - T val; - - SKVX_ALWAYS_INLINE Vec() = default; - - Vec(T s) : val(s) {} - - SKVX_ALWAYS_INLINE Vec(std::initializer_list xs) : val(xs.size() ? *xs.begin() : 0) {} - - SKVX_ALWAYS_INLINE T operator[](int) const { return val; } - SKVX_ALWAYS_INLINE T& operator[](int) { return val; } - - SKVX_ALWAYS_INLINE static Vec Load(const void* ptr) { - Vec v; - memcpy(&v, ptr, sizeof(Vec)); - return v; - } - SKVX_ALWAYS_INLINE void store(void* ptr) const { - memcpy(ptr, this, sizeof(Vec)); - } -}; - -template -SI D bit_pun(const S& s) { - static_assert(sizeof(D) == sizeof(S)); - D d; - memcpy(&d, &s, sizeof(D)); - return d; -} - -// Translate from a value type T to its corresponding Mask, the result of a comparison. -template struct Mask { using type = T; }; -template <> struct Mask { using type = int32_t; }; -template <> struct Mask { using type = int64_t; }; -template using M = typename Mask::type; - -// Join two Vec into one Vec<2N,T>. -SINT Vec<2*N,T> join(const Vec& lo, const Vec& hi) { - Vec<2*N,T> v; - v.lo = lo; - v.hi = hi; - return v; -} - -// We have three strategies for implementing Vec operations: -// 1) lean on Clang/GCC vector extensions when available; -// 2) use map() to apply a scalar function lane-wise; -// 3) recurse on lo/hi to scalar portable implementations. -// We can slot in platform-specific implementations as overloads for particular Vec, -// or often integrate them directly into the recursion of style 3), allowing fine control. - -#if SKVX_USE_SIMD && (defined(__clang__) || defined(__GNUC__)) - - // VExt types have the same size as Vec and support most operations directly. - #if defined(__clang__) - template - using VExt = T __attribute__((ext_vector_type(N))); - - #elif defined(__GNUC__) - template - struct VExtHelper { - typedef T __attribute__((vector_size(N*sizeof(T)))) type; - }; - - template - using VExt = typename VExtHelper::type; - - // For some reason some (new!) versions of GCC cannot seem to deduce N in the generic - // to_vec() below for N=4 and T=float. This workaround seems to help... - SI Vec<4,float> to_vec(VExt<4,float> v) { return bit_pun>(v); } - #endif - - SINT VExt to_vext(const Vec& v) { return bit_pun>(v); } - SINT Vec to_vec(const VExt& v) { return bit_pun>(v); } - - SINT Vec operator+(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) + to_vext(y)); - } - SINT Vec operator-(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) - to_vext(y)); - } - SINT Vec operator*(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) * to_vext(y)); - } - SINT Vec operator/(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) / to_vext(y)); - } - - SINT Vec operator^(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) ^ to_vext(y)); - } - SINT Vec operator&(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) & to_vext(y)); - } - SINT Vec operator|(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) | to_vext(y)); - } - - SINT Vec operator!(const Vec& x) { return to_vec(!to_vext(x)); } - SINT Vec operator-(const Vec& x) { return to_vec(-to_vext(x)); } - SINT Vec operator~(const Vec& x) { return to_vec(~to_vext(x)); } - - SINT Vec operator<<(const Vec& x, int k) { return to_vec(to_vext(x) << k); } - SINT Vec operator>>(const Vec& x, int k) { return to_vec(to_vext(x) >> k); } - - SINT Vec> operator==(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) == to_vext(y)); - } - SINT Vec> operator!=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) != to_vext(y)); - } - SINT Vec> operator<=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) <= to_vext(y)); - } - SINT Vec> operator>=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) >= to_vext(y)); - } - SINT Vec> operator< (const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) < to_vext(y)); - } - SINT Vec> operator> (const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) > to_vext(y)); - } - -#else - - // Either SKNX_NO_SIMD is defined, or Clang/GCC vector extensions are not available. - // We'll implement things portably with N==1 scalar implementations and recursion onto them. - - // N == 1 scalar implementations. - SIT Vec<1,T> operator+(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val + y.val; } - SIT Vec<1,T> operator-(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val - y.val; } - SIT Vec<1,T> operator*(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val * y.val; } - SIT Vec<1,T> operator/(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val / y.val; } - - SIT Vec<1,T> operator^(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val ^ y.val; } - SIT Vec<1,T> operator&(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val & y.val; } - SIT Vec<1,T> operator|(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val | y.val; } - - SIT Vec<1,T> operator!(const Vec<1,T>& x) { return !x.val; } - SIT Vec<1,T> operator-(const Vec<1,T>& x) { return -x.val; } - SIT Vec<1,T> operator~(const Vec<1,T>& x) { return ~x.val; } - - SIT Vec<1,T> operator<<(const Vec<1,T>& x, int k) { return x.val << k; } - SIT Vec<1,T> operator>>(const Vec<1,T>& x, int k) { return x.val >> k; } - - SIT Vec<1,M> operator==(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val == y.val ? ~0 : 0; - } - SIT Vec<1,M> operator!=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val != y.val ? ~0 : 0; - } - SIT Vec<1,M> operator<=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val <= y.val ? ~0 : 0; - } - SIT Vec<1,M> operator>=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val >= y.val ? ~0 : 0; - } - SIT Vec<1,M> operator< (const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val < y.val ? ~0 : 0; - } - SIT Vec<1,M> operator> (const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val > y.val ? ~0 : 0; - } - - // Recurse on lo/hi down to N==1 scalar implementations. - SINT Vec operator+(const Vec& x, const Vec& y) { - return join(x.lo + y.lo, x.hi + y.hi); - } - SINT Vec operator-(const Vec& x, const Vec& y) { - return join(x.lo - y.lo, x.hi - y.hi); - } - SINT Vec operator*(const Vec& x, const Vec& y) { - return join(x.lo * y.lo, x.hi * y.hi); - } - SINT Vec operator/(const Vec& x, const Vec& y) { - return join(x.lo / y.lo, x.hi / y.hi); - } - - SINT Vec operator^(const Vec& x, const Vec& y) { - return join(x.lo ^ y.lo, x.hi ^ y.hi); - } - SINT Vec operator&(const Vec& x, const Vec& y) { - return join(x.lo & y.lo, x.hi & y.hi); - } - SINT Vec operator|(const Vec& x, const Vec& y) { - return join(x.lo | y.lo, x.hi | y.hi); - } - - SINT Vec operator!(const Vec& x) { return join(!x.lo, !x.hi); } - SINT Vec operator-(const Vec& x) { return join(-x.lo, -x.hi); } - SINT Vec operator~(const Vec& x) { return join(~x.lo, ~x.hi); } - - SINT Vec operator<<(const Vec& x, int k) { return join(x.lo << k, x.hi << k); } - SINT Vec operator>>(const Vec& x, int k) { return join(x.lo >> k, x.hi >> k); } - - SINT Vec> operator==(const Vec& x, const Vec& y) { - return join(x.lo == y.lo, x.hi == y.hi); - } - SINT Vec> operator!=(const Vec& x, const Vec& y) { - return join(x.lo != y.lo, x.hi != y.hi); - } - SINT Vec> operator<=(const Vec& x, const Vec& y) { - return join(x.lo <= y.lo, x.hi <= y.hi); - } - SINT Vec> operator>=(const Vec& x, const Vec& y) { - return join(x.lo >= y.lo, x.hi >= y.hi); - } - SINT Vec> operator< (const Vec& x, const Vec& y) { - return join(x.lo < y.lo, x.hi < y.hi); - } - SINT Vec> operator> (const Vec& x, const Vec& y) { - return join(x.lo > y.lo, x.hi > y.hi); - } -#endif - -// Scalar/vector operations splat the scalar to a vector. -SINTU Vec operator+ (U x, const Vec& y) { return Vec(x) + y; } -SINTU Vec operator- (U x, const Vec& y) { return Vec(x) - y; } -SINTU Vec operator* (U x, const Vec& y) { return Vec(x) * y; } -SINTU Vec operator/ (U x, const Vec& y) { return Vec(x) / y; } -SINTU Vec operator^ (U x, const Vec& y) { return Vec(x) ^ y; } -SINTU Vec operator& (U x, const Vec& y) { return Vec(x) & y; } -SINTU Vec operator| (U x, const Vec& y) { return Vec(x) | y; } -SINTU Vec> operator==(U x, const Vec& y) { return Vec(x) == y; } -SINTU Vec> operator!=(U x, const Vec& y) { return Vec(x) != y; } -SINTU Vec> operator<=(U x, const Vec& y) { return Vec(x) <= y; } -SINTU Vec> operator>=(U x, const Vec& y) { return Vec(x) >= y; } -SINTU Vec> operator< (U x, const Vec& y) { return Vec(x) < y; } -SINTU Vec> operator> (U x, const Vec& y) { return Vec(x) > y; } - -SINTU Vec operator+ (const Vec& x, U y) { return x + Vec(y); } -SINTU Vec operator- (const Vec& x, U y) { return x - Vec(y); } -SINTU Vec operator* (const Vec& x, U y) { return x * Vec(y); } -SINTU Vec operator/ (const Vec& x, U y) { return x / Vec(y); } -SINTU Vec operator^ (const Vec& x, U y) { return x ^ Vec(y); } -SINTU Vec operator& (const Vec& x, U y) { return x & Vec(y); } -SINTU Vec operator| (const Vec& x, U y) { return x | Vec(y); } -SINTU Vec> operator==(const Vec& x, U y) { return x == Vec(y); } -SINTU Vec> operator!=(const Vec& x, U y) { return x != Vec(y); } -SINTU Vec> operator<=(const Vec& x, U y) { return x <= Vec(y); } -SINTU Vec> operator>=(const Vec& x, U y) { return x >= Vec(y); } -SINTU Vec> operator< (const Vec& x, U y) { return x < Vec(y); } -SINTU Vec> operator> (const Vec& x, U y) { return x > Vec(y); } - -SINT Vec& operator+=(Vec& x, const Vec& y) { return (x = x + y); } -SINT Vec& operator-=(Vec& x, const Vec& y) { return (x = x - y); } -SINT Vec& operator*=(Vec& x, const Vec& y) { return (x = x * y); } -SINT Vec& operator/=(Vec& x, const Vec& y) { return (x = x / y); } -SINT Vec& operator^=(Vec& x, const Vec& y) { return (x = x ^ y); } -SINT Vec& operator&=(Vec& x, const Vec& y) { return (x = x & y); } -SINT Vec& operator|=(Vec& x, const Vec& y) { return (x = x | y); } - -SINTU Vec& operator+=(Vec& x, U y) { return (x = x + Vec(y)); } -SINTU Vec& operator-=(Vec& x, U y) { return (x = x - Vec(y)); } -SINTU Vec& operator*=(Vec& x, U y) { return (x = x * Vec(y)); } -SINTU Vec& operator/=(Vec& x, U y) { return (x = x / Vec(y)); } -SINTU Vec& operator^=(Vec& x, U y) { return (x = x ^ Vec(y)); } -SINTU Vec& operator&=(Vec& x, U y) { return (x = x & Vec(y)); } -SINTU Vec& operator|=(Vec& x, U y) { return (x = x | Vec(y)); } - -SINT Vec& operator<<=(Vec& x, int bits) { return (x = x << bits); } -SINT Vec& operator>>=(Vec& x, int bits) { return (x = x >> bits); } - -// Some operations we want are not expressible with Clang/GCC vector extensions. - -// Clang can reason about naive_if_then_else() and optimize through it better -// than if_then_else(), so it's sometimes useful to call it directly when we -// think an entire expression should optimize away, e.g. min()/max(). -SINT Vec naive_if_then_else(const Vec>& cond, const Vec& t, const Vec& e) { - return bit_pun>(( cond & bit_pun>>(t)) | - (~cond & bit_pun>>(e)) ); -} - -SIT Vec<1,T> if_then_else(const Vec<1,M>& cond, const Vec<1,T>& t, const Vec<1,T>& e) { - // In practice this scalar implementation is unlikely to be used. See next if_then_else(). - return bit_pun>(( cond & bit_pun>>(t)) | - (~cond & bit_pun>>(e)) ); -} -SINT Vec if_then_else(const Vec>& cond, const Vec& t, const Vec& e) { - // Specializations inline here so they can generalize what types the apply to. -#if SKVX_USE_SIMD && defined(__AVX2__) - if constexpr (N*sizeof(T) == 32) { - return bit_pun>(_mm256_blendv_epi8(bit_pun<__m256i>(e), - bit_pun<__m256i>(t), - bit_pun<__m256i>(cond))); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE4_1__) - if constexpr (N*sizeof(T) == 16) { - return bit_pun>(_mm_blendv_epi8(bit_pun<__m128i>(e), - bit_pun<__m128i>(t), - bit_pun<__m128i>(cond))); - } -#endif -#if SKVX_USE_SIMD && defined(__ARM_NEON) - if constexpr (N*sizeof(T) == 16) { - return bit_pun>(vbslq_u8(bit_pun(cond), - bit_pun(t), - bit_pun(e))); - } -#endif - // Recurse for large vectors to try to hit the specializations above. - if constexpr (N*sizeof(T) > 16) { - return join(if_then_else(cond.lo, t.lo, e.lo), - if_then_else(cond.hi, t.hi, e.hi)); - } - // This default can lead to better code than the recursing onto scalars. - return naive_if_then_else(cond, t, e); -} - -SIT bool any(const Vec<1,T>& x) { return x.val != 0; } -SINT bool any(const Vec& x) { - // For any(), the _mm_testz intrinsics are correct and don't require comparing 'x' to 0, so it's - // lower latency compared to _mm_movemask + _mm_compneq on plain SSE. -#if SKVX_USE_SIMD && defined(__AVX2__) - if constexpr (N*sizeof(T) == 32) { - return !_mm256_testz_si256(bit_pun<__m256i>(x), _mm256_set1_epi32(-1)); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE_4_1__) - if constexpr (N*sizeof(T) == 16) { - return !_mm_testz_si128(bit_pun<__m128i>(x), _mm_set1_epi32(-1)); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE__) - if constexpr (N*sizeof(T) == 16) { - // On SSE, movemask checks only the MSB in each lane, which is fine if the lanes were set - // directly from a comparison op (which sets all bits to 1 when true), but skvx::Vec<> - // treats any non-zero value as true, so we have to compare 'x' to 0 before calling movemask - return _mm_movemask_ps(_mm_cmpneq_ps(bit_pun<__m128>(x), _mm_set1_ps(0))) != 0b0000; - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - // On 64-bit NEON, take the max across lanes, which will be non-zero if any lane was true. - // The specific lane-size doesn't really matter in this case since it's really any set bit - // that we're looking for. - if constexpr (N*sizeof(T) == 8 ) { return vmaxv_u8 (bit_pun (x)) > 0; } - if constexpr (N*sizeof(T) == 16) { return vmaxvq_u8(bit_pun(x)) > 0; } -#endif -#if SKVX_USE_SIMD && defined(__wasm_simd128__) - if constexpr (N == 4 && sizeof(T) == 4) { - return wasm_i32x4_any_true(bit_pun>(x)); - } -#endif - return any(x.lo) - || any(x.hi); -} - -SIT bool all(const Vec<1,T>& x) { return x.val != 0; } -SINT bool all(const Vec& x) { -// Unlike any(), we have to respect the lane layout, or we'll miss cases where a -// true lane has a mix of 0 and 1 bits. -#if SKVX_USE_SIMD && defined(__SSE__) - // Unfortunately, the _mm_testc intrinsics don't let us avoid the comparison to 0 for all()'s - // correctness, so always just use the plain SSE version. - if constexpr (N == 4 && sizeof(T) == 4) { - return _mm_movemask_ps(_mm_cmpneq_ps(bit_pun<__m128>(x), _mm_set1_ps(0))) == 0b1111; - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - // On 64-bit NEON, take the min across the lanes, which will be non-zero if all lanes are != 0. - if constexpr (sizeof(T)==1 && N==8) {return vminv_u8 (bit_pun (x)) > 0;} - if constexpr (sizeof(T)==1 && N==16) {return vminvq_u8 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==2 && N==4) {return vminv_u16 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==2 && N==8) {return vminvq_u16(bit_pun(x)) > 0;} - if constexpr (sizeof(T)==4 && N==2) {return vminv_u32 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==4 && N==4) {return vminvq_u32(bit_pun(x)) > 0;} -#endif -#if SKVX_USE_SIMD && defined(__wasm_simd128__) - if constexpr (N == 4 && sizeof(T) == 4) { - return wasm_i32x4_all_true(bit_pun>(x)); - } -#endif - return all(x.lo) - && all(x.hi); -} - -// cast() Vec to Vec, as if applying a C-cast to each lane. -// TODO: implement with map()? -template -SI Vec<1,D> cast(const Vec<1,S>& src) { return (D)src.val; } - -template -SI Vec cast(const Vec& src) { -#if SKVX_USE_SIMD && defined(__clang__) - return to_vec(__builtin_convertvector(to_vext(src), VExt)); -#else - return join(cast(src.lo), cast(src.hi)); -#endif -} - -// min/max match logic of std::min/std::max, which is important when NaN is involved. -SIT T min(const Vec<1,T>& x) { return x.val; } -SIT T max(const Vec<1,T>& x) { return x.val; } -SINT T min(const Vec& x) { return std::min(min(x.lo), min(x.hi)); } -SINT T max(const Vec& x) { return std::max(max(x.lo), max(x.hi)); } - -SINT Vec min(const Vec& x, const Vec& y) { return naive_if_then_else(y < x, y, x); } -SINT Vec max(const Vec& x, const Vec& y) { return naive_if_then_else(x < y, y, x); } - -SINTU Vec min(const Vec& x, U y) { return min(x, Vec(y)); } -SINTU Vec max(const Vec& x, U y) { return max(x, Vec(y)); } -SINTU Vec min(U x, const Vec& y) { return min(Vec(x), y); } -SINTU Vec max(U x, const Vec& y) { return max(Vec(x), y); } - -// pin matches the logic of SkTPin, which is important when NaN is involved. It always returns -// values in the range lo..hi, and if x is NaN, it returns lo. -SINT Vec pin(const Vec& x, const Vec& lo, const Vec& hi) { - return max(lo, min(x, hi)); -} - -// Shuffle values from a vector pretty arbitrarily: -// skvx::Vec<4,float> rgba = {R,G,B,A}; -// shuffle<2,1,0,3> (rgba) ~> {B,G,R,A} -// shuffle<2,1> (rgba) ~> {B,G} -// shuffle<2,1,2,1,2,1,2,1>(rgba) ~> {B,G,B,G,B,G,B,G} -// shuffle<3,3,3,3> (rgba) ~> {A,A,A,A} -// The only real restriction is that the output also be a legal N=power-of-two sknx::Vec. -template -SI Vec shuffle(const Vec& x) { -#if SKVX_USE_SIMD && defined(__clang__) - // TODO: can we just always use { x[Ix]... }? - return to_vec(__builtin_shufflevector(to_vext(x), to_vext(x), Ix...)); -#else - return { x[Ix]... }; -#endif -} - -// Call map(fn, x) for a vector with fn() applied to each lane of x, { fn(x[0]), fn(x[1]), ... }, -// or map(fn, x,y) for a vector of fn(x[i], y[i]), etc. - -template -SI auto map(std::index_sequence, - Fn&& fn, const Args&... args) -> skvx::Vec { - auto lane = [&](size_t i) -#if defined(__clang__) - // CFI, specifically -fsanitize=cfi-icall, seems to give a false positive here, - // with errors like "control flow integrity check for type 'float (float) - // noexcept' failed during indirect function call... note: sqrtf.cfi_jt defined - // here". But we can be quite sure fn is the right type: it's all inferred! - // So, stifle CFI in this function. - __attribute__((no_sanitize("cfi"))) -#endif - { return fn(args[i]...); }; - - return { lane(I)... }; -} - -template -auto map(Fn&& fn, const Vec& first, const Rest&... rest) { - // Derive an {0...N-1} index_sequence from the size of the first arg: N lanes in, N lanes out. - return map(std::make_index_sequence{}, fn, first,rest...); -} - -SIN Vec ceil(const Vec& x) { return map( ceilf, x); } -SIN Vec floor(const Vec& x) { return map(floorf, x); } -SIN Vec trunc(const Vec& x) { return map(truncf, x); } -SIN Vec round(const Vec& x) { return map(roundf, x); } -SIN Vec sqrt(const Vec& x) { return map( sqrtf, x); } -SIN Vec abs(const Vec& x) { return map( fabsf, x); } -SIN Vec fma(const Vec& x, - const Vec& y, - const Vec& z) { - // I don't understand why Clang's codegen is terrible if we write map(fmaf, x,y,z) directly. - auto fn = [](float x, float y, float z) { return fmaf(x,y,z); }; - return map(fn, x,y,z); -} - -SI Vec<1,int> lrint(const Vec<1,float>& x) { - return (int)lrintf(x.val); -} -SIN Vec lrint(const Vec& x) { -#if SKVX_USE_SIMD && defined(__AVX__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtps_epi32(bit_pun<__m256>(x))); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE__) - if constexpr (N == 4) { - return bit_pun>(_mm_cvtps_epi32(bit_pun<__m128>(x))); - } -#endif - return join(lrint(x.lo), - lrint(x.hi)); -} - -SIN Vec fract(const Vec& x) { return x - floor(x); } - -// Assumes inputs are finite and treat/flush denorm half floats as/to zero. -// Key constants to watch for: -// - a float is 32-bit, 1-8-23 sign-exponent-mantissa, with 127 exponent bias; -// - a half is 16-bit, 1-5-10 sign-exponent-mantissa, with 15 exponent bias. -SIN Vec to_half_finite_ftz(const Vec& x) { - Vec sem = bit_pun>(x), - s = sem & 0x8000'0000, - em = sem ^ s, - is_norm = em > 0x387f'd000, // halfway between largest f16 denorm and smallest norm - norm = (em>>13) - ((127-15)<<10); - return cast((s>>16) | (is_norm & norm)); -} -SIN Vec from_half_finite_ftz(const Vec& x) { - Vec wide = cast(x), - s = wide & 0x8000, - em = wide ^ s, - is_norm = em > 0x3ff, - norm = (em<<13) + ((127-15)<<23); - return bit_pun>((s<<16) | (is_norm & norm)); -} - -// Like if_then_else(), these N=1 base cases won't actually be used unless explicitly called. -SI Vec<1,uint16_t> to_half(const Vec<1,float>& x) { return to_half_finite_ftz(x); } -SI Vec<1,float> from_half(const Vec<1,uint16_t>& x) { return from_half_finite_ftz(x); } - -SIN Vec to_half(const Vec& x) { -#if SKVX_USE_SIMD && defined(__F16C__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtps_ph(bit_pun<__m256>(x), - _MM_FROUND_TO_NEAREST_INT)); - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - if constexpr (N == 4) { - return bit_pun>(vcvt_f16_f32(bit_pun(x))); - - } -#endif - if constexpr (N > 4) { - return join(to_half(x.lo), - to_half(x.hi)); - } - return to_half_finite_ftz(x); -} - -SIN Vec from_half(const Vec& x) { -#if SKVX_USE_SIMD && defined(__F16C__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtph_ps(bit_pun<__m128i>(x))); - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - if constexpr (N == 4) { - return bit_pun>(vcvt_f32_f16(bit_pun(x))); - } -#endif - if constexpr (N > 4) { - return join(from_half(x.lo), - from_half(x.hi)); - } - return from_half_finite_ftz(x); -} - -// div255(x) = (x + 127) / 255 is a bit-exact rounding divide-by-255, packing down to 8-bit. -SIN Vec div255(const Vec& x) { - return cast( (x+127)/255 ); -} - -// approx_scale(x,y) approximates div255(cast(x)*cast(y)) within a bit, -// and is always perfect when x or y is 0 or 255. -SIN Vec approx_scale(const Vec& x, const Vec& y) { - // All of (x*y+x)/256, (x*y+y)/256, and (x*y+255)/256 meet the criteria above. - // We happen to have historically picked (x*y+x)/256. - auto X = cast(x), - Y = cast(y); - return cast( (X*Y+X)/256 ); -} - -// saturated_add(x,y) sums values and clamps to the maximum value instead of overflowing. -SINT std::enable_if_t, Vec> saturated_add(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && (defined(__SSE__) || defined(__ARM_NEON)) - // Both SSE and ARM have 16-lane saturated adds, so use intrinsics for those and recurse down - // or join up to take advantage. - if constexpr (N == 16 && sizeof(T) == 1) { - #if defined(__SSE__) - return bit_pun>(_mm_adds_epu8(bit_pun<__m128i>(x), bit_pun<__m128i>(y))); - #else // __ARM_NEON - return bit_pun>(vqaddq_u8(bit_pun(x), bit_pun(y))); - #endif - } else if constexpr (N < 16 && sizeof(T) == 1) { - return saturated_add(join(x,x), join(y,y)).lo; - } else if constexpr (sizeof(T) == 1) { - return join(saturated_add(x.lo, y.lo), saturated_add(x.hi, y.hi)); - } -#endif - // Otherwise saturate manually - auto sum = x + y; - return if_then_else(sum < x, Vec(std::numeric_limits::max()), sum); -} - -// The ScaledDividerU32 takes a divisor > 1, and creates a function divide(numerator) that -// calculates a numerator / denominator. For this to be rounded properly, numerator should have -// half added in: -// divide(numerator + half) == floor(numerator/denominator + 1/2). -// -// This gives an answer within +/- 1 from the true value. -// -// Derivation of half: -// numerator/denominator + 1/2 = (numerator + half) / d -// numerator + denominator / 2 = numerator + half -// half = denominator / 2. -// -// Because half is divided by 2, that division must also be rounded. -// half == denominator / 2 = (denominator + 1) / 2. -// -// The divisorFactor is just a scaled value: -// divisorFactor = (1 / divisor) * 2 ^ 32. -// The maximum that can be divided and rounded is UINT_MAX - half. -class ScaledDividerU32 { -public: - explicit ScaledDividerU32(uint32_t divisor) - : fDivisorFactor{(uint32_t)(std::round((1.0 / divisor) * (1ull << 32)))} - , fHalf{(divisor + 1) >> 1} { - assert(divisor > 1); - } - - Vec<4, uint32_t> divide(const Vec<4, uint32_t>& numerator) const { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - uint64x2_t hi = vmull_n_u32(vget_high_u32(to_vext(numerator)), fDivisorFactor); - uint64x2_t lo = vmull_n_u32(vget_low_u32(to_vext(numerator)), fDivisorFactor); - - return to_vec<4, uint32_t>(vcombine_u32(vshrn_n_u64(lo,32), vshrn_n_u64(hi,32))); -#else - return cast((cast(numerator) * fDivisorFactor) >> 32); -#endif - } - - uint32_t half() const { return fHalf; } - -private: - const uint32_t fDivisorFactor; - const uint32_t fHalf; -}; - - -SIN Vec mull(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - // With NEON we can do eight u8*u8 -> u16 in one instruction, vmull_u8 (read, mul-long). - if constexpr (N == 8) { - return to_vec<8,uint16_t>(vmull_u8(to_vext(x), to_vext(y))); - } else if constexpr (N < 8) { - return mull(join(x,x), join(y,y)).lo; - } else { // N > 8 - return join(mull(x.lo, y.lo), mull(x.hi, y.hi)); - } -#else - return cast(x) * cast(y); -#endif -} - -SIN Vec mull(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - // NEON can do four u16*u16 -> u32 in one instruction, vmull_u16 - if constexpr (N == 4) { - return to_vec<4,uint32_t>(vmull_u16(to_vext(x), to_vext(y))); - } else if constexpr (N < 4) { - return mull(join(x,x), join(y,y)).lo; - } else { // N > 4 - return join(mull(x.lo, y.lo), mull(x.hi, y.hi)); - } -#else - return cast(x) * cast(y); -#endif -} - -SIN Vec mulhi(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__SSE__) - // Use _mm_mulhi_epu16 for 8xuint16_t and join or split to get there. - if constexpr (N == 8) { - return bit_pun>(_mm_mulhi_epu16(bit_pun<__m128i>(x), bit_pun<__m128i>(y))); - } else if constexpr (N < 8) { - return mulhi(join(x,x), join(y,y)).lo; - } else { // N > 8 - return join(mulhi(x.lo, y.lo), mulhi(x.hi, y.hi)); - } -#else - return skvx::cast(mull(x, y) >> 16); -#endif -} - -SINT T dot(const Vec& a, const Vec& b) { - auto ab = a*b; - if constexpr (N == 2) { - return ab[0] + ab[1]; - } else if constexpr (N == 4) { - return ab[0] + ab[1] + ab[2] + ab[3]; - } else { - T sum = ab[0]; - for (int i = 1; i < N; ++i) { - sum += ab[i]; - } - return sum; - } -} - -SI float cross(const Vec<2, float>& a, const Vec<2, float>& b) { - auto x = a * shuffle<1,0>(b); - return x[0] - x[1]; -} - -// De-interleaving load of 4 vectors. -// -// WARNING: These are really only supported well on NEON. Consider restructuring your data before -// resorting to these methods. -SIT void strided_load4(const T* v, - Vec<1,T>& a, - Vec<1,T>& b, - Vec<1,T>& c, - Vec<1,T>& d) { - a.val = v[0]; - b.val = v[1]; - c.val = v[2]; - d.val = v[3]; -} -SINT void strided_load4(const T* v, - Vec& a, - Vec& b, - Vec& c, - Vec& d) { - strided_load4(v, a.lo, b.lo, c.lo, d.lo); - strided_load4(v + 4*(N/2), a.hi, b.hi, c.hi, d.hi); -} -#if SKVX_USE_SIMD && defined(__ARM_NEON) -#define IMPL_LOAD4_TRANSPOSED(N, T, VLD) \ -SI void strided_load4(const T* v, \ - Vec& a, \ - Vec& b, \ - Vec& c, \ - Vec& d) { \ - auto mat = VLD(v); \ - a = bit_pun>(mat.val[0]); \ - b = bit_pun>(mat.val[1]); \ - c = bit_pun>(mat.val[2]); \ - d = bit_pun>(mat.val[3]); \ -} -IMPL_LOAD4_TRANSPOSED(2, uint32_t, vld4_u32) -IMPL_LOAD4_TRANSPOSED(4, uint16_t, vld4_u16) -IMPL_LOAD4_TRANSPOSED(8, uint8_t, vld4_u8) -IMPL_LOAD4_TRANSPOSED(2, int32_t, vld4_s32) -IMPL_LOAD4_TRANSPOSED(4, int16_t, vld4_s16) -IMPL_LOAD4_TRANSPOSED(8, int8_t, vld4_s8) -IMPL_LOAD4_TRANSPOSED(2, float, vld4_f32) -IMPL_LOAD4_TRANSPOSED(4, uint32_t, vld4q_u32) -IMPL_LOAD4_TRANSPOSED(8, uint16_t, vld4q_u16) -IMPL_LOAD4_TRANSPOSED(16, uint8_t, vld4q_u8) -IMPL_LOAD4_TRANSPOSED(4, int32_t, vld4q_s32) -IMPL_LOAD4_TRANSPOSED(8, int16_t, vld4q_s16) -IMPL_LOAD4_TRANSPOSED(16, int8_t, vld4q_s8) -IMPL_LOAD4_TRANSPOSED(4, float, vld4q_f32) -#undef IMPL_LOAD4_TRANSPOSED - -#elif SKVX_USE_SIMD && defined(__SSE__) - -SI void strided_load4(const float* v, - Vec<4,float>& a, - Vec<4,float>& b, - Vec<4,float>& c, - Vec<4,float>& d) { - __m128 a_ = _mm_loadu_ps(v); - __m128 b_ = _mm_loadu_ps(v+4); - __m128 c_ = _mm_loadu_ps(v+8); - __m128 d_ = _mm_loadu_ps(v+12); - _MM_TRANSPOSE4_PS(a_, b_, c_, d_); - a = bit_pun>(a_); - b = bit_pun>(b_); - c = bit_pun>(c_); - d = bit_pun>(d_); -} -#endif - -// De-interleaving load of 2 vectors. -// -// WARNING: These are really only supported well on NEON. Consider restructuring your data before -// resorting to these methods. -SIT void strided_load2(const T* v, Vec<1,T>& a, Vec<1,T>& b) { - a.val = v[0]; - b.val = v[1]; -} -SINT void strided_load2(const T* v, Vec& a, Vec& b) { - strided_load2(v, a.lo, b.lo); - strided_load2(v + 2*(N/2), a.hi, b.hi); -} -#if SKVX_USE_SIMD && defined(__ARM_NEON) -#define IMPL_LOAD2_TRANSPOSED(N, T, VLD) \ -SI void strided_load2(const T* v, Vec& a, Vec& b) { \ - auto mat = VLD(v); \ - a = bit_pun>(mat.val[0]); \ - b = bit_pun>(mat.val[1]); \ -} -IMPL_LOAD2_TRANSPOSED(2, uint32_t, vld2_u32) -IMPL_LOAD2_TRANSPOSED(4, uint16_t, vld2_u16) -IMPL_LOAD2_TRANSPOSED(8, uint8_t, vld2_u8) -IMPL_LOAD2_TRANSPOSED(2, int32_t, vld2_s32) -IMPL_LOAD2_TRANSPOSED(4, int16_t, vld2_s16) -IMPL_LOAD2_TRANSPOSED(8, int8_t, vld2_s8) -IMPL_LOAD2_TRANSPOSED(2, float, vld2_f32) -IMPL_LOAD2_TRANSPOSED(4, uint32_t, vld2q_u32) -IMPL_LOAD2_TRANSPOSED(8, uint16_t, vld2q_u16) -IMPL_LOAD2_TRANSPOSED(16, uint8_t, vld2q_u8) -IMPL_LOAD2_TRANSPOSED(4, int32_t, vld2q_s32) -IMPL_LOAD2_TRANSPOSED(8, int16_t, vld2q_s16) -IMPL_LOAD2_TRANSPOSED(16, int8_t, vld2q_s8) -IMPL_LOAD2_TRANSPOSED(4, float, vld2q_f32) -#undef IMPL_LOAD2_TRANSPOSED -#endif - -// Define commonly used aliases -using float2 = Vec< 2, float>; -using float4 = Vec< 4, float>; -using float8 = Vec< 8, float>; - -using double2 = Vec< 2, double>; -using double4 = Vec< 4, double>; -using double8 = Vec< 8, double>; - -using byte2 = Vec< 2, uint8_t>; -using byte4 = Vec< 4, uint8_t>; -using byte8 = Vec< 8, uint8_t>; -using byte16 = Vec<16, uint8_t>; - -using int2 = Vec< 2, int32_t>; -using int4 = Vec< 4, int32_t>; -using int8 = Vec< 8, int32_t>; - -using uint2 = Vec< 2, uint32_t>; -using uint4 = Vec< 4, uint32_t>; -using uint8 = Vec< 8, uint32_t>; - -using long2 = Vec< 2, int64_t>; -using long4 = Vec< 4, int64_t>; -using long8 = Vec< 8, int64_t>; - -// Use with from_half and to_half to convert between floatX, and use these for storage. -using half2 = Vec< 2, uint16_t>; -using half4 = Vec< 4, uint16_t>; -using half8 = Vec< 8, uint16_t>; - -} // namespace skvx - -#undef SINTU -#undef SINT -#undef SIN -#undef SIT -#undef SI -#undef SKVX_ALWAYS_INLINE -#undef SKVX_USE_SIMD - -#endif//SKVX_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h index 2b577342f4cd2..058a18652ba51 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h @@ -9,7 +9,10 @@ #define SkWeakRefCnt_DEFINED #include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + #include +#include /** \class SkWeakRefCnt diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h similarity index 86% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h index f60f7c83b969c..473981e1fb83f 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h @@ -8,16 +8,19 @@ #ifndef skgpu_SingleOwner_DEFINED #define skgpu_SingleOwner_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkDebug.h" // IWYU pragma: keep + +#if defined(SK_DEBUG) +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkThreadAnnotations.h" +#include "include/private/base/SkThreadID.h" -#ifdef SK_DEBUG -#include "include/private/SkMutex.h" -#include "include/private/SkThreadID.h" #endif namespace skgpu { -#ifdef SK_DEBUG +#if defined(SK_DEBUG) #define SKGPU_ASSERT_SINGLE_OWNER(obj) \ skgpu::SingleOwner::AutoEnforce debug_SingleOwner(obj, __FILE__, __LINE__); diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h new file mode 100644 index 0000000000000..4028f95d87d2b --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h @@ -0,0 +1,52 @@ +/* + * 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 SkAPI_DEFINED +#define SkAPI_DEFINED + +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +// If SKIA_IMPLEMENTATION is defined as 1, that signals we are building Skia and should +// export our symbols. If it is not set (or set to 0), then Skia is being used by a client +// and we should not export our symbols. +#if !defined(SKIA_IMPLEMENTATION) + #define SKIA_IMPLEMENTATION 0 +#endif + +// If we are compiling Skia is being as a DLL, we need to be sure to export all of our public +// APIs to that DLL. If a client is using Skia which was compiled as a DLL, we need to instruct +// the linker to use the symbols from that DLL. This is the goal of the SK_API define. +#if !defined(SK_API) + #if defined(SKIA_DLL) + #if defined(_MSC_VER) + #if SKIA_IMPLEMENTATION + #define SK_API __declspec(dllexport) + #else + #define SK_API __declspec(dllimport) + #endif + #else + #define SK_API __attribute__((visibility("default"))) + #endif + #else + #define SK_API + #endif +#endif + +// SK_SPI is functionally identical to SK_API, but used within src to clarify that it's less stable +#if !defined(SK_SPI) + #define SK_SPI SK_API +#endif + +// See https://clang.llvm.org/docs/AttributeReference.html#availability +// The API_AVAILABLE macro comes from on MacOS +#if defined(SK_ENABLE_API_AVAILABLE) +# define SK_API_AVAILABLE API_AVAILABLE +#else +# define SK_API_AVAILABLE(...) +#endif + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h new file mode 100644 index 0000000000000..2b2138ddd49c2 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h @@ -0,0 +1,39 @@ +/* + * 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 SkAlign_DEFINED +#define SkAlign_DEFINED + +#include "include/private/base/SkAssert.h" + +#include + +template static constexpr T SkAlign2(T x) { return (x + 1) >> 1 << 1; } +template static constexpr T SkAlign4(T x) { return (x + 3) >> 2 << 2; } +template static constexpr T SkAlign8(T x) { return (x + 7) >> 3 << 3; } + +template static constexpr bool SkIsAlign2(T x) { return 0 == (x & 1); } +template static constexpr bool SkIsAlign4(T x) { return 0 == (x & 3); } +template static constexpr bool SkIsAlign8(T x) { return 0 == (x & 7); } + +template static constexpr T SkAlignPtr(T x) { + return sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x); +} +template static constexpr bool SkIsAlignPtr(T x) { + return sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x); +} + +/** + * align up to a power of 2 + */ +static inline constexpr size_t SkAlignTo(size_t x, size_t alignment) { + // The same as alignment && SkIsPow2(value), w/o a dependency cycle. + SkASSERT(alignment && (alignment & (alignment - 1)) == 0); + return (x + alignment - 1) & ~(alignment - 1); +} + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h new file mode 100644 index 0000000000000..532ad03978fac --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h @@ -0,0 +1,32 @@ +// 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 SkAlignedStorage_DEFINED +#define SkAlignedStorage_DEFINED + +#include +#include + +template class SkAlignedSTStorage { +public: + SkAlignedSTStorage() {} + SkAlignedSTStorage(SkAlignedSTStorage&&) = delete; + SkAlignedSTStorage(const SkAlignedSTStorage&) = delete; + SkAlignedSTStorage& operator=(SkAlignedSTStorage&&) = delete; + SkAlignedSTStorage& operator=(const SkAlignedSTStorage&) = delete; + + // Returns void* because this object does not initialize the + // memory. Use placement new for types that require a constructor. + void* get() { return fStorage; } + const void* get() const { return fStorage; } + + // Act as a container of bytes because the storage is uninitialized. + std::byte* data() { return fStorage; } + const std::byte* data() const { return fStorage; } + size_t size() const { return std::size(fStorage); } + +private: + alignas(T) std::byte fStorage[sizeof(T) * N]; +}; + +#endif // SkAlignedStorage_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h new file mode 100644 index 0000000000000..97d43d4f64ff4 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h @@ -0,0 +1,92 @@ +/* + * 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 SkAssert_DEFINED +#define SkAssert_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" // IWYU pragma: keep + +/** Called internally if we hit an unrecoverable error. + The platform implementation must not return, but should either throw + an exception or otherwise exit. +*/ +[[noreturn]] SK_API extern void sk_abort_no_print(void); + +#if defined(SK_BUILD_FOR_GOOGLE3) + void SkDebugfForDumpStackTrace(const char* data, void* unused); + namespace base { + void DumpStackTrace(int skip_count, void w(const char*, void*), void* arg); + } +# define SK_DUMP_GOOGLE3_STACK() ::base::DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr) +#else +# define SK_DUMP_GOOGLE3_STACK() +#endif + +#if !defined(SK_ABORT) +# if defined(SK_BUILD_FOR_WIN) + // This style lets Visual Studio follow errors back to the source file. +# define SK_DUMP_LINE_FORMAT "%s(%d)" +# else +# define SK_DUMP_LINE_FORMAT "%s:%d" +# endif +# define SK_ABORT(message, ...) \ + do { \ + SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \ + __FILE__, __LINE__, ##__VA_ARGS__); \ + SK_DUMP_GOOGLE3_STACK(); \ + sk_abort_no_print(); \ + } while (false) +#endif + +// SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g. +// uint32_t foo(int x) { +// SkASSERT(x > 4); +// return x - 4; +// } +// and are also written to be compatible with constexpr functions: +// constexpr uint32_t foo(int x) { +// return SkASSERT(x > 4), +// x - 4; +// } +#define SkASSERT_RELEASE(cond) \ + static_cast( (cond) ? (void)0 : []{ SK_ABORT("assert(%s)", #cond); }() ) + +#if defined(SK_DEBUG) + #define SkASSERT(cond) SkASSERT_RELEASE(cond) + #define SkASSERTF(cond, fmt, ...) static_cast( (cond) ? (void)0 : [&]{ \ + SkDebugf(fmt"\n", ##__VA_ARGS__); \ + SK_ABORT("assert(%s)", #cond); \ + }() ) + #define SkDEBUGFAIL(message) SK_ABORT("%s", message) + #define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__) + #define SkAssertResult(cond) SkASSERT(cond) +#else + #define SkASSERT(cond) static_cast(0) + #define SkASSERTF(cond, fmt, ...) static_cast(0) + #define SkDEBUGFAIL(message) + #define SkDEBUGFAILF(fmt, ...) + + // unlike SkASSERT, this macro executes its condition in the non-debug build. + // The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT. + #define SkAssertResult(cond) if (cond) {} do {} while(false) +#endif + +#if !defined(SkUNREACHABLE) +# if defined(_MSC_VER) && !defined(__clang__) +# include +# define FAST_FAIL_INVALID_ARG 5 +// See https://developercommunity.visualstudio.com/content/problem/1128631/code-flow-doesnt-see-noreturn-with-extern-c.html +// for why this is wrapped. Hopefully removable after msvc++ 19.27 is no longer supported. +[[noreturn]] static inline void sk_fast_fail() { __fastfail(FAST_FAIL_INVALID_ARG); } +# define SkUNREACHABLE sk_fast_fail() +# else +# define SkUNREACHABLE __builtin_trap() +# endif +#endif + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h new file mode 100644 index 0000000000000..34fdf0e09c92e --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h @@ -0,0 +1,102 @@ +/* + * 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 SkAttributes_DEFINED +#define SkAttributes_DEFINED + +#include "include/private/base/SkFeatures.h" // IWYU pragma: keep +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +#if defined(__clang__) || defined(__GNUC__) +# define SK_ATTRIBUTE(attr) __attribute__((attr)) +#else +# define SK_ATTRIBUTE(attr) +#endif + +#if !defined(SK_UNUSED) +# if !defined(__clang__) && defined(_MSC_VER) +# define SK_UNUSED __pragma(warning(suppress:4189)) +# else +# define SK_UNUSED SK_ATTRIBUTE(unused) +# endif +#endif + +#if !defined(SK_WARN_UNUSED_RESULT) + #define SK_WARN_UNUSED_RESULT SK_ATTRIBUTE(warn_unused_result) +#endif + +/** + * If your judgment is better than the compiler's (i.e. you've profiled it), + * you can use SK_ALWAYS_INLINE to force inlining. E.g. + * inline void someMethod() { ... } // may not be inlined + * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined + */ +#if !defined(SK_ALWAYS_INLINE) +# if defined(SK_BUILD_FOR_WIN) +# define SK_ALWAYS_INLINE __forceinline +# else +# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline +# endif +#endif + +/** + * If your judgment is better than the compiler's (i.e. you've profiled it), + * you can use SK_NEVER_INLINE to prevent inlining. + */ +#if !defined(SK_NEVER_INLINE) +# if defined(SK_BUILD_FOR_WIN) +# define SK_NEVER_INLINE __declspec(noinline) +# else +# define SK_NEVER_INLINE SK_ATTRIBUTE(noinline) +# endif +#endif + +/** + * Used to annotate a function as taking printf style arguments. + * `A` is the (1 based) index of the format string argument. + * `B` is the (1 based) index of the first argument used by the format string. + */ +#if !defined(SK_PRINTF_LIKE) +# define SK_PRINTF_LIKE(A, B) SK_ATTRIBUTE(format(printf, (A), (B))) +#endif + +/** + * Used to ignore sanitizer warnings. + */ +#if !defined(SK_NO_SANITIZE) +# define SK_NO_SANITIZE(A) SK_ATTRIBUTE(no_sanitize(A)) +#endif + +/** + * Helper macro to define no_sanitize attributes only with clang. + */ +#if defined(__clang__) && defined(__has_attribute) + #if __has_attribute(no_sanitize) + #define SK_CLANG_NO_SANITIZE(A) SK_NO_SANITIZE(A) + #endif +#endif + +#if !defined(SK_CLANG_NO_SANITIZE) + #define SK_CLANG_NO_SANITIZE(A) +#endif + +/** + * Annotates a class' non-trivial special functions as trivial for the purposes of calls. + * Allows a class with a non-trivial destructor to be __is_trivially_relocatable. + * Use of this attribute on a public API breaks platform ABI. + * Annotated classes may not hold pointers derived from `this`. + * Annotated classes must implement move+delete as equivalent to memcpy+free. + * Use may require more complete types, as callee destroys. + * + * https://clang.llvm.org/docs/AttributeReference.html#trivial-abi + * https://libcxx.llvm.org/DesignDocs/UniquePtrTrivialAbi.html + */ +#if !defined(SK_TRIVIAL_ABI) +# define SK_TRIVIAL_ABI +#endif + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h new file mode 100644 index 0000000000000..a5f60fd3ef191 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h @@ -0,0 +1,25 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkCPUTypes_DEFINED +#define SkCPUTypes_DEFINED + +// TODO(bungeman,kjlubick) There are a lot of assumptions throughout the codebase that +// these types are 32 bits, when they could be more or less. Public APIs should stop +// using these. Internally, we could use uint_fast8_t and uint_fast16_t, but not in +// public APIs due to ABI incompatibilities. + +/** Fast type for unsigned 8 bits. Use for parameter passing and local + variables, not for storage +*/ +typedef unsigned U8CPU; + +/** Fast type for unsigned 16 bits. Use for parameter passing and local + variables, not for storage +*/ +typedef unsigned U16CPU; + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h new file mode 100644 index 0000000000000..2ece73e28761b --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h @@ -0,0 +1,46 @@ +// 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 SkContainers_DEFINED +#define SkContainers_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkSpan_impl.h" + +#include +#include + +class SK_SPI SkContainerAllocator { +public: + SkContainerAllocator(size_t sizeOfT, int maxCapacity) + : fSizeOfT{sizeOfT} + , fMaxCapacity{maxCapacity} {} + + // allocate will abort on failure. Given a capacity of 0, it will return the empty span. + // The bytes allocated are freed using sk_free(). + SkSpan allocate(int capacity, double growthFactor = 1.0); + +private: + friend struct SkContainerAllocatorTestingPeer; + // All capacity counts will be rounded up to kCapacityMultiple. + // TODO: this is a constant from the original SkTArray code. This should be checked some how. + static constexpr int64_t kCapacityMultiple = 8; + + // Rounds up capacity to next multiple of kCapacityMultiple and pin to fMaxCapacity. + size_t roundUpCapacity(int64_t capacity) const; + + // Grows the capacity by growthFactor being sure to stay with in kMinBytes and fMaxCapacity. + size_t growthFactorCapacity(int capacity, double growthFactor) const; + + const size_t fSizeOfT; + const int64_t fMaxCapacity; +}; + +// sk_allocate_canfail returns the empty span on failure. Parameter size must be > 0. +SkSpan sk_allocate_canfail(size_t size); + +// Returns the empty span if size is 0. sk_allocate_throw aborts on failure. +SkSpan sk_allocate_throw(size_t size); + +SK_SPI void sk_report_container_overflow_and_die(); +#endif // SkContainers_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h new file mode 100644 index 0000000000000..2e4810fc1c961 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.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 SkDebug_DEFINED +#define SkDebug_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +#if !defined(SkDebugf) + void SK_SPI SkDebugf(const char format[], ...) SK_PRINTF_LIKE(1, 2); +#endif + +#if defined(SK_DEBUG) + #define SkDEBUGCODE(...) __VA_ARGS__ + #define SkDEBUGF(...) SkDebugf(__VA_ARGS__) +#else + #define SkDEBUGCODE(...) + #define SkDEBUGF(...) +#endif + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h similarity index 98% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h index 8adc39c1c71f2..fbc61673131b4 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h @@ -10,7 +10,9 @@ #ifndef SkDeque_DEFINED #define SkDeque_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" + +#include /* * The deque class works by blindly creating memory space of a specified element diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h new file mode 100644 index 0000000000000..662bf0321161e --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h @@ -0,0 +1,151 @@ +/* + * 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 SkFeatures_DEFINED +#define SkFeatures_DEFINED + +#if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && \ + !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) + + #ifdef __APPLE__ + #include + #endif + + #if defined(_WIN32) || defined(__SYMBIAN32__) + #define SK_BUILD_FOR_WIN + #elif defined(ANDROID) || defined(__ANDROID__) + #define SK_BUILD_FOR_ANDROID + #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || \ + defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || \ + defined(__DragonFly__) || defined(__Fuchsia__) || \ + defined(__GLIBC__) || defined(__GNU__) || defined(__unix__) + #define SK_BUILD_FOR_UNIX + #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR + #define SK_BUILD_FOR_IOS + #else + #define SK_BUILD_FOR_MAC + #endif +#endif // end SK_BUILD_FOR_* + + +#if defined(SK_BUILD_FOR_WIN) && !defined(__clang__) + #if !defined(SK_RESTRICT) + #define SK_RESTRICT __restrict + #endif + #if !defined(SK_WARN_UNUSED_RESULT) + #define SK_WARN_UNUSED_RESULT + #endif +#endif + +#if !defined(SK_RESTRICT) + #define SK_RESTRICT __restrict__ +#endif + +#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) + #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) + #define SK_CPU_BENDIAN + #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) + #define SK_CPU_LENDIAN + #elif defined(__sparc) || defined(__sparc__) || \ + defined(_POWER) || defined(__powerpc__) || \ + defined(__ppc__) || defined(__hppa) || \ + defined(__PPC__) || defined(__PPC64__) || \ + defined(_MIPSEB) || defined(__ARMEB__) || \ + defined(__s390__) || \ + (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ + (defined(__ia64) && defined(__BIG_ENDIAN__)) + #define SK_CPU_BENDIAN + #else + #define SK_CPU_LENDIAN + #endif +#endif + +#if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) + #define SK_CPU_X86 1 +#endif + +/** + * SK_CPU_SSE_LEVEL + * + * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. + * On non-intel CPU this should be undefined. + */ +#define SK_CPU_SSE_LEVEL_SSE1 10 +#define SK_CPU_SSE_LEVEL_SSE2 20 +#define SK_CPU_SSE_LEVEL_SSE3 30 +#define SK_CPU_SSE_LEVEL_SSSE3 31 +#define SK_CPU_SSE_LEVEL_SSE41 41 +#define SK_CPU_SSE_LEVEL_SSE42 42 +#define SK_CPU_SSE_LEVEL_AVX 51 +#define SK_CPU_SSE_LEVEL_AVX2 52 +#define SK_CPU_SSE_LEVEL_SKX 60 + +// TODO(brianosman,kjlubick) clean up these checks + +// Are we in GCC/Clang? +#ifndef SK_CPU_SSE_LEVEL + // These checks must be done in descending order to ensure we set the highest + // available SSE level. + #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ + defined(__AVX512BW__) && defined(__AVX512VL__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX + #elif defined(__AVX2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 + #elif defined(__AVX__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX + #elif defined(__SSE4_2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42 + #elif defined(__SSE4_1__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41 + #elif defined(__SSSE3__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 + #elif defined(__SSE3__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 + #elif defined(__SSE2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #endif +#endif + +// Are we in VisualStudio? +#ifndef SK_CPU_SSE_LEVEL + // These checks must be done in descending order to ensure we set the highest + // available SSE level. 64-bit intel guarantees at least SSE2 support. + #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ + defined(__AVX512BW__) && defined(__AVX512VL__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX + #elif defined(__AVX2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 + #elif defined(__AVX__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX + #elif defined(_M_X64) || defined(_M_AMD64) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #elif defined(_M_IX86_FP) + #if _M_IX86_FP >= 2 + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #elif _M_IX86_FP == 1 + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 + #endif + #endif +#endif + +// ARM defines +#if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) + #define SK_CPU_ARM32 +#elif defined(__aarch64__) + #define SK_CPU_ARM64 +#endif + +// All 64-bit ARM chips have NEON. Many 32-bit ARM chips do too. +#if !defined(SK_ARM_HAS_NEON) && defined(__ARM_NEON) + #define SK_ARM_HAS_NEON +#endif + +#if defined(__ARM_FEATURE_CRC32) + #define SK_ARM_HAS_CRC32 +#endif + +#endif // SkFeatures_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h similarity index 94% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h index e34c19f2ac867..2c8f2fb56c188 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h @@ -8,11 +8,12 @@ #ifndef SkFixed_DEFINED #define SkFixed_DEFINED -#include "include/core/SkScalar.h" -#include "include/core/SkTypes.h" -#include "include/private/SkSafe_math.h" -#include "include/private/SkTPin.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMath.h" // IWYU pragma: keep +#include "include/private/base/SkTPin.h" // IWYU pragma: keep + +#include /** \file SkFixed.h @@ -86,7 +87,6 @@ static inline SkFixed SkFixedFloorToFixed(SkFixed x) { return (SkFixed)( (uint32_t)x & 0xFFFF0000 ); } -#define SkFixedAbs(x) SkAbs32(x) #define SkFixedAve(a, b) (((a) + (b)) >> 1) // The divide may exceed 32 bits. Clamp to a signed 32 bit result. @@ -102,6 +102,8 @@ static inline SkFixed SkFixedMul(SkFixed a, SkFixed b) { // The VCVT float-to-fixed instruction is part of the VFPv3 instruction set. #if defined(__ARM_VFPV3__) + #include + /* This does not handle NaN or other obscurities, but is faster than than (int)(x*65536). When built on Android with -Os, needs forcing to inline or we lose the speed benefit. @@ -110,7 +112,7 @@ static inline SkFixed SkFixedMul(SkFixed a, SkFixed b) { { int32_t y; asm("vcvt.s32.f32 %0, %0, #16": "+w"(x)); - memcpy(&y, &x, sizeof(y)); + std::memcpy(&y, &x, sizeof(y)); return y; } #undef SkFloatToFixed diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h similarity index 96% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h index 89eea4b9e3495..37a7b271aee12 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h @@ -8,10 +8,9 @@ #ifndef SkFloatBits_DEFINED #define SkFloatBits_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkSafe_math.h" +#include "include/private/base/SkMath.h" -#include +#include /** Convert a sign-bit int (i.e. float interpreted as int) into a 2s compliement int. This also converts -0 (0x80000000) to 0. Doing this to a float allows diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h similarity index 89% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h index 8135abbfe1952..7aa8909f3a5eb 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h @@ -8,14 +8,14 @@ #ifndef SkFloatingPoint_DEFINED #define SkFloatingPoint_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkFloatBits.h" -#include "include/private/SkSafe_math.h" -#include -#include +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkFloatBits.h" +#include "include/private/base/SkMath.h" + +#include #include +#include #include -#include constexpr float SK_FloatSqrt2 = 1.41421356f; constexpr float SK_FloatPI = 3.14159265f; @@ -150,7 +150,7 @@ static inline int64_t sk_float_saturate2int64(float x) { // Cast double to float, ignoring any warning about too-large finite values being cast to float. // Clang thinks this is undefined, but it's actually implementation defined to return either // the largest float or infinity (one of the two bracketing representable floats). Good enough! -SK_ATTRIBUTE(no_sanitize("float-cast-overflow")) +SK_NO_SANITIZE("float-cast-overflow") static inline float sk_double_to_float(double x) { return static_cast(x); } @@ -196,12 +196,12 @@ static inline int sk_float_nextlog2(float x) { // IEEE defines how float divide behaves for non-finite values and zero-denoms, but C does not // so we have a helper that suppresses the possible undefined-behavior warnings. -SK_ATTRIBUTE(no_sanitize("float-divide-by-zero")) +SK_NO_SANITIZE("float-divide-by-zero") static inline float sk_ieee_float_divide(float numer, float denom) { return numer / denom; } -SK_ATTRIBUTE(no_sanitize("float-divide-by-zero")) +SK_NO_SANITIZE("float-divide-by-zero") static inline double sk_ieee_double_divide(double numer, double denom) { return numer / denom; } @@ -219,4 +219,13 @@ static inline float sk_fmaf(float f, float m, float a) { #endif } +// Returns true iff the provided number is within a small epsilon of 0. +bool sk_double_nearly_zero(double a); + +// Comparing floating point numbers is complicated. This helper only works if one or none +// of the two inputs is not very close to zero. It also does not work if both inputs could be NaN. +// The term "ulps" stands for "units of least precision". Read the following for more nuance: +// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ +bool sk_doubles_nearly_equal_ulps(double a, double b, uint8_t max_ulps_diff=16); + #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h new file mode 100644 index 0000000000000..b212ada86b0e5 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h @@ -0,0 +1,63 @@ +/* + * 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 SK_USER_CONFIG_WAS_LOADED + +// Include this to set reasonable defaults (e.g. for SK_CPU_LENDIAN) +#include "include/private/base/SkFeatures.h" + +// Allows embedders that want to disable macros that take arguments to just +// define that symbol to be one of these +#define SK_NOTHING_ARG1(arg1) +#define SK_NOTHING_ARG2(arg1, arg2) +#define SK_NOTHING_ARG3(arg1, arg2, arg3) + +// IWYU pragma: begin_exports + +// Note: SK_USER_CONFIG_HEADER will not work with Bazel builds and some C++ compilers. +#if defined(SK_USER_CONFIG_HEADER) + #include SK_USER_CONFIG_HEADER +#elif defined(SK_USE_BAZEL_CONFIG_HEADER) + // The Bazel config file is presumed to be in the root directory of its Bazel Workspace. + // This is achieved in Skia by having a nested WORKSPACE in include/config and a cc_library + // defined in that folder. As a result, we do not try to include SkUserConfig.h from the + // top of Skia because Bazel sandboxing will move it to a different location. + #include "SkUserConfig.h" +#else + #include "include/config/SkUserConfig.h" +#endif +// IWYU pragma: end_exports + +// Checks to make sure the SkUserConfig options do not conflict. +#if !defined(SK_DEBUG) && !defined(SK_RELEASE) + #ifdef NDEBUG + #define SK_RELEASE + #else + #define SK_DEBUG + #endif +#endif + +#if defined(SK_DEBUG) && defined(SK_RELEASE) +# error "cannot define both SK_DEBUG and SK_RELEASE" +#elif !defined(SK_DEBUG) && !defined(SK_RELEASE) +# error "must define either SK_DEBUG or SK_RELEASE" +#endif + +#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) +# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" +#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) +# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" +#endif + +#if defined(SK_CPU_BENDIAN) && !defined(I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN) + #error "The Skia team is not endian-savvy enough to support big-endian CPUs." + #error "If you still want to use Skia," + #error "please define I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN." +#endif + +#define SK_USER_CONFIG_WAS_LOADED +#endif // SK_USER_CONFIG_WAS_LOADED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h similarity index 77% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h index 308c5d05fd4a7..5d1835d013096 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h @@ -7,8 +7,6 @@ #ifndef SkMacros_DEFINED #define SkMacros_DEFINED -#include - /* * Usage: SK_MACRO_CONCAT(a, b) to construct the symbol ab * @@ -40,6 +38,23 @@ #define SK_END_REQUIRE_DENSE #endif +#if defined(__clang__) && defined(__has_feature) + // Some compilers have a preprocessor that does not appear to do short-circuit + // evaluation as expected + #if __has_feature(leak_sanitizer) || __has_feature(address_sanitizer) + // Chrome had issues if we tried to include lsan_interface.h ourselves. + // https://github.com/llvm/llvm-project/blob/10a35632d55bb05004fe3d0c2d4432bb74897ee7/compiler-rt/include/sanitizer/lsan_interface.h#L26 +extern "C" { + void __lsan_ignore_object(const void *p); +} + #define SK_INTENTIONALLY_LEAKED(X) __lsan_ignore_object(X) + #else + #define SK_INTENTIONALLY_LEAKED(X) ((void)0) + #endif +#else + #define SK_INTENTIONALLY_LEAKED(X) ((void)0) +#endif + #define SK_INIT_TO_AVOID_WARNING = 0 //////////////////////////////////////////////////////////////////////////////// diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h similarity index 94% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h index 206bf14e2f877..1c0c2e73da625 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h @@ -8,10 +8,9 @@ #ifndef SkMalloc_DEFINED #define SkMalloc_DEFINED -#include #include -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" /* memory wrappers to be implemented by the porting layer (platform) @@ -51,7 +50,9 @@ enum { SK_API extern void* sk_malloc_flags(size_t size, unsigned flags); /** Same as standard realloc(), but this one never returns null on failure. It will throw - * an exception if it fails. + * if it fails. + * If size is 0, it will call sk_free on buffer and return null. (This behavior is implementation- + * defined for normal realloc. We follow what glibc does.) */ SK_API extern void* sk_realloc_throw(void* buffer, size_t size); @@ -78,10 +79,6 @@ SK_API extern void* sk_calloc_throw(size_t count, size_t elemSize); SK_API extern void* sk_malloc_throw(size_t count, size_t elemSize); SK_API extern void* sk_realloc_throw(void* buffer, size_t count, size_t elemSize); -// Returns the true usable size provided by the underlying allocator, or 0 if -// querying the allocation size is not supported. -SK_API extern size_t sk_malloc_usable_size(void* buffer); - /** * These variants return nullptr on failure */ diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h similarity index 64% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h index 97352afab9d6f..34bfa739f7a97 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h @@ -8,7 +8,22 @@ #ifndef SkMath_DEFINED #define SkMath_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkCPUTypes.h" + +#include +#include + +// Max Signed 16 bit value +static constexpr int16_t SK_MaxS16 = INT16_MAX; +static constexpr int16_t SK_MinS16 = -SK_MaxS16; + +static constexpr int32_t SK_MaxS32 = INT32_MAX; +static constexpr int32_t SK_MinS32 = -SK_MaxS32; +static constexpr int32_t SK_NaN32 = INT32_MIN; + +static constexpr int64_t SK_MaxS64 = INT64_MAX; +static constexpr int64_t SK_MinS64 = -SK_MaxS64; // 64bit -> 32bit utilities @@ -19,6 +34,14 @@ static inline int64_t sk_64_mul(int64_t a, int64_t b) { return a * b; } +static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { + return (int32_t) ((uint32_t) value << shift); +} + +static inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) { + return (int64_t) ((uint64_t) value << shift); +} + /////////////////////////////////////////////////////////////////////////////// /** @@ -48,7 +71,7 @@ static inline unsigned SkMul16ShiftRound(U16CPU a, U16CPU b, int shift) { * Only valid if a and b are unsigned and <= 32767. */ static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { - return SkMul16ShiftRound(a,b,8); + return SkMul16ShiftRound(a, b, 8); } #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h similarity index 86% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h index b7cdceb1e1d8d..4452beb912f56 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h @@ -8,11 +8,11 @@ #ifndef SkMutex_DEFINED #define SkMutex_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMacros.h" -#include "include/private/SkSemaphore.h" -#include "include/private/SkThreadAnnotations.h" -#include "include/private/SkThreadID.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkSemaphore.h" +#include "include/private/base/SkThreadAnnotations.h" +#include "include/private/base/SkThreadID.h" class SK_CAPABILITY("mutex") SkMutex { public: diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h similarity index 89% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h index bda5d50bb6804..ec4a4e5161199 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h @@ -8,9 +8,9 @@ #ifndef SkNoncopyable_DEFINED #define SkNoncopyable_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" -/** \class SkNoncopyable +/** \class SkNoncopyable (DEPRECATED) SkNoncopyable is the base class for objects that do not want to be copied. It hides its copy-constructor and its assignment-operator. diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h similarity index 96% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h index edf3e833582b5..97ce6b6311e0b 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h @@ -8,8 +8,10 @@ #ifndef SkOnce_DEFINED #define SkOnce_DEFINED -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkThreadAnnotations.h" + #include +#include #include // SkOnce provides call-once guarantees for Skia, much like std::once_flag/std::call_once(). diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h new file mode 100644 index 0000000000000..642bbb3489f7e --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h @@ -0,0 +1,25 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * This file contains private enums related to paths. See also skbug.com/10670 + */ + +#ifndef SkPathEnums_DEFINED +#define SkPathEnums_DEFINED + +enum class SkPathConvexity { + kConvex, + kConcave, + kUnknown, +}; + +enum class SkPathFirstDirection { + kCW, // == SkPathDirection::kCW + kCCW, // == SkPathDirection::kCCW + kUnknown, +}; + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h similarity index 64% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h index 7e59f2b0040ad..5ba4c2f9a48e2 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h @@ -8,7 +8,10 @@ #ifndef SkSafe32_DEFINED #define SkSafe32_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkMath.h" + +#include static constexpr int32_t Sk64_pin_to_s32(int64_t x) { return x < SK_MinS32 ? SK_MinS32 : (x > SK_MaxS32 ? SK_MaxS32 : (int32_t)x); @@ -31,4 +34,16 @@ static constexpr int32_t Sk32_can_overflow_sub(int32_t a, int32_t b) { return (int32_t)((uint32_t)a - (uint32_t)b); } +/** + * This is a 'safe' abs for 32-bit integers that asserts when undefined behavior would occur. + * SkTAbs (in SkTemplates.h) is a general purpose absolute-value function. + */ +static inline int32_t SkAbs32(int32_t value) { + SkASSERT(value != SK_NaN32); // The most negative int32_t can't be negated. + if (value < 0) { + value = -value; + } + return value; +} + #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h similarity index 95% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h index d7318be577919..f78ee86625a42 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h @@ -8,9 +8,10 @@ #ifndef SkSemaphore_DEFINED #define SkSemaphore_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkOnce.h" -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkThreadAnnotations.h" + #include #include diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h new file mode 100644 index 0000000000000..5f31a651bb375 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h @@ -0,0 +1,129 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkSpan_DEFINED +#define SkSpan_DEFINED + +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTo.h" + +#include +#include +#include +#include +#include + +// Having this be an export works around IWYU churn related to +// https://github.com/include-what-you-use/include-what-you-use/issues/1121 +#include // IWYU pragma: export + +// Add macro to check the lifetime of initializer_list arguments. initializer_list has a very +// short life span, and can only be used as a parameter, and not as a variable. +#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::lifetimebound) +#define SK_CHECK_IL_LIFETIME [[clang::lifetimebound]] +#else +#define SK_CHECK_IL_LIFETIME +#endif + +/** + * SkSpan holds a reference to contiguous data of type T along with a count. SkSpan does not own + * the data itself but is merely a reference, therefore you must take care with the lifetime of + * the underlying data. + * + * SkSpan is a count and a pointer into existing array or data type that stores its data in + * contiguous memory like std::vector. Any container that works with std::size() and std::data() + * can be used. + * + * SkSpan makes a convenient parameter for a routine to accept array like things. This allows you to + * write the routine without overloads for all different container types. + * + * Example: + * void routine(SkSpan a) { ... } + * + * std::vector v = {1, 2, 3, 4, 5}; + * + * routine(a); + * + * A word of caution when working with initializer_list, initializer_lists have a lifetime that is + * limited to the current statement. The following is correct and safe: + * + * Example: + * routine({1,2,3,4,5}); + * + * The following is undefined, and will result in erratic execution: + * + * Bad Example: + * initializer_list l = {1, 2, 3, 4, 5}; // The data behind l dies at the ;. + * routine(l); + */ +template +class SkSpan { +public: + constexpr SkSpan() : fPtr{nullptr}, fSize{0} {} + + template , bool> = true> + constexpr SkSpan(T* ptr, Integer size) : fPtr{ptr}, fSize{SkToSizeT(size)} { + SkASSERT(ptr || fSize == 0); // disallow nullptr + a nonzero size + SkASSERT(fSize < kMaxSize); + } + template >> + constexpr SkSpan(const SkSpan& that) : fPtr(std::data(that)), fSize(std::size(that)) {} + constexpr SkSpan(const SkSpan& o) = default; + template constexpr SkSpan(T(&a)[N]) : SkSpan(a, N) { } + template + constexpr SkSpan(Container& c) : SkSpan(std::data(c), std::size(c)) { } + SkSpan(std::initializer_list il SK_CHECK_IL_LIFETIME) + : SkSpan(std::data(il), std::size(il)) {} + + constexpr SkSpan& operator=(const SkSpan& that) = default; + + constexpr T& operator [] (size_t i) const { + SkASSERT(i < this->size()); + return fPtr[i]; + } + constexpr T& front() const { return fPtr[0]; } + constexpr T& back() const { return fPtr[fSize - 1]; } + constexpr T* begin() const { return fPtr; } + constexpr T* end() const { return fPtr + fSize; } + constexpr auto rbegin() const { return std::make_reverse_iterator(this->end()); } + constexpr auto rend() const { return std::make_reverse_iterator(this->begin()); } + constexpr T* data() const { return this->begin(); } + constexpr size_t size() const { return fSize; } + constexpr bool empty() const { return fSize == 0; } + constexpr size_t size_bytes() const { return fSize * sizeof(T); } + constexpr SkSpan first(size_t prefixLen) const { + SkASSERT(prefixLen <= this->size()); + return SkSpan{fPtr, prefixLen}; + } + constexpr SkSpan last(size_t postfixLen) const { + SkASSERT(postfixLen <= this->size()); + return SkSpan{fPtr + (this->size() - postfixLen), postfixLen}; + } + constexpr SkSpan subspan(size_t offset) const { + return this->subspan(offset, this->size() - offset); + } + constexpr SkSpan subspan(size_t offset, size_t count) const { + SkASSERT(offset <= this->size()); + SkASSERT(count <= this->size() - offset); + return SkSpan{fPtr + offset, count}; + } + +private: + static const constexpr size_t kMaxSize = std::numeric_limits::max() / sizeof(T); + T* fPtr; + size_t fSize; +}; + +template +SkSpan(Container&) -> + SkSpan()))>>; + +template +SkSpan(std::initializer_list) -> + SkSpan>()))>>; + +#endif // SkSpan_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h new file mode 100644 index 0000000000000..de8e276513b2e --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h @@ -0,0 +1,694 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkTArray_DEFINED +#define SkTArray_DEFINED + +#include "include/private/base/SkAlignedStorage.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkContainers.h" +#include "include/private/base/SkMalloc.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkSpan_impl.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" // IWYU pragma: keep + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace skia_private { +/** TArray implements a typical, mostly std::vector-like array. + Each T will be default-initialized on allocation, and ~T will be called on destruction. + + MEM_MOVE controls the behavior when a T needs to be moved (e.g. when the array is resized) + - true: T will be bit-copied via memcpy. + - false: T will be moved via move-constructors. +*/ +template > class TArray { +public: + using value_type = T; + + /** + * Creates an empty array with no initial storage + */ + TArray() : fOwnMemory(true), fCapacity{0} {} + + /** + * Creates an empty array that will preallocate space for reserveCount + * elements. + */ + explicit TArray(int reserveCount) : TArray() { this->reserve_back(reserveCount); } + + /** + * Copies one array to another. The new array will be heap allocated. + */ + TArray(const TArray& that) : TArray(that.fData, that.fSize) {} + + TArray(TArray&& that) { + if (that.fOwnMemory) { + this->setData(that); + that.setData({}); + } else { + this->initData(that.fSize); + that.move(fData); + } + fSize = std::exchange(that.fSize, 0); + } + + /** + * Creates a TArray by copying contents of a standard C array. The new + * array will be heap allocated. Be careful not to use this constructor + * when you really want the (void*, int) version. + */ + TArray(const T* array, int count) { + this->initData(count); + this->copy(array); + } + + /** + * Creates a TArray by copying contents of an initializer list. + */ + TArray(std::initializer_list data) : TArray(data.begin(), data.size()) {} + + TArray& operator=(const TArray& that) { + if (this == &that) { + return *this; + } + this->clear(); + this->checkRealloc(that.size(), kExactFit); + fSize = that.fSize; + this->copy(that.fData); + return *this; + } + TArray& operator=(TArray&& that) { + if (this != &that) { + this->clear(); + if (that.fOwnMemory) { + // The storage is on the heap, so move the data pointer. + if (fOwnMemory) { + sk_free(fData); + } + + fData = std::exchange(that.fData, nullptr); + + // Can't use exchange with bitfields. + fCapacity = that.fCapacity; + that.fCapacity = 0; + + fOwnMemory = true; + } else { + // The data is stored inline in that, so move it element-by-element. + this->checkRealloc(that.size(), kExactFit); + that.move(fData); + } + fSize = std::exchange(that.fSize, 0); + } + return *this; + } + + ~TArray() { + this->destroyAll(); + if (fOwnMemory) { + sk_free(fData); + } + } + + /** + * Resets to size() = n newly constructed T objects and resets any reserve count. + */ + void reset(int n) { + SkASSERT(n >= 0); + this->clear(); + this->checkRealloc(n, kExactFit); + fSize = n; + for (int i = 0; i < this->size(); ++i) { + new (fData + i) T; + } + } + + /** + * Resets to a copy of a C array and resets any reserve count. + */ + void reset(const T* array, int count) { + SkASSERT(count >= 0); + this->clear(); + this->checkRealloc(count, kExactFit); + fSize = count; + this->copy(array); + } + + /** + * Ensures there is enough reserved space for n elements. + */ + void reserve(int n) { + SkASSERT(n >= 0); + if (n > this->size()) { + this->checkRealloc(n - this->size(), kGrowing); + } + } + + /** + * Ensures there is enough reserved space for n additional elements. The is guaranteed at least + * until the array size grows above n and subsequently shrinks below n, any version of reset() + * is called, or reserve_back() is called again. + */ + void reserve_back(int n) { + SkASSERT(n >= 0); + if (n > 0) { + this->checkRealloc(n, kExactFit); + } + } + + void removeShuffle(int n) { + SkASSERT(n < this->size()); + int newCount = fSize - 1; + fSize = newCount; + fData[n].~T(); + if (n != newCount) { + this->move(n, newCount); + } + } + + // Is the array empty. + bool empty() const { return fSize == 0; } + + /** + * Adds 1 new default-initialized T value and returns it by reference. Note + * the reference only remains valid until the next call that adds or removes + * elements. + */ + T& push_back() { + void* newT = this->push_back_raw(1); + return *new (newT) T; + } + + /** + * Version of above that uses a copy constructor to initialize the new item + */ + T& push_back(const T& t) { + void* newT = this->push_back_raw(1); + return *new (newT) T(t); + } + + /** + * Version of above that uses a move constructor to initialize the new item + */ + T& push_back(T&& t) { + void* newT = this->push_back_raw(1); + return *new (newT) T(std::move(t)); + } + + /** + * Construct a new T at the back of this array. + */ + template T& emplace_back(Args&&... args) { + void* newT = this->push_back_raw(1); + return *new (newT) T(std::forward(args)...); + } + + /** + * Allocates n more default-initialized T values, and returns the address of + * the start of that new range. Note: this address is only valid until the + * next API call made on the array that might add or remove elements. + */ + T* push_back_n(int n) { + SkASSERT(n >= 0); + T* newTs = TCast(this->push_back_raw(n)); + for (int i = 0; i < n; ++i) { + new (&newTs[i]) T; + } + return newTs; + } + + /** + * Version of above that uses a copy constructor to initialize all n items + * to the same T. + */ + T* push_back_n(int n, const T& t) { + SkASSERT(n >= 0); + T* newTs = TCast(this->push_back_raw(n)); + for (int i = 0; i < n; ++i) { + new (&newTs[i]) T(t); + } + return static_cast(newTs); + } + + /** + * Version of above that uses a copy constructor to initialize the n items + * to separate T values. + */ + T* push_back_n(int n, const T t[]) { + SkASSERT(n >= 0); + this->checkRealloc(n, kGrowing); + T* end = this->end(); + for (int i = 0; i < n; ++i) { + new (end + i) T(t[i]); + } + fSize += n; + return end; + } + + /** + * Version of above that uses the move constructor to set n items. + */ + T* move_back_n(int n, T* t) { + SkASSERT(n >= 0); + this->checkRealloc(n, kGrowing); + T* end = this->end(); + for (int i = 0; i < n; ++i) { + new (end + i) T(std::move(t[i])); + } + fSize += n; + return end; + } + + /** + * Removes the last element. Not safe to call when size() == 0. + */ + void pop_back() { + SkASSERT(fSize > 0); + --fSize; + fData[fSize].~T(); + } + + /** + * Removes the last n elements. Not safe to call when size() < n. + */ + void pop_back_n(int n) { + SkASSERT(n >= 0); + SkASSERT(this->size() >= n); + int i = fSize; + while (i-- > fSize - n) { + (*this)[i].~T(); + } + fSize -= n; + } + + /** + * Pushes or pops from the back to resize. Pushes will be default + * initialized. + */ + void resize_back(int newCount) { + SkASSERT(newCount >= 0); + + if (newCount > this->size()) { + this->push_back_n(newCount - fSize); + } else if (newCount < this->size()) { + this->pop_back_n(fSize - newCount); + } + } + + /** Swaps the contents of this array with that array. Does a pointer swap if possible, + otherwise copies the T values. */ + void swap(TArray& that) { + using std::swap; + if (this == &that) { + return; + } + if (fOwnMemory && that.fOwnMemory) { + swap(fData, that.fData); + swap(fSize, that.fSize); + + // Can't use swap because fCapacity is a bit field. + auto allocCount = fCapacity; + fCapacity = that.fCapacity; + that.fCapacity = allocCount; + } else { + // This could be more optimal... + TArray copy(std::move(that)); + that = std::move(*this); + *this = std::move(copy); + } + } + + T* begin() { + return fData; + } + const T* begin() const { + return fData; + } + + // It's safe to use fItemArray + fSize because if fItemArray is nullptr then adding 0 is + // valid and returns nullptr. See [expr.add] in the C++ standard. + T* end() { + if (fData == nullptr) { + SkASSERT(fSize == 0); + } + return fData + fSize; + } + const T* end() const { + if (fData == nullptr) { + SkASSERT(fSize == 0); + } + return fData + fSize; + } + T* data() { return fData; } + const T* data() const { return fData; } + int size() const { return fSize; } + size_t size_bytes() const { return this->bytes(fSize); } + void resize(size_t count) { this->resize_back((int)count); } + + void clear() { + this->destroyAll(); + fSize = 0; + } + + void shrink_to_fit() { + if (!fOwnMemory || fSize == fCapacity) { + return; + } + if (fSize == 0) { + sk_free(fData); + fData = nullptr; + fCapacity = 0; + } else { + SkSpan allocation = Allocate(fSize); + this->move(TCast(allocation.data())); + if (fOwnMemory) { + sk_free(fData); + } + this->setDataFromBytes(allocation); + } + } + + /** + * Get the i^th element. + */ + T& operator[] (int i) { + SkASSERT(i < this->size()); + SkASSERT(i >= 0); + return fData[i]; + } + + const T& operator[] (int i) const { + SkASSERT(i < this->size()); + SkASSERT(i >= 0); + return fData[i]; + } + + T& at(int i) { return (*this)[i]; } + const T& at(int i) const { return (*this)[i]; } + + /** + * equivalent to operator[](0) + */ + T& front() { SkASSERT(fSize > 0); return fData[0];} + + const T& front() const { SkASSERT(fSize > 0); return fData[0];} + + /** + * equivalent to operator[](size() - 1) + */ + T& back() { SkASSERT(fSize); return fData[fSize - 1];} + + const T& back() const { SkASSERT(fSize > 0); return fData[fSize - 1];} + + /** + * equivalent to operator[](size()-1-i) + */ + T& fromBack(int i) { + SkASSERT(i >= 0); + SkASSERT(i < this->size()); + return fData[fSize - i - 1]; + } + + const T& fromBack(int i) const { + SkASSERT(i >= 0); + SkASSERT(i < this->size()); + return fData[fSize - i - 1]; + } + + bool operator==(const TArray& right) const { + int leftCount = this->size(); + if (leftCount != right.size()) { + return false; + } + for (int index = 0; index < leftCount; ++index) { + if (fData[index] != right.fData[index]) { + return false; + } + } + return true; + } + + bool operator!=(const TArray& right) const { + return !(*this == right); + } + + int capacity() const { + return fCapacity; + } + +protected: + // Creates an empty array that will use the passed storage block until it is insufficiently + // large to hold the entire array. + template + TArray(SkAlignedSTStorage* storage, int size = 0) { + static_assert(InitialCapacity >= 0); + SkASSERT(size >= 0); + SkASSERT(storage->get() != nullptr); + if (size > InitialCapacity) { + this->initData(size); + } else { + this->setDataFromBytes(*storage); + fSize = size; + + // setDataFromBytes always sets fOwnMemory to true, but we are actually using static + // storage here, which shouldn't ever be freed. + fOwnMemory = false; + } + } + + // Copy a C array, using pre-allocated storage if preAllocCount >= count. Otherwise, storage + // will only be used when array shrinks to fit. + template + TArray(const T* array, int size, SkAlignedSTStorage* storage) + : TArray{storage, size} + { + this->copy(array); + } + +private: + // Growth factors for checkRealloc. + static constexpr double kExactFit = 1.0; + static constexpr double kGrowing = 1.5; + + static constexpr int kMinHeapAllocCount = 8; + static_assert(SkIsPow2(kMinHeapAllocCount), "min alloc count not power of two."); + + // Note for 32-bit machines kMaxCapacity will be <= SIZE_MAX. For 64-bit machines it will + // just be INT_MAX if the sizeof(T) < 2^32. + static constexpr int kMaxCapacity = SkToInt(std::min(SIZE_MAX / sizeof(T), (size_t)INT_MAX)); + + void setDataFromBytes(SkSpan allocation) { + T* data = TCast(allocation.data()); + // We have gotten extra bytes back from the allocation limit, pin to kMaxCapacity. It + // would seem like the SkContainerAllocator should handle the divide, but it would have + // to a full divide instruction. If done here the size is known at compile, and usually + // can be implemented by a right shift. The full divide takes ~50X longer than the shift. + size_t size = std::min(allocation.size() / sizeof(T), SkToSizeT(kMaxCapacity)); + setData(SkSpan(data, size)); + } + + void setData(SkSpan array) { + fData = array.data(); + fCapacity = SkToU32(array.size()); + fOwnMemory = true; + } + + // We disable Control-Flow Integrity sanitization (go/cfi) when casting item-array buffers. + // CFI flags this code as dangerous because we are casting `buffer` to a T* while the buffer's + // contents might still be uninitialized memory. When T has a vtable, this is especially risky + // because we could hypothetically access a virtual method on fItemArray and jump to an + // unpredictable location in memory. Of course, TArray won't actually use fItemArray in this + // way, and we don't want to construct a T before the user requests one. There's no real risk + // here, so disable CFI when doing these casts. + SK_CLANG_NO_SANITIZE("cfi") + static T* TCast(void* buffer) { + return (T*)buffer; + } + + size_t bytes(int n) const { + SkASSERT(n <= kMaxCapacity); + return SkToSizeT(n) * sizeof(T); + } + + static SkSpan Allocate(int capacity, double growthFactor = 1.0) { + return SkContainerAllocator{sizeof(T), kMaxCapacity}.allocate(capacity, growthFactor); + } + + void initData(int count) { + this->setDataFromBytes(Allocate(count)); + fSize = count; + } + + void destroyAll() { + if (!this->empty()) { + T* cursor = this->begin(); + T* const end = this->end(); + do { + cursor->~T(); + cursor++; + } while (cursor < end); + } + } + + /** In the following move and copy methods, 'dst' is assumed to be uninitialized raw storage. + * In the following move methods, 'src' is destroyed leaving behind uninitialized raw storage. + */ + void copy(const T* src) { + if constexpr (std::is_trivially_copyable_v) { + if (!this->empty() && src != nullptr) { + sk_careful_memcpy(fData, src, this->size_bytes()); + } + } else { + for (int i = 0; i < this->size(); ++i) { + new (fData + i) T(src[i]); + } + } + } + + void move(int dst, int src) { + if constexpr (MEM_MOVE) { + memcpy(static_cast(&fData[dst]), + static_cast(&fData[src]), + sizeof(T)); + } else { + new (&fData[dst]) T(std::move(fData[src])); + fData[src].~T(); + } + } + + void move(void* dst) { + if constexpr (MEM_MOVE) { + sk_careful_memcpy(dst, fData, this->bytes(fSize)); + } else { + for (int i = 0; i < this->size(); ++i) { + new (static_cast(dst) + this->bytes(i)) T(std::move(fData[i])); + fData[i].~T(); + } + } + } + + // Helper function that makes space for n objects, adjusts the count, but does not initialize + // the new objects. + void* push_back_raw(int n) { + this->checkRealloc(n, kGrowing); + void* ptr = fData + fSize; + fSize += n; + return ptr; + } + + void checkRealloc(int delta, double growthFactor) { + // This constant needs to be declared in the function where it is used to work around + // MSVC's persnickety nature about template definitions. + SkASSERT(delta >= 0); + SkASSERT(fSize >= 0); + SkASSERT(fCapacity >= 0); + + // Return if there are enough remaining allocated elements to satisfy the request. + if (this->capacity() - fSize >= delta) { + return; + } + + // Don't overflow fSize or size_t later in the memory allocation. Overflowing memory + // allocation really only applies to fSizes on 32-bit machines; on 64-bit machines this + // will probably never produce a check. Since kMaxCapacity is bounded above by INT_MAX, + // this also checks the bounds of fSize. + if (delta > kMaxCapacity - fSize) { + sk_report_container_overflow_and_die(); + } + const int newCount = fSize + delta; + + SkSpan allocation = Allocate(newCount, growthFactor); + + this->move(TCast(allocation.data())); + if (fOwnMemory) { + sk_free(fData); + } + this->setDataFromBytes(allocation); + SkASSERT(this->capacity() >= newCount); + SkASSERT(fData != nullptr); + } + + T* fData{nullptr}; + int fSize{0}; + uint32_t fOwnMemory : 1; + uint32_t fCapacity : 31; +}; + +template static inline void swap(TArray& a, TArray& b) { + a.swap(b); +} + +// Subclass of TArray that contains a pre-allocated memory block for the array. +template > +class STArray : private SkAlignedSTStorage, public TArray { + static_assert(N > 0); + using Storage = SkAlignedSTStorage; + +public: + STArray() + : Storage{} + , TArray(this) {} // Must use () to avoid confusion with initializer_list + // when T=bool because * are convertable to bool. + + STArray(const T* array, int count) + : Storage{} + , TArray{array, count, this} {} + + STArray(std::initializer_list data) + : STArray{data.begin(), SkToInt(data.size())} {} + + explicit STArray(int reserveCount) + : STArray() { this->reserve_back(reserveCount); } + + STArray(const STArray& that) + : STArray() { *this = that; } + + explicit STArray(const TArray& that) + : STArray() { *this = that; } + + STArray(STArray&& that) + : STArray() { *this = std::move(that); } + + explicit STArray(TArray&& that) + : STArray() { *this = std::move(that); } + + STArray& operator=(const STArray& that) { + TArray::operator=(that); + return *this; + } + + STArray& operator=(const TArray& that) { + TArray::operator=(that); + return *this; + } + + STArray& operator=(STArray&& that) { + TArray::operator=(std::move(that)); + return *this; + } + + STArray& operator=(TArray&& that) { + TArray::operator=(std::move(that)); + return *this; + } + + // Force the use of TArray for data() and size(). + using TArray::data; + using TArray::size; +}; +} // namespace skia_private +#endif // SkTArray_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h similarity index 81% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h index 1b56266535a56..b08d285378b10 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h @@ -8,21 +8,18 @@ #ifndef SkTDArray_DEFINED #define SkTDArray_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTo.h" #include #include -#include #include -#include -#include class SK_SPI SkTDStorage { public: explicit SkTDStorage(int sizeOfT); - SkTDStorage(const void* src, int count, int sizeOfT); + SkTDStorage(const void* src, int size, int sizeOfT); // Copy SkTDStorage(const SkTDStorage& that); @@ -38,15 +35,15 @@ class SK_SPI SkTDStorage { void swap(SkTDStorage& that); // Size routines - bool empty() const { return fCount == 0; } - void clear() { fCount = 0; } - int size() const { return fCount; } - void resize(int newCount); - size_t size_bytes() const { return this->bytes(fCount); } + bool empty() const { return fSize == 0; } + void clear() { fSize = 0; } + int size() const { return fSize; } + void resize(int newSize); + size_t size_bytes() const { return this->bytes(fSize); } // Capacity routines - int capacity() const { return fReserve; } - void reserve(int newReserve); + int capacity() const { return fCapacity; } + void reserve(int newCapacity); void shrink_to_fit(); void* data() { return fStorage; } @@ -68,8 +65,8 @@ class SK_SPI SkTDStorage { void* insert(int index, int count, const void* src); void pop_back() { - SkASSERT(fCount > 0); - fCount--; + SkASSERT(fSize > 0); + fSize--; } friend bool operator==(const SkTDStorage& a, const SkTDStorage& b); @@ -81,7 +78,7 @@ class SK_SPI SkTDStorage { size_t bytes(int n) const { return SkToSizeT(n * fSizeOfT); } void* address(int n) { return fStorage + this->bytes(n); } - // Adds delta to fCount. Crash if outside [0, INT_MAX] + // Adds delta to fSize. Crash if outside [0, INT_MAX] int calculateSizeOrDie(int delta); // Move the tail of the array defined by the indexes tailStart and tailEnd to dstIndex. The @@ -93,8 +90,8 @@ class SK_SPI SkTDStorage { const int fSizeOfT; std::byte* fStorage{nullptr}; - int fReserve{0}; // size of the allocation in fArray (#elements) - int fCount{0}; // logical number of elements (fCount <= fReserve) + int fCapacity{0}; // size of the allocation in fArray (#elements) + int fSize{0}; // logical number of elements (fSize <= fCapacity) }; static inline void swap(SkTDStorage& a, SkTDStorage& b) { @@ -188,7 +185,7 @@ template class SkTDArray { fStorage.resize(count); } - void reserve(size_t n) { + void reserve(int n) { fStorage.reserve(n); } @@ -219,18 +216,6 @@ template class SkTDArray { fStorage.removeShuffle(index); } - int find(const T& elem) const { - const T* iter = this->begin(); - const T* stop = this->end(); - - for (; iter < stop; iter++) { - if (*iter == elem) { - return SkToInt(iter - this->begin()); - } - } - return -1; - } - // routines to treat the array like a stack void push_back(const T& v) { this->append(); @@ -238,28 +223,6 @@ template class SkTDArray { } void pop_back() { fStorage.pop_back(); } - void deleteAll() { - for (T p : *this) { - delete p; - } - this->reset(); - } - - void freeAll() { - for (T p : *this) { - sk_free(p); - } - - this->reset(); - } - - void unrefAll() { - for (T p : *this) { - p->unref(); - } - this->reset(); - } - void shrink_to_fit() { fStorage.shrink_to_fit(); } diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h similarity index 82% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h index a912f13e08c01..365748abef483 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h @@ -8,8 +8,10 @@ #ifndef SkTFitsIn_DEFINED #define SkTFitsIn_DEFINED +#include "include/private/base/SkDebug.h" + +#include #include -#include #include /** @@ -71,28 +73,32 @@ static constexpr inline typename std::enable_if<(std::is_integral::value || std::is_enum::value) && (std::is_integral::value || std::is_enum::value), bool>::type /*bool*/ SkTFitsIn(S src) { + // Ensure that is_signed and is_unsigned are passed the arithmetic underlyng types of enums. + using Sa = typename sk_strip_enum::type; + using Da = typename sk_strip_enum::type; + // SkTFitsIn() is used in public headers, so needs to be written targeting at most C++11. return // E.g. (int8_t)(uint8_t) int8_t(-1) == -1, but the uint8_t == 255, not -1. - (std::is_signed::value && std::is_unsigned::value && sizeof(S) <= sizeof(D)) ? + (std::is_signed::value && std::is_unsigned::value && sizeof(Sa) <= sizeof(Da)) ? (S)0 <= src : // E.g. (uint8_t)(int8_t) uint8_t(255) == 255, but the int8_t == -1. - (std::is_signed::value && std::is_unsigned::value && sizeof(D) <= sizeof(S)) ? - src <= (S)std::numeric_limits::type>::max() : + (std::is_signed::value && std::is_unsigned::value && sizeof(Da) <= sizeof(Sa)) ? + src <= (S)std::numeric_limits::max() : #if !defined(SK_DEBUG) && !defined(__MSVC_RUNTIME_CHECKS ) // Correct (simple) version. This trips up MSVC's /RTCc run-time checking. (S)(D)src == src; #else // More complex version that's safe with /RTCc. Used in all debug builds, for coverage. - (std::is_signed::value) ? - (intmax_t)src >= (intmax_t)std::numeric_limits::type>::min() && - (intmax_t)src <= (intmax_t)std::numeric_limits::type>::max() : + (std::is_signed::value) ? + (intmax_t)src >= (intmax_t)std::numeric_limits::min() && + (intmax_t)src <= (intmax_t)std::numeric_limits::max() : // std::is_unsigned ? - (uintmax_t)src <= (uintmax_t)std::numeric_limits::type>::max(); + (uintmax_t)src <= (uintmax_t)std::numeric_limits::max(); #endif } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h similarity index 98% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h index dce0dc804becd..26f363c94699e 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h @@ -14,7 +14,7 @@ #include #include -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" // The sknonstd namespace contains things we would like to be proposed and feel std-ish. namespace sknonstd { diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTPin.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTPin.h similarity index 100% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTPin.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTPin.h diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h similarity index 73% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h index 16b0e0e586a29..cbcf36c5943b8 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h @@ -8,18 +8,21 @@ #ifndef SkTemplates_DEFINED #define SkTemplates_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkAlign.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMalloc.h" +#include "include/private/base/SkTLogic.h" -#include #include #include +#include +#include #include -#include #include #include + /** \file SkTemplates.h This file contains light-weight template classes for type-safe and exception-safe @@ -32,6 +35,17 @@ */ template inline void sk_ignore_unused_variable(const T&) { } +/** + * This is a general purpose absolute-value function. + * See SkAbs32 in (SkSafe32.h) for a 32-bit int specific version that asserts. + */ +template static inline T SkTAbs(T value) { + if (value < 0) { + value = -value; + } + return value; +} + /** * Returns a pointer to a D which comes immediately after S[count]. */ @@ -48,14 +62,16 @@ template inline D* SkTAddOffset(S* ptr, ptrdiff_t byteO return reinterpret_cast(reinterpret_cast*>(ptr) + byteOffset); } -// TODO: when C++17 the language is available, use template -template struct SkFunctionWrapper { +template struct SkOverloadedFunctionObject { template auto operator()(Args&&... args) const -> decltype(P(std::forward(args)...)) { return P(std::forward(args)...); } }; +template using SkFunctionObject = + SkOverloadedFunctionObject, F>; + /** \class SkAutoTCallVProc Call a function when this goes out of scope. The template uses two @@ -65,8 +81,8 @@ template struct SkFunctionWrapper { function. */ template class SkAutoTCallVProc - : public std::unique_ptr, P>> { - using inherited = std::unique_ptr, P>>; + : public std::unique_ptr> { + using inherited = std::unique_ptr>; public: using inherited::inherited; SkAutoTCallVProc(const SkAutoTCallVProc&) = delete; @@ -75,14 +91,16 @@ template class SkAutoTCallVProc operator T*() const { return this->get(); } }; + +namespace skia_private { /** Allocate an array of T elements, and free the array in the destructor */ -template class SkAutoTArray { +template class AutoTArray { public: - SkAutoTArray() {} + AutoTArray() {} /** Allocate count number of T elements */ - explicit SkAutoTArray(int count) { + explicit AutoTArray(int count) { SkASSERT(count >= 0); if (count) { fArray.reset(new T[count]); @@ -90,10 +108,10 @@ template class SkAutoTArray { SkDEBUGCODE(fCount = count;) } - SkAutoTArray(SkAutoTArray&& other) : fArray(std::move(other.fArray)) { + AutoTArray(AutoTArray&& other) : fArray(std::move(other.fArray)) { SkDEBUGCODE(fCount = other.fCount; other.fCount = 0;) } - SkAutoTArray& operator=(SkAutoTArray&& other) { + AutoTArray& operator=(AutoTArray&& other) { if (this != &other) { fArray = std::move(other.fArray); SkDEBUGCODE(fCount = other.fCount; other.fCount = 0;) @@ -103,7 +121,7 @@ template class SkAutoTArray { /** Reallocates given a new count. Reallocation occurs even if new count equals old count. */ - void reset(int count = 0) { *this = SkAutoTArray(count); } + void reset(int count = 0) { *this = AutoTArray(count); } /** Return the array of T elements. Will be NULL if count == 0 */ @@ -125,30 +143,30 @@ template class SkAutoTArray { SkDEBUGCODE(int fCount = 0;) }; -/** Wraps SkAutoTArray, with room for kCountRequested elements preallocated. +/** Wraps AutoTArray, with room for kCountRequested elements preallocated. */ -template class SkAutoSTArray { +template class AutoSTArray { public: - SkAutoSTArray(SkAutoSTArray&&) = delete; - SkAutoSTArray(const SkAutoSTArray&) = delete; - SkAutoSTArray& operator=(SkAutoSTArray&&) = delete; - SkAutoSTArray& operator=(const SkAutoSTArray&) = delete; + AutoSTArray(AutoSTArray&&) = delete; + AutoSTArray(const AutoSTArray&) = delete; + AutoSTArray& operator=(AutoSTArray&&) = delete; + AutoSTArray& operator=(const AutoSTArray&) = delete; /** Initialize with no objects */ - SkAutoSTArray() { + AutoSTArray() { fArray = nullptr; fCount = 0; } /** Allocate count number of T elements */ - SkAutoSTArray(int count) { + AutoSTArray(int count) { fArray = nullptr; fCount = 0; this->reset(count); } - ~SkAutoSTArray() { + ~AutoSTArray() { this->reset(0); } @@ -216,8 +234,8 @@ template class SkAutoSTArray { private: #if defined(SK_BUILD_FOR_GOOGLE3) - // Stack frame size is limited for SK_BUILD_FOR_GOOGLE3. 4k is less than the actual max, but some functions - // have multiple large stack allocations. + // Stack frame size is limited for SK_BUILD_FOR_GOOGLE3. 4k is less than the actual max, + // but some functions have multiple large stack allocations. static const int kMaxBytes = 4 * 1024; static const int kCount = kCountRequested * sizeof(T) > kMaxBytes ? kMaxBytes / sizeof(T) @@ -226,10 +244,9 @@ template class SkAutoSTArray { static const int kCount = kCountRequested; #endif - int fCount; - T* fArray; - // since we come right after fArray, fStorage should be properly aligned - char fStorage[kCount * sizeof(T)]; + int fCount; + T* fArray; + alignas(T) char fStorage[kCount * sizeof(T)]; }; /** Manages an array of T elements, freeing the array in the destructor. @@ -238,17 +255,17 @@ template class SkAutoSTArray { template ::value && std::is_trivially_destructible::value>> -class SkAutoTMalloc { +class AutoTMalloc { public: /** Takes ownership of the ptr. The ptr must be a value which can be passed to sk_free. */ - explicit SkAutoTMalloc(T* ptr = nullptr) : fPtr(ptr) {} + explicit AutoTMalloc(T* ptr = nullptr) : fPtr(ptr) {} /** Allocates space for 'count' Ts. */ - explicit SkAutoTMalloc(size_t count) + explicit AutoTMalloc(size_t count) : fPtr(count ? (T*)sk_malloc_throw(count, sizeof(T)) : nullptr) {} - SkAutoTMalloc(SkAutoTMalloc&&) = default; - SkAutoTMalloc& operator=(SkAutoTMalloc&&) = default; + AutoTMalloc(AutoTMalloc&&) = default; + AutoTMalloc& operator=(AutoTMalloc&&) = default; /** Resize the memory area pointed to by the current ptr preserving contents. */ void realloc(size_t count) { @@ -283,18 +300,18 @@ class SkAutoTMalloc { T* release() { return fPtr.release(); } private: - std::unique_ptr> fPtr; + std::unique_ptr> fPtr; }; template ::value && std::is_trivially_destructible::value>> -class SkAutoSTMalloc { +class AutoSTMalloc { public: - SkAutoSTMalloc() : fPtr(fTStorage) {} + AutoSTMalloc() : fPtr(fTStorage) {} - SkAutoSTMalloc(size_t count) { + AutoSTMalloc(size_t count) { if (count > kCount) { fPtr = (T*)sk_malloc_throw(count, sizeof(T)); } else if (count) { @@ -304,12 +321,12 @@ class SkAutoSTMalloc { } } - SkAutoSTMalloc(SkAutoSTMalloc&&) = delete; - SkAutoSTMalloc(const SkAutoSTMalloc&) = delete; - SkAutoSTMalloc& operator=(SkAutoSTMalloc&&) = delete; - SkAutoSTMalloc& operator=(const SkAutoSTMalloc&) = delete; + AutoSTMalloc(AutoSTMalloc&&) = delete; + AutoSTMalloc(const AutoSTMalloc&) = delete; + AutoSTMalloc& operator=(AutoSTMalloc&&) = delete; + AutoSTMalloc& operator=(const AutoSTMalloc&) = delete; - ~SkAutoSTMalloc() { + ~AutoSTMalloc() { if (fPtr != fTStorage) { sk_free(fPtr); } @@ -391,27 +408,9 @@ class SkAutoSTMalloc { }; }; -////////////////////////////////////////////////////////////////////////////////////////////////// +using UniqueVoidPtr = std::unique_ptr>; -template class SkAlignedSTStorage { -public: - SkAlignedSTStorage() {} - SkAlignedSTStorage(SkAlignedSTStorage&&) = delete; - SkAlignedSTStorage(const SkAlignedSTStorage&) = delete; - SkAlignedSTStorage& operator=(SkAlignedSTStorage&&) = delete; - SkAlignedSTStorage& operator=(const SkAlignedSTStorage&) = delete; - - /** - * Returns void* because this object does not initialize the - * memory. Use placement new for types that require a constructor. - */ - void* get() { return fStorage; } - const void* get() const { return fStorage; } -private: - alignas(T) char fStorage[sizeof(T)*N]; -}; - -using SkAutoFree = std::unique_ptr>; +} // namespace skia_private template constexpr auto SkMakeArrayFromIndexSequence(C c, std::index_sequence is) @@ -424,28 +423,4 @@ template constexpr auto SkMakeArray(C c) return SkMakeArrayFromIndexSequence(c, std::make_index_sequence{}); } -/** - * Trait for identifying types which are relocatable via memcpy, for container optimizations. - * - */ -template -struct sk_has_trivially_relocatable_member : std::false_type {}; - -// Types can declare themselves trivially relocatable with a public -// using sk_is_trivially_relocatable = std::true_type; -template -struct sk_has_trivially_relocatable_member> - : T::sk_is_trivially_relocatable {}; - -// By default, all trivially copyable types are trivially relocatable. -template -struct sk_is_trivially_relocatable - : std::disjunction, sk_has_trivially_relocatable_member ->{}; - -// Here be some dragons: while technically not guaranteed, we count on all sane unique_ptr -// implementations to be trivially relocatable. -template -struct sk_is_trivially_relocatable> : std::true_type {}; - #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkThreadAnnotations.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadAnnotations.h similarity index 100% rename from ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/SkThreadAnnotations.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadAnnotations.h diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h similarity index 69% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h index e14388b3de5bd..18984884c96f7 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h @@ -8,11 +8,14 @@ #ifndef SkThreadID_DEFINED #define SkThreadID_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" + +#include typedef int64_t SkThreadID; -// SkMutex.h uses SkGetThredID in debug only code. +// SkMutex.h uses SkGetThreadID in debug only code. SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID(); const SkThreadID kIllegalThreadID = 0; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h similarity index 71% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h index d788f7b269dad..51ccafeeaf754 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h @@ -7,8 +7,11 @@ #ifndef SkTo_DEFINED #define SkTo_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkTFitsIn.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTFitsIn.h" + +#include +#include template constexpr D SkTo(S s) { return SkASSERT(SkTFitsIn(s)), @@ -21,8 +24,16 @@ template constexpr int16_t SkToS16(S x) { return SkTo(x template constexpr uint16_t SkToU16(S x) { return SkTo(x); } template constexpr int32_t SkToS32(S x) { return SkTo(x); } template constexpr uint32_t SkToU32(S x) { return SkTo(x); } +template constexpr int64_t SkToS64(S x) { return SkTo(x); } +template constexpr uint64_t SkToU64(S x) { return SkTo(x); } template constexpr int SkToInt(S x) { return SkTo(x); } template constexpr unsigned SkToUInt(S x) { return SkTo(x); } template constexpr size_t SkToSizeT(S x) { return SkTo(x); } +/** @return false or true based on the condition +*/ +template static constexpr bool SkToBool(const T& x) { + return (bool)x; +} + #endif // SkTo_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h new file mode 100644 index 0000000000000..736f7897763d5 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h @@ -0,0 +1,33 @@ +// 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 SkTypeTraits_DEFINED +#define SkTypeTraits_DEFINED + +#include +#include + +// Trait for identifying types which are relocatable via memcpy, for container optimizations. +template +struct sk_has_trivially_relocatable_member : std::false_type {}; + +// Types can declare themselves trivially relocatable with a public +// using sk_is_trivially_relocatable = std::true_type; +template +struct sk_has_trivially_relocatable_member> + : T::sk_is_trivially_relocatable {}; + +// By default, all trivially copyable types are trivially relocatable. +template +struct sk_is_trivially_relocatable + : std::disjunction, sk_has_trivially_relocatable_member>{}; + +// Here be some dragons: while technically not guaranteed, we count on all sane unique_ptr +// implementations to be trivially relocatable. +template +struct sk_is_trivially_relocatable> : std::true_type {}; + +template +inline constexpr bool sk_is_trivially_relocatable_v = sk_is_trivially_relocatable::value; + +#endif // SkTypeTraits_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h new file mode 100644 index 0000000000000..51ed8a804defe --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h @@ -0,0 +1,130 @@ +/* + * Copyright 2019 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrVkSecondaryCBDrawContext_DEFINED +#define GrVkSecondaryCBDrawContext_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/core/SkSurfaceProps.h" +#include "include/core/SkTypes.h" + +#include + +class GrBackendSemaphore; +class GrRecordingContext; +struct GrVkDrawableInfo; +namespace skgpu::ganesh { +class Device; +} +class SkCanvas; +class SkDeferredDisplayList; +struct SkImageInfo; +class SkSurfaceCharacterization; +class SkSurfaceProps; + +/** + * This class is a private header that is intended to only be used inside of Chromium. This requires + * Chromium to burrow in and include this specifically since it is not part of skia's public include + * directory. + */ + +/** + * This class is used to draw into an external Vulkan secondary command buffer that is imported + * by the client. The secondary command buffer that gets imported must already have had begin called + * on it with VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT. Thus any draws to the imported + * command buffer cannot require changing the render pass. This requirement means that certain types + * of draws will not be supported when using a GrVkSecondaryCBDrawContext. This includes: + * Draws that require a dst copy for blending will be dropped + * Text draws will be dropped (these may require intermediate uploads of text data) + * Read and Write pixels will not work + * Any other draw that requires a copy will fail (this includes using backdrop filter with save + * layer). + * Stenciling is also disabled, but that should not restrict any actual draws from working. + * + * While using a GrVkSecondaryCBDrawContext, the client can also draw into normal SkSurfaces and + * then draw those SkSufaces (as SkImages) into the GrVkSecondaryCBDrawContext. If any of the + * previously mentioned unsupported draws are needed by the client, they can draw them into an + * offscreen surface, and then draw that into the GrVkSecondaryCBDrawContext. + * + * After all drawing to the GrVkSecondaryCBDrawContext has been done, the client must call flush() + * on the GrVkSecondaryCBDrawContext to actually fill in the secondary VkCommandBuffer with the + * draws. + * + * Additionally, the client must keep the GrVkSecondaryCBDrawContext alive until the secondary + * VkCommandBuffer has been submitted and all work finished on the GPU. Before deleting the + * GrVkSecondaryCBDrawContext, the client must call releaseResources() so that Skia can cleanup + * any internal objects that were created for the draws into the secondary command buffer. + */ +class SK_SPI GrVkSecondaryCBDrawContext : public SkRefCnt { +public: + static sk_sp Make(GrRecordingContext*, + const SkImageInfo&, + const GrVkDrawableInfo&, + const SkSurfaceProps* props); + + ~GrVkSecondaryCBDrawContext() override; + + SkCanvas* getCanvas(); + + // Records all the draws to the imported secondary command buffer and sets any dependent + // offscreen draws to the GPU. + void flush(); + + /** Inserts a list of GPU semaphores that Skia will have the driver wait on before executing + commands for this secondary CB. The wait semaphores will get added to the VkCommandBuffer + owned by this GrContext when flush() is called, and not the command buffer which the + Secondary CB is from. This will guarantee that the driver waits on the semaphores before + the secondary command buffer gets executed. If this call returns false, then the GPU + back end will not wait on any passed in semaphores, and the client will still own the + semaphores, regardless of the value of deleteSemaphoresAfterWait. + + If deleteSemaphoresAfterWait is false then Skia will not delete the semaphores. In this case + it is the client's responsibility to not destroy or attempt to reuse the semaphores until it + knows that Skia has finished waiting on them. This can be done by using finishedProcs + on flush calls. + + @param numSemaphores size of waitSemaphores array + @param waitSemaphores array of semaphore containers + @paramm deleteSemaphoresAfterWait who owns and should delete the semaphores + @return true if GPU is waiting on semaphores + */ + bool wait(int numSemaphores, + const GrBackendSemaphore waitSemaphores[], + bool deleteSemaphoresAfterWait = true); + + // This call will release all resources held by the draw context. The client must call + // releaseResources() before deleting the drawing context. However, the resources also include + // any Vulkan resources that were created and used for draws. Therefore the client must only + // call releaseResources() after submitting the secondary command buffer, and waiting for it to + // finish on the GPU. If it is called earlier then some vulkan objects may be deleted while they + // are still in use by the GPU. + void releaseResources(); + + const SkSurfaceProps& props() const { return fProps; } + + // TODO: Fill out these calls to support DDL + bool characterize(SkSurfaceCharacterization* characterization) const; + +#ifndef SK_DDL_IS_UNIQUE_POINTER + bool draw(sk_sp deferredDisplayList); +#else + bool draw(const SkDeferredDisplayList* deferredDisplayList); +#endif + + bool isCompatible(const SkSurfaceCharacterization& characterization) const; + +private: + explicit GrVkSecondaryCBDrawContext(sk_sp, const SkSurfaceProps*); + + sk_sp fDevice; + std::unique_ptr fCachedCanvas; + const SkSurfaceProps fProps; + + using INHERITED = SkRefCnt; +}; + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h index 55568b9af75a9..962d183b2d979 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h @@ -13,6 +13,7 @@ #include "include/core/SkData.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTypeface.h" #include "include/utils/SkNoDrawCanvas.h" struct SkPackedGlyphID; @@ -21,7 +22,6 @@ class SkStrikeCache; class SkStrikeClientImpl; class SkStrikeServer; class SkStrikeServerImpl; -class SkTypeface; namespace sktext::gpu { class Slug; } using SkDiscardableHandleId = uint32_t; @@ -62,9 +62,6 @@ class SkStrikeServer { bool DFTSupport, bool DFTPerspSupport = true); - // Serializes the typeface to be transmitted using this server. - SK_SPI sk_sp serializeTypeface(SkTypeface*); - // Serializes the strike data captured using a canvas returned by ::makeAnalysisCanvas. Any // handles locked using the DiscardableHandleManager will be assumed to be // unlocked after this call. @@ -128,10 +125,6 @@ class SkStrikeClient { SkStrikeCache* strikeCache = nullptr); SK_SPI ~SkStrikeClient(); - // Deserializes the typeface previously serialized using the SkStrikeServer. Returns null if the - // data is invalid. - SK_SPI sk_sp deserializeTypeface(const void* data, size_t length); - // Deserializes the strike data from a SkStrikeServer. All messages generated // from a server when serializing the ops must be deserialized before the op // is rasterized. @@ -142,9 +135,12 @@ class SkStrikeClient { // corresponding typefaceID on the GPU. SK_SPI bool translateTypefaceID(SkAutoDescriptor* descriptor) const; + // Testing helpers + sk_sp retrieveTypefaceUsingServerIDForTest(SkTypefaceID) const; + // Given a buffer, unflatten into a slug making sure to do the typefaceID translation from // renderer to GPU. Returns nullptr if there was a problem. - sk_sp deserializeSlug(const void* data, size_t size) const; + sk_sp deserializeSlugForTest(const void* data, size_t size) const; private: std::unique_ptr fImpl; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h new file mode 100644 index 0000000000000..ade4d71aa7497 --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h @@ -0,0 +1,70 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkDiscardableMemory_DEFINED +#define SkDiscardableMemory_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +/** + * Interface for discardable memory. Implementation is provided by the + * embedder. + */ +class SK_SPI SkDiscardableMemory { +public: + /** + * Factory method that creates, initializes and locks an SkDiscardableMemory + * object. If either of these steps fails, a nullptr pointer will be returned. + */ + static SkDiscardableMemory* Create(size_t bytes); + + /** + * Factory class that creates, initializes and locks an SkDiscardableMemory + * object. If either of these steps fails, a nullptr pointer will be returned. + */ + class Factory : public SkRefCnt { + public: + virtual SkDiscardableMemory* create(size_t bytes) = 0; + private: + using INHERITED = SkRefCnt; + }; + + /** Must not be called while locked. + */ + virtual ~SkDiscardableMemory() {} + + /** + * Locks the memory, prevent it from being discarded. Once locked. you may + * obtain a pointer to that memory using the data() method. + * + * lock() may return false, indicating that the underlying memory was + * discarded and that the lock failed. + * + * Nested calls to lock are not allowed. + */ + virtual bool SK_WARN_UNUSED_RESULT lock() = 0; + + /** + * Returns the current pointer for the discardable memory. This call is ONLY + * valid when the discardable memory object is locked. + */ + virtual void* data() = 0; + + /** + * Unlock the memory so that it can be purged by the system. Must be called + * after every successful lock call. + */ + virtual void unlock() = 0; + +protected: + SkDiscardableMemory() = default; + SkDiscardableMemory(const SkDiscardableMemory&) = delete; + SkDiscardableMemory& operator=(const SkDiscardableMemory&) = delete; +}; + +#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h index 0f4d9773db776..6775af0fc6966 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h @@ -21,14 +21,6 @@ class SkStrikeClient; class SkWriteBuffer; namespace sktext::gpu { - -// You can use Slug to simulate drawTextBlob by defining the following at compile time. -// SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG -// You can use Slug serialization to simulate drawTextBlob by defining the following: -// SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE -// For Skia, add this to your args.gn file. -// extra_cflags = ["-D", "SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG"] - // Slug encapsulates an SkTextBlob at a specific origin, using a specific paint. It can be // manipulated using matrix and clip changes to the canvas. If the canvas is transformed, then // the Slug will also transform with smaller glyphs using bi-linear interpolation to render. You @@ -70,7 +62,6 @@ class SK_API Slug : public SkRefCnt { static uint32_t NextUniqueID(); const uint32_t fUniqueID{NextUniqueID()}; }; - } // namespace sktext::gpu #endif // sktext_gpu_Slug_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h index 847e76f23252e..ba7172e005ae5 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h @@ -19,6 +19,7 @@ class GrContextThreadSafeProxy; class GrDirectContext; class GrImageContext; class GrRecordingContext; +enum class SkTextureCompressionType; class GrContext_Base : public SkRefCnt { public: @@ -43,7 +44,7 @@ class GrContext_Base : public SkRefCnt { */ SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const; - SK_API GrBackendFormat compressedBackendFormat(SkImage::CompressionType) const; + SK_API GrBackendFormat compressedBackendFormat(SkTextureCompressionType) const; /** * Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h index 049c07bff63be..26b75344760ee 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h @@ -65,7 +65,7 @@ struct GrD3DTextureResourceSpecHolder { GrD3DSurfaceInfo getSurfaceInfo(uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected) const; + skgpu::Protected isProtected) const; private: GrD3DTextureResourceSpec* fSpec; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h index 5eacf2ea2d263..ffcdc0eaaf49e 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h @@ -20,7 +20,7 @@ struct GrDawnTextureSpec { GrDawnSurfaceInfo GrDawnTextureSpecToSurfaceInfo(const GrDawnTextureSpec& dawnSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h index e951fbd17cfa5..7db777487aecc 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h @@ -103,6 +103,6 @@ struct GrGLTextureSpec { GrGLSurfaceInfo GrGLTextureSpecToSurfaceInfo(const GrGLTextureSpec& glSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h index 5a1a7a32d6241..72fdd4433d065 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h @@ -8,7 +8,7 @@ #ifndef GrImageContext_DEFINED #define GrImageContext_DEFINED -#include "include/private/SingleOwner.h" +#include "include/private/base/SingleOwner.h" #include "include/private/gpu/ganesh/GrContext_Base.h" class GrImageContextPriv; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h index fc72c7fd93bed..59a608dcfca0d 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h @@ -8,18 +8,19 @@ #ifndef GrMockTypesPriv_DEFINED #define GrMockTypesPriv_DEFINED +#include "include/core/SkTextureCompressionType.h" #include "include/gpu/mock/GrMockTypes.h" struct GrMockTextureSpec { GrMockTextureSpec() : fColorType(GrColorType::kUnknown) - , fCompressionType(SkImage::CompressionType::kNone) {} + , fCompressionType(SkTextureCompressionType::kNone) {} GrMockTextureSpec(const GrMockSurfaceInfo& info) : fColorType(info.fColorType) , fCompressionType(info.fCompressionType) {} GrColorType fColorType = GrColorType::kUnknown; - SkImage::CompressionType fCompressionType = SkImage::CompressionType::kNone; + SkTextureCompressionType fCompressionType = SkTextureCompressionType::kNone; }; GrMockSurfaceInfo GrMockTextureSpecToSurfaceInfo(const GrMockTextureSpec& mockSpec, diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h index 550d01760f946..ef65848b5e15a 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h @@ -68,7 +68,7 @@ struct GrMtlTextureSpec { GrMtlSurfaceInfo GrMtlTextureSpecToSurfaceInfo(const GrMtlTextureSpec& mtlSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif // __APPLE__ diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h index b663ff2b193ee..84e2346348503 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h @@ -8,28 +8,21 @@ #ifndef GrTypesPriv_DEFINED #define GrTypesPriv_DEFINED -#include -#include "include/core/SkImage.h" +#include "include/core/SkColor.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPath.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTextureCompressionType.h" #include "include/gpu/GrTypes.h" -#include "include/private/SkImageInfoPriv.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" +#include "include/private/base/SkTypeTraits.h" + +#include class GrBackendFormat; class GrCaps; class GrSurfaceProxy; -// The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might -// not actually be monotonic, depending on how libstdc++ was built. However, this is only currently -// used for idle resource purging so it shouldn't cause a correctness problem. -#if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000) -using GrStdSteadyClock = std::chrono::monotonic_clock; -#else -using GrStdSteadyClock = std::chrono::steady_clock; -#endif - /** * divide, rounding up */ @@ -643,6 +636,7 @@ static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct) { case kRGB_101010x_SkColorType: return GrColorType::kUnknown; case kBGRA_1010102_SkColorType: return GrColorType::kBGRA_1010102; case kBGR_101010x_SkColorType: return GrColorType::kUnknown; + case kBGR_101010x_XR_SkColorType: return GrColorType::kUnknown; case kRGBA_F32_SkColorType: return GrColorType::kRGBA_F32; case kR8G8_unorm_SkColorType: return GrColorType::kRG_88; case kA16_unorm_SkColorType: return GrColorType::kAlpha_16; @@ -924,12 +918,12 @@ static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct) { // In general we try to not mix CompressionType and ColorType, but currently SkImage still requires // an SkColorType even for CompressedTypes so we need some conversion. -static constexpr SkColorType GrCompressionTypeToSkColorType(SkImage::CompressionType compression) { +static constexpr SkColorType GrCompressionTypeToSkColorType(SkTextureCompressionType compression) { switch (compression) { - case SkImage::CompressionType::kNone: return kUnknown_SkColorType; - case SkImage::CompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType; - case SkImage::CompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType; - case SkImage::CompressionType::kBC1_RGBA8_UNORM: return kRGBA_8888_SkColorType; + case SkTextureCompressionType::kNone: return kUnknown_SkColorType; + case SkTextureCompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType; + case SkTextureCompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType; + case SkTextureCompressionType::kBC1_RGBA8_UNORM: return kRGBA_8888_SkColorType; } SkUNREACHABLE; @@ -995,12 +989,12 @@ static constexpr const char* GrColorTypeToStr(GrColorType ct) { SkUNREACHABLE; } -static constexpr const char* GrCompressionTypeToStr(SkImage::CompressionType compression) { +static constexpr const char* GrCompressionTypeToStr(SkTextureCompressionType compression) { switch (compression) { - case SkImage::CompressionType::kNone: return "kNone"; - case SkImage::CompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM"; - case SkImage::CompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM"; - case SkImage::CompressionType::kBC1_RGBA8_UNORM: return "kBC1_RGBA8_UNORM"; + case SkTextureCompressionType::kNone: return "kNone"; + case SkTextureCompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM"; + case SkTextureCompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM"; + case SkTextureCompressionType::kBC1_RGBA8_UNORM: return "kBC1_RGBA8_UNORM"; } SkUNREACHABLE; } diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h index a68d467dd8c92..f300a7139632b 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h @@ -35,7 +35,7 @@ struct GrVkBackendSurfaceInfo { GrVkImageInfo snapImageInfo(const skgpu::MutableTextureStateRef*) const; - bool isProtected() const { return fImageInfo.fProtected == GrProtected::kYes; } + bool isProtected() const { return fImageInfo.fProtected == skgpu::Protected::kYes; } #if GR_TEST_UTILS bool operator==(const GrVkBackendSurfaceInfo& that) const; #endif @@ -68,6 +68,6 @@ struct GrVkImageSpec { GrVkSurfaceInfo GrVkImageSpecToSurfaceInfo(const GrVkImageSpec& vkSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h new file mode 100644 index 0000000000000..bbf401c95e48d --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h @@ -0,0 +1,38 @@ +/* + * 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 skgpu_graphite_DawnTypesPriv_DEFINED +#define skgpu_graphite_DawnTypesPriv_DEFINED + +#include "include/gpu/graphite/dawn/DawnTypes.h" + +namespace skgpu::graphite { + +struct DawnTextureSpec { + DawnTextureSpec() + : fFormat(wgpu::TextureFormat::Undefined) + , fUsage(wgpu::TextureUsage::None) {} + DawnTextureSpec(const DawnTextureInfo& info) + : fFormat(info.fFormat) + , fUsage(info.fUsage) {} + + bool operator==(const DawnTextureSpec& that) const { + return fUsage == that.fUsage && + fFormat == that.fFormat; + } + + wgpu::TextureFormat fFormat; + wgpu::TextureUsage fUsage; +}; + +DawnTextureInfo DawnTextureSpecToTextureInfo(const DawnTextureSpec& dawnSpec, + uint32_t sampleCount, + Mipmapped mipmapped); + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_DawnTypesPriv_DEFINED diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h similarity index 87% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h index 697628a84d939..bf26aa2a78ad3 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h @@ -5,11 +5,11 @@ * found in the LICENSE file. */ -#ifndef skgpu_graphite_MtlTypesPriv_DEFINED -#define skgpu_graphite_MtlTypesPriv_DEFINED +#ifndef skgpu_graphite_MtlGraphiteTypesPriv_DEFINED +#define skgpu_graphite_MtlGraphiteTypesPriv_DEFINED #include "include/gpu/graphite/GraphiteTypes.h" -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" /////////////////////////////////////////////////////////////////////////////// @@ -67,8 +67,8 @@ struct MtlTextureSpec { MtlTextureInfo MtlTextureSpecToTextureInfo(const MtlTextureSpec& mtlSpec, uint32_t sampleCount, - uint32_t levelCount); + Mipmapped mipmapped); } // namespace skgpu::graphite -#endif // skgpu_graphite_MtlTypesPriv_DEFINED +#endif // skgpu_graphite_MtlGraphiteTypesPriv_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h index e0703d7ef1c86..b4304e3ae8988 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h @@ -19,8 +19,6 @@ struct VulkanTextureSpec { , fImageTiling(VK_IMAGE_TILING_OPTIMAL) , fImageUsageFlags(0) , fSharingMode(VK_SHARING_MODE_EXCLUSIVE) - , fCurrentQueueFamily(VK_QUEUE_FAMILY_IGNORED) - , fImageLayout(VK_IMAGE_LAYOUT_UNDEFINED) , fAspectMask(VK_IMAGE_ASPECT_COLOR_BIT) {} VulkanTextureSpec(const VulkanTextureInfo& info) : fFlags(info.fFlags) @@ -28,8 +26,6 @@ struct VulkanTextureSpec { , fImageTiling(info.fImageTiling) , fImageUsageFlags(info.fImageUsageFlags) , fSharingMode(info.fSharingMode) - , fCurrentQueueFamily(info.fCurrentQueueFamily) - , fImageLayout(info.fImageLayout) , fAspectMask(info.fAspectMask) {} bool operator==(const VulkanTextureSpec& that) const { @@ -38,8 +34,6 @@ struct VulkanTextureSpec { fImageTiling == that.fImageTiling && fImageUsageFlags == that.fImageUsageFlags && fSharingMode == that.fSharingMode && - fCurrentQueueFamily == that.fCurrentQueueFamily && - fImageLayout == that.fImageLayout && fAspectMask == that.fAspectMask; } @@ -48,15 +42,13 @@ struct VulkanTextureSpec { VkImageTiling fImageTiling; VkImageUsageFlags fImageUsageFlags; VkSharingMode fSharingMode; - uint32_t fCurrentQueueFamily; - VkImageLayout fImageLayout; VkImageAspectFlags fAspectMask; // GrVkYcbcrConversionInfo fYcbcrConversionInfo; }; VulkanTextureInfo VulkanTextureSpecToTextureInfo(const VulkanTextureSpec& vkSpec, uint32_t sampleCount, - uint32_t levelCount); + Mipmapped mipmapped); } // namespace skgpu::graphite diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h index c0a9b03bdaa02..ca4bcf108bf45 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h @@ -10,6 +10,8 @@ #include "include/core/SkTypes.h" +// IWYU pragma: begin_exports + #if SKIA_IMPLEMENTATION || !defined(SK_VULKAN) #include "include/third_party/vulkan/vulkan/vulkan_core.h" #else @@ -29,4 +31,6 @@ #endif #endif +// IWYU pragma: end_exports + #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h deleted file mode 100644 index 6b9ebd4727730..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL -#define SKSL_DSL - -#include "include/sksl/DSLBlock.h" -#include "include/sksl/DSLCore.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLFunction.h" -#include "include/sksl/DSLType.h" - -namespace SkSL { - -namespace dsl { - -using Block = DSLBlock; -using Case = DSLCase; -using Expression = DSLExpression; -using Field = DSLField; -using Function = DSLFunction; -using GlobalVar = DSLGlobalVar; -using Layout = DSLLayout; -using Modifiers = DSLModifiers; -using Parameter = DSLParameter; -using Statement = DSLStatement; -using Var = DSLVar; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h deleted file mode 100644 index 959ea2235bacd..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_BLOCK -#define SKSL_DSL_BLOCK - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include - -namespace SkSL { - -class Block; -class SymbolTable; - -namespace dsl { - -class DSLBlock { -public: - template - DSLBlock(Statements... statements) { - fStatements.reserve_back(sizeof...(statements)); - ((void)fStatements.push_back(DSLStatement(statements.release()).release()), ...); - } - - DSLBlock(SkSL::StatementArray statements, std::shared_ptr symbols = nullptr, - Position pos = {}); - - DSLBlock(SkTArray statements, std::shared_ptr symbols = nullptr, - Position pos = {}); - - DSLBlock(DSLBlock&& other) = default; - DSLBlock& operator=(DSLBlock&& other) = default; - - ~DSLBlock() = default; - - void append(DSLStatement stmt); - - std::unique_ptr release(); - -private: - SkSL::StatementArray fStatements; - std::shared_ptr fSymbols; - Position fPosition; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h deleted file mode 100644 index 16780e644a2c9..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_CASE -#define SKSL_DSL_CASE - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include - -namespace SkSL { - -namespace dsl { - -class DSLCase { -public: - // An empty expression means 'default:'. - template - DSLCase(DSLExpression value, Statements... statements) - : fValue(std::move(value)) { - fStatements.reserve_back(sizeof...(statements)); - ((void)fStatements.push_back(DSLStatement(std::move(statements)).release()), ...); - } - - DSLCase(DSLExpression value, SkTArray statements, - Position pos = {}); - - DSLCase(DSLExpression value, SkSL::StatementArray statements, - Position pos = {}); - - DSLCase(DSLCase&&); - - ~DSLCase(); - - DSLCase& operator=(DSLCase&&); - - void append(DSLStatement stmt); - -private: - DSLExpression fValue; - SkSL::StatementArray fStatements; - Position fPosition; - - friend class DSLCore; - - template - friend DSLStatement Switch(DSLExpression value, Cases... cases); -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h deleted file mode 100644 index 72441d4dee15a..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h +++ /dev/null @@ -1,492 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_CORE -#define SKSL_DSL_CORE - -#include "include/private/SkSLDefines.h" -#include "include/private/SkSLProgramKind.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLCase.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/DSLVar.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Compiler; -class ErrorReporter; -struct Program; -struct ProgramSettings; - -namespace dsl { - -class DSLField; -class DSLModifiers; - -// When users import the DSL namespace via `using namespace SkSL::dsl`, we want the SwizzleComponent -// Type enum to come into scope as well, so `Swizzle(var, X, Y, ONE)` can work as expected. -// `namespace SkSL::SwizzleComponent` contains only an `enum Type`; this `using namespace` directive -// shouldn't pollute the SkSL::dsl namespace with anything else. -using namespace SkSL::SwizzleComponent; - -/** - * Starts DSL output on the current thread using the specified compiler. This must be called - * prior to any other DSL functions. - */ -void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment); - -void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind, const SkSL::ProgramSettings& settings); - -/** - * Signals the end of DSL output. This must be called sometime between a call to Start() and the - * termination of the thread. - */ -void End(); - -/** - * Returns all global elements (functions and global variables) as a self-contained Program. The - * optional source string is retained as the program's source. DSL programs do not normally have - * sources, but when a DSL program is produced from parsed program text (as in Parser), it may be - * important to retain it so that any std::string_views derived from it remain valid. - */ -std::unique_ptr ReleaseProgram(std::unique_ptr source = nullptr); - -/** - * Returns the ErrorReporter which will be notified of any errors that occur during DSL calls. The - * default error reporter aborts on any error. - */ -ErrorReporter& GetErrorReporter(); - -/** - * Installs an ErrorReporter which will be notified of any errors that occur during DSL calls. - */ -void SetErrorReporter(ErrorReporter* errorReporter); - -DSLGlobalVar sk_FragColor(); - -DSLGlobalVar sk_FragCoord(); - -DSLExpression sk_Position(); - -/** - * #extension : enable - */ -void AddExtension(std::string_view name, Position pos = {}); - -/** - * break; - */ -DSLStatement Break(Position pos = {}); - -/** - * continue; - */ -DSLStatement Continue(Position pos = {}); - -/** - * Adds a modifiers declaration to the current program. - */ -void Declare(const DSLModifiers& modifiers, Position pos = {}); - -/** - * Creates a local variable declaration statement. - */ -DSLStatement Declare(DSLVar& var, Position pos = {}); - -/** - * Creates a local variable declaration statement containing multiple variables. - */ -DSLStatement Declare(SkTArray& vars, Position pos = {}); - -/** - * Declares a global variable. - */ -void Declare(DSLGlobalVar& var, Position pos = {}); - -/** - * Declares a set of global variables. - */ -void Declare(SkTArray& vars, Position pos = {}); - -/** - * default: statements - */ -template -DSLCase Default(Statements... statements) { - return DSLCase(DSLExpression(), std::move(statements)...); -} - -/** - * discard; - */ -DSLStatement Discard(Position pos = {}); - -/** - * do stmt; while (test); - */ -DSLStatement Do(DSLStatement stmt, DSLExpression test, Position pos = {}); - -/** - * for (initializer; test; next) stmt; - */ -DSLStatement For(DSLStatement initializer, DSLExpression test, DSLExpression next, - DSLStatement stmt, Position pos = {}, ForLoopPositions positions = {}); - -/** - * if (test) ifTrue; [else ifFalse;] - */ -DSLStatement If(DSLExpression test, DSLStatement ifTrue, DSLStatement ifFalse = DSLStatement(), - Position pos = {}); - -DSLGlobalVar InterfaceBlock(const DSLModifiers& modifiers, std::string_view typeName, - SkTArray fields, std::string_view varName = "", - int arraySize = 0, Position pos = {}); - -/** - * return [value]; - */ -DSLStatement Return(DSLExpression value = DSLExpression(), - Position pos = {}); - -/** - * test ? ifTrue : ifFalse - */ -DSLExpression Select(DSLExpression test, DSLExpression ifTrue, DSLExpression ifFalse, - Position = {}); - -DSLStatement StaticIf(DSLExpression test, DSLStatement ifTrue, - DSLStatement ifFalse = DSLStatement(), - Position pos = {}); - -// Internal use only -DSLStatement StaticSwitch(DSLExpression value, SkTArray cases, Position pos = {}); - -/** - * @switch (value) { cases } - */ -template -DSLStatement StaticSwitch(DSLExpression value, Cases... cases) { - SkTArray caseArray; - caseArray.reserve_back(sizeof...(cases)); - (caseArray.push_back(std::move(cases)), ...); - return StaticSwitch(std::move(value), std::move(caseArray), Position{}); -} - -// Internal use only -DSLStatement Switch(DSLExpression value, SkTArray cases, Position pos = {}); - -/** - * switch (value) { cases } - */ -template -DSLStatement Switch(DSLExpression value, Cases... cases) { - SkTArray caseArray; - caseArray.reserve_back(sizeof...(cases)); - (caseArray.push_back(std::move(cases)), ...); - return Switch(std::move(value), std::move(caseArray), Position{}); -} - -/** - * while (test) stmt; - */ -DSLStatement While(DSLExpression test, DSLStatement stmt, - Position pos = {}); - -/** - * expression.xyz1 - */ -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - SkSL::SwizzleComponent::Type c, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - SkSL::SwizzleComponent::Type c, - SkSL::SwizzleComponent::Type d, - Position pos = {}, - Position maskPos = {}); - -/** - * Returns the absolute value of x. If x is a vector, operates componentwise. - */ -DSLExpression Abs(DSLExpression x, Position pos = {}); - -/** - * Returns true if all of the components of boolean vector x are true. - */ -DSLExpression All(DSLExpression x, Position pos = {}); - -/** - * Returns true if any of the components of boolean vector x are true. - */ -DSLExpression Any(DSLExpression x, Position pos = {}); - -/** - * Returns the arctangent of y over x. Operates componentwise on vectors. - */ -DSLExpression Atan(DSLExpression y_over_x, Position pos = {}); -DSLExpression Atan(DSLExpression y, DSLExpression x, Position pos = {}); - -/** - * Returns x rounded towards positive infinity. If x is a vector, operates componentwise. - */ -DSLExpression Ceil(DSLExpression x, Position pos = {}); - -/** - * Returns x clamped to between min and max. If x is a vector, operates componentwise. - */ -DSLExpression Clamp(DSLExpression x, DSLExpression min, DSLExpression max, - Position pos = {}); - -/** - * Returns the cosine of x. If x is a vector, operates componentwise. - */ -DSLExpression Cos(DSLExpression x, Position pos = {}); - -/** - * Returns the cross product of x and y. - */ -DSLExpression Cross(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns x converted from radians to degrees. If x is a vector, operates componentwise. - */ -DSLExpression Degrees(DSLExpression x, Position pos = {}); - -/** - * Returns the distance between x and y. - */ -DSLExpression Distance(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the dot product of x and y. - */ -DSLExpression Dot(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are equal to the corresponding - * components of y. - */ -DSLExpression Equal(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns e^x. If x is a vector, operates componentwise. - */ -DSLExpression Exp(DSLExpression x, Position pos = {}); - -/** - * Returns 2^x. If x is a vector, operates componentwise. - */ -DSLExpression Exp2(DSLExpression x, Position pos = {}); - -/** - * If dot(i, nref) >= 0, returns n, otherwise returns -n. - */ -DSLExpression Faceforward(DSLExpression n, DSLExpression i, DSLExpression nref, - Position pos = {}); - -/** - * Returns x rounded towards negative infinity. If x is a vector, operates componentwise. - */ -DSLExpression Floor(DSLExpression x, Position pos = {}); - -/** - * Returns the fractional part of x. If x is a vector, operates componentwise. - */ -DSLExpression Fract(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are greater than the corresponding - * components of y. - */ -DSLExpression GreaterThan(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are greater than or equal to the - * corresponding components of y. - */ -DSLExpression GreaterThanEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the 1/sqrt(x). If x is a vector, operates componentwise. - */ -DSLExpression Inversesqrt(DSLExpression x, Position pos = {}); - -/** - * Returns the inverse of the matrix x. - */ -DSLExpression Inverse(DSLExpression x, Position pos = {}); - -/** - * Returns the length of the vector x. - */ -DSLExpression Length(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are less than the corresponding - * components of y. - */ -DSLExpression LessThan(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are less than or equal to the - * corresponding components of y. - */ -DSLExpression LessThanEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the log base e of x. If x is a vector, operates componentwise. - */ -DSLExpression Log(DSLExpression x, Position pos = {}); - -/** - * Returns the log base 2 of x. If x is a vector, operates componentwise. - */ -DSLExpression Log2(DSLExpression x, Position pos = {}); - -/** - * Returns the larger (closer to positive infinity) of x and y. If x is a vector, operates - * componentwise. y may be either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Max(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns the smaller (closer to negative infinity) of x and y. If x is a vector, operates - * componentwise. y may be either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Min(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns a linear intepolation between x and y at position a, where a=0 results in x and a=1 - * results in y. If x and y are vectors, operates componentwise. a may be either a vector of the - * same dimensions as x and y, or a scalar. - */ -DSLExpression Mix(DSLExpression x, DSLExpression y, DSLExpression a, - Position pos = {}); - -/** - * Returns x modulo y. If x is a vector, operates componentwise. y may be either a vector of the - * same dimensions as x, or a scalar. - */ -DSLExpression Mod(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns the vector x normalized to a length of 1. - */ -DSLExpression Normalize(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are not equal to the corresponding - * components of y. - */ -DSLExpression NotEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns x raised to the power y. If x is a vector, operates componentwise. y may be either a - * vector of the same dimensions as x, or a scalar. - */ -DSLExpression Pow(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns x converted from degrees to radians. If x is a vector, operates componentwise. - */ -DSLExpression Radians(DSLExpression x, Position pos = {}); - -/** - * Returns i reflected from a surface with normal n. - */ -DSLExpression Reflect(DSLExpression i, DSLExpression n, Position pos = {}); - -/** - * Returns i refracted across a surface with normal n and ratio of indices of refraction eta. - */ -DSLExpression Refract(DSLExpression i, DSLExpression n, DSLExpression eta, - Position pos = {}); - -/** - * Returns x, rounded to the nearest integer. If x is a vector, operates componentwise. - */ -DSLExpression Round(DSLExpression x, Position pos = {}); - -/** - * Returns x clamped to the range [0, 1]. If x is a vector, operates componentwise. - */ -DSLExpression Saturate(DSLExpression x, Position pos = {}); - -/** - * Returns -1, 0, or 1 depending on whether x is negative, zero, or positive, respectively. If x is - * a vector, operates componentwise. - */ -DSLExpression Sign(DSLExpression x, Position pos = {}); - -/** - * Returns the sine of x. If x is a vector, operates componentwise. - */ -DSLExpression Sin(DSLExpression x, Position pos = {}); - -/** - * Returns a smooth interpolation between 0 (at x=edge1) and 1 (at x=edge2). If x is a vector, - * operates componentwise. edge1 and edge2 may either be both vectors of the same dimensions as x or - * scalars. - */ -DSLExpression Smoothstep(DSLExpression edge1, DSLExpression edge2, DSLExpression x, - Position pos = {}); - -/** - * Returns the square root of x. If x is a vector, operates componentwise. - */ -DSLExpression Sqrt(DSLExpression x, Position pos = {}); - -/** - * Returns 0 if x < edge or 1 if x >= edge. If x is a vector, operates componentwise. edge may be - * either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Step(DSLExpression edge, DSLExpression x, Position pos = {}); - -/** - * Returns the tangent of x. If x is a vector, operates componentwise. - */ -DSLExpression Tan(DSLExpression x, Position pos = {}); - -/** - * Returns x converted from premultipled to unpremultiplied alpha. - */ -DSLExpression Unpremul(DSLExpression x, Position pos = {}); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h deleted file mode 100644 index bdb5f2fe24691..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_EXPRESSION -#define SKSL_DSL_EXPRESSION - -#include "include/private/SkTArray.h" -#include "include/sksl/SkSLOperator.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include -#include - -#if defined(__has_cpp_attribute) && __has_cpp_attribute(clang::reinitializes) -#define SK_CLANG_REINITIALIZES [[clang::reinitializes]] -#else -#define SK_CLANG_REINITIALIZES -#endif - -namespace SkSL { - -class Expression; -class ExpressionArray; - -namespace dsl { - -class DSLType; -class DSLVarBase; - -/** - * Represents an expression such as 'cos(x)' or 'a + b'. - */ -class DSLExpression { -public: - DSLExpression(const DSLExpression&) = delete; - - DSLExpression(DSLExpression&&); - - DSLExpression(); - - /** - * Creates an expression representing a literal float. - */ - DSLExpression(float value, Position pos = {}); - - /** - * Creates an expression representing a literal float. - */ - DSLExpression(double value, Position pos = {}) - : DSLExpression((float) value) {} - - /** - * Creates an expression representing a literal int. - */ - DSLExpression(int value, Position pos = {}); - - /** - * Creates an expression representing a literal int. - */ - DSLExpression(int64_t value, Position pos = {}); - - /** - * Creates an expression representing a literal uint. - */ - DSLExpression(unsigned int value, Position pos = {}); - - /** - * Creates an expression representing a literal bool. - */ - DSLExpression(bool value, Position pos = {}); - - /** - * Creates an expression representing a variable reference. - */ - DSLExpression(DSLVarBase& var, Position pos = {}); - - DSLExpression(DSLVarBase&& var, Position pos = {}); - - // If expression is null, returns Poison - explicit DSLExpression(std::unique_ptr expression, Position pos = {}); - - static DSLExpression Poison(Position pos = {}); - - ~DSLExpression(); - - DSLType type() const; - - std::string description() const; - - Position position() const; - - void setPosition(Position pos); - - /** - * Performs assignment, like the '=' operator. - */ - DSLExpression assign(DSLExpression other); - - DSLExpression x(Position pos = {}); - - DSLExpression y(Position pos = {}); - - DSLExpression z(Position pos = {}); - - DSLExpression w(Position pos = {}); - - DSLExpression r(Position pos = {}); - - DSLExpression g(Position pos = {}); - - DSLExpression b(Position pos = {}); - - DSLExpression a(Position pos = {}); - - /** - * Creates an SkSL struct field access expression. - */ - DSLExpression field(std::string_view name, Position pos = {}); - - /** - * Creates an SkSL array index expression. - */ - DSLExpression operator[](DSLExpression index); - - DSLExpression operator()(SkTArray args, Position pos = {}); - - DSLExpression operator()(ExpressionArray args, Position pos = {}); - - /** - * Invokes a prefix operator. - */ - DSLExpression prefix(Operator::Kind op, Position pos); - - /** - * Invokes a postfix operator. - */ - DSLExpression postfix(Operator::Kind op, Position pos); - - /** - * Invokes a binary operator. - */ - DSLExpression binary(Operator::Kind op, DSLExpression right, Position pos); - - /** - * Equivalent to operator[]. - */ - DSLExpression index(DSLExpression index, Position pos); - - /** - * Returns true if this object contains an expression. DSLExpressions which were created with - * the empty constructor or which have already been release()ed do not have a value. - * DSLExpressions created with errors are still considered to have a value (but contain poison). - */ - bool hasValue() const { - return fExpression != nullptr; - } - - /** - * Returns true if this object contains an expression which is not poison. - */ - bool isValid() const; - - SK_CLANG_REINITIALIZES void swap(DSLExpression& other); - - /** - * Invalidates this object and returns the SkSL expression it represents. It is an error to call - * this on an invalid DSLExpression. - */ - std::unique_ptr release(); - -private: - /** - * Calls release if this expression has a value, otherwise returns null. - */ - std::unique_ptr releaseIfPossible(); - - std::unique_ptr fExpression; - - friend DSLExpression SampleChild(int index, DSLExpression coords); - - friend class DSLCore; - friend class DSLVarBase; - friend class DSLWriter; -}; - -DSLExpression operator+(DSLExpression left, DSLExpression right); -DSLExpression operator+(DSLExpression expr); -DSLExpression operator+=(DSLExpression left, DSLExpression right); -DSLExpression operator-(DSLExpression left, DSLExpression right); -DSLExpression operator-(DSLExpression expr); -DSLExpression operator-=(DSLExpression left, DSLExpression right); -DSLExpression operator*(DSLExpression left, DSLExpression right); -DSLExpression operator*=(DSLExpression left, DSLExpression right); -DSLExpression operator/(DSLExpression left, DSLExpression right); -DSLExpression operator/=(DSLExpression left, DSLExpression right); -DSLExpression operator%(DSLExpression left, DSLExpression right); -DSLExpression operator%=(DSLExpression left, DSLExpression right); -DSLExpression operator<<(DSLExpression left, DSLExpression right); -DSLExpression operator<<=(DSLExpression left, DSLExpression right); -DSLExpression operator>>(DSLExpression left, DSLExpression right); -DSLExpression operator>>=(DSLExpression left, DSLExpression right); -DSLExpression operator&&(DSLExpression left, DSLExpression right); -DSLExpression operator||(DSLExpression left, DSLExpression right); -DSLExpression operator&(DSLExpression left, DSLExpression right); -DSLExpression operator&=(DSLExpression left, DSLExpression right); -DSLExpression operator|(DSLExpression left, DSLExpression right); -DSLExpression operator|=(DSLExpression left, DSLExpression right); -DSLExpression operator^(DSLExpression left, DSLExpression right); -DSLExpression operator^=(DSLExpression left, DSLExpression right); -DSLExpression LogicalXor(DSLExpression left, DSLExpression right); -DSLExpression operator,(DSLExpression left, DSLExpression right); -DSLExpression operator==(DSLExpression left, DSLExpression right); -DSLExpression operator!=(DSLExpression left, DSLExpression right); -DSLExpression operator>(DSLExpression left, DSLExpression right); -DSLExpression operator<(DSLExpression left, DSLExpression right); -DSLExpression operator>=(DSLExpression left, DSLExpression right); -DSLExpression operator<=(DSLExpression left, DSLExpression right); -DSLExpression operator!(DSLExpression expr); -DSLExpression operator~(DSLExpression expr); -DSLExpression operator++(DSLExpression expr); -DSLExpression operator++(DSLExpression expr, int); -DSLExpression operator--(DSLExpression expr); -DSLExpression operator--(DSLExpression expr, int); - -} // namespace dsl - -} // namespace SkSL - -template struct sk_is_trivially_relocatable; - -template <> -struct sk_is_trivially_relocatable : std::true_type {}; - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h deleted file mode 100644 index de7b8f1fbcb6d..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_FUNCTION -#define SKSL_DSL_FUNCTION - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLBlock.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/DSLVar.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include - -namespace SkSL { - -class FunctionDeclaration; - -namespace dsl { - -class DSLType; - -class DSLFunction { -public: - template - DSLFunction(const DSLType& returnType, std::string_view name, Parameters&... parameters) - : DSLFunction(DSLModifiers(), returnType, name, parameters...) {} - - template - DSLFunction(const DSLModifiers& modifiers, const DSLType& returnType, std::string_view name, - Parameters&... parameters) { - SkTArray parameterArray; - parameterArray.reserve_back(sizeof...(parameters)); - (parameterArray.push_back(¶meters), ...); - - // We can't have a default parameter and a template parameter pack at the same time, so - // unfortunately we can't capture position from this overload. - this->init(modifiers, returnType, name, std::move(parameterArray), Position()); - } - - DSLFunction(std::string_view name, const DSLModifiers& modifiers, const DSLType& returnType, - SkTArray parameters, Position pos = {}) { - this->init(modifiers, returnType, name, std::move(parameters), pos); - } - - DSLFunction(SkSL::FunctionDeclaration* decl) - : fDecl(decl) {} - - virtual ~DSLFunction() = default; - - template - void define(Stmt... stmts) { - DSLBlock block = DSLBlock(DSLStatement(std::move(stmts))...); - this->define(std::move(block)); - } - - void define(DSLBlock block, Position pos = {}); - - void prototype(); - - /** - * Invokes the function with the given arguments. - */ - template - DSLExpression operator()(Args&&... args) { - ExpressionArray argArray; - argArray.reserve_back(sizeof...(args)); - this->collectArgs(argArray, std::forward(args)...); - return this->call(std::move(argArray)); - } - - /** - * Invokes the function with the given arguments. - */ - DSLExpression call(SkTArray args, Position pos = {}); - - DSLExpression call(ExpressionArray args, Position pos = {}); - -private: - void collectArgs(ExpressionArray& args) {} - - template - void collectArgs(ExpressionArray& args, DSLVar& var, RemainingArgs&&... remaining) { - args.push_back(DSLExpression(var).release()); - collectArgs(args, std::forward(remaining)...); - } - - template - void collectArgs(ExpressionArray& args, DSLExpression expr, RemainingArgs&&... remaining) { - args.push_back(expr.release()); - collectArgs(args, std::forward(remaining)...); - } - - void init(DSLModifiers modifiers, const DSLType& returnType, std::string_view name, - SkTArray params, Position pos); - - SkSL::FunctionDeclaration* fDecl = nullptr; - SkSL::Position fPosition; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h deleted file mode 100644 index a1c963a74eacd..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_LAYOUT -#define SKSL_DSL_LAYOUT - -#include "include/private/SkSLLayout.h" -#include "include/sksl/SkSLPosition.h" - -namespace SkSL { - -namespace dsl { - -class DSLLayout { -public: - DSLLayout() {} - - DSLLayout& originUpperLeft(Position pos = {}) { - return this->flag(SkSL::Layout::kOriginUpperLeft_Flag, "origin_upper_left", pos); - } - - DSLLayout& pushConstant(Position pos = {}) { - return this->flag(SkSL::Layout::kPushConstant_Flag, "push_constant", pos); - } - - DSLLayout& blendSupportAllEquations(Position pos = {}) { - return this->flag(SkSL::Layout::kBlendSupportAllEquations_Flag, - "blend_support_all_equations", pos); - } - - DSLLayout& color(Position pos = {}) { - return this->flag(SkSL::Layout::kColor_Flag, "color", pos); - } - - DSLLayout& location(int location, Position pos = {}) { - return this->intValue(&fSkSLLayout.fLocation, location, SkSL::Layout::kLocation_Flag, - "location", pos); - } - - DSLLayout& offset(int offset, Position pos = {}) { - return this->intValue(&fSkSLLayout.fOffset, offset, SkSL::Layout::kOffset_Flag, "offset", - pos); - } - - DSLLayout& binding(int binding, Position pos = {}) { - return this->intValue(&fSkSLLayout.fBinding, binding, SkSL::Layout::kBinding_Flag, - "binding", pos); - } - - DSLLayout& index(int index, Position pos = {}) { - return this->intValue(&fSkSLLayout.fIndex, index, SkSL::Layout::kIndex_Flag, "index", pos); - } - - DSLLayout& set(int set, Position pos = {}) { - return this->intValue(&fSkSLLayout.fSet, set, SkSL::Layout::kSet_Flag, "set", pos); - } - - DSLLayout& builtin(int builtin, Position pos = {}) { - return this->intValue(&fSkSLLayout.fBuiltin, builtin, SkSL::Layout::kBuiltin_Flag, - "builtin", pos); - } - - DSLLayout& inputAttachmentIndex(int inputAttachmentIndex, - Position pos = {}) { - return this->intValue(&fSkSLLayout.fInputAttachmentIndex, inputAttachmentIndex, - SkSL::Layout::kInputAttachmentIndex_Flag, "input_attachment_index", - pos); - } - -private: - explicit DSLLayout(SkSL::Layout skslLayout) - : fSkSLLayout(skslLayout) {} - - DSLLayout& flag(SkSL::Layout::Flag mask, const char* name, Position pos); - - DSLLayout& intValue(int* target, int value, SkSL::Layout::Flag flag, const char* name, - Position pos); - - SkSL::Layout fSkSLLayout; - - friend class DSLModifiers; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h deleted file mode 100644 index 01fb0623376d8..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_MODIFIERS -#define SKSL_DSL_MODIFIERS - -#include "include/core/SkSpan.h" -#include "include/private/SkSLModifiers.h" -#include "include/sksl/DSLLayout.h" - -namespace SkSL { - -namespace dsl { - -class DSLField; -class DSLType; - -enum Modifier { - kNo_Modifier = SkSL::Modifiers::kNo_Flag, - kConst_Modifier = SkSL::Modifiers::kConst_Flag, - kIn_Modifier = SkSL::Modifiers::kIn_Flag, - kOut_Modifier = SkSL::Modifiers::kOut_Flag, - kInOut_Modifier = SkSL::Modifiers::kIn_Flag | SkSL::Modifiers::kOut_Flag, - kUniform_Modifier = SkSL::Modifiers::kUniform_Flag, - kFlat_Modifier = SkSL::Modifiers::kFlat_Flag, - kNoPerspective_Modifier = SkSL::Modifiers::kNoPerspective_Flag, -}; - -class DSLModifiers { -public: - DSLModifiers(int flags = 0, Position pos = {}) - : DSLModifiers(DSLLayout(), flags, pos) {} - - DSLModifiers(DSLLayout layout, int flags = 0, Position pos = {}) - : fModifiers(layout.fSkSLLayout, flags) - , fPosition(pos) {} - - int& flags() { - return fModifiers.fFlags; - } - - const int& flags() const { - return fModifiers.fFlags; - } - - DSLLayout layout() const { - return DSLLayout(fModifiers.fLayout); - } - -private: - SkSL::Modifiers fModifiers; - Position fPosition; - - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); - friend class DSLCore; - friend class DSLFunction; - friend class DSLType; - friend class DSLWriter; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h deleted file mode 100644 index 391e911d3aac9..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_STATEMENT -#define SKSL_DSL_STATEMENT - -#include "include/core/SkTypes.h" -#include "include/private/SkSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include - -namespace SkSL { - -class Expression; - -namespace dsl { - -class DSLBlock; -class DSLExpression; - -class DSLStatement { -public: - DSLStatement(); - - DSLStatement(DSLExpression expr); - - DSLStatement(DSLBlock block); - - DSLStatement(DSLStatement&&) = default; - - DSLStatement(std::unique_ptr expr); - - DSLStatement(std::unique_ptr stmt, Position pos); - - DSLStatement(std::unique_ptr stmt); - - ~DSLStatement(); - - DSLStatement& operator=(DSLStatement&& other) = default; - - Position position() { - SkASSERT(this->hasValue()); - return fStatement->fPosition; - } - - void setPosition(Position pos) { - SkASSERT(this->hasValue()); - fStatement->fPosition = pos; - } - - bool hasValue() { return fStatement != nullptr; } - - std::unique_ptr release() { - SkASSERT(this->hasValue()); - return std::move(fStatement); - } - -private: - std::unique_ptr releaseIfPossible() { - return std::move(fStatement); - } - - std::unique_ptr fStatement; - - friend class DSLCore; - friend class DSLWriter; - friend DSLStatement operator,(DSLStatement left, DSLStatement right); -}; - -DSLStatement operator,(DSLStatement left, DSLStatement right); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h deleted file mode 100644 index dfd45d1b34280..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_SYMBOLS -#define SKSL_DSL_SYMBOLS - -#include "include/sksl/DSLExpression.h" - -#include -#include - -namespace SkSL { - -class Position; -class SymbolTable; - -namespace dsl { - -class DSLVarBase; - -// This header provides methods for manually managing symbol tables in DSL code. They should not be -// used by normal hand-written DSL code, where we rely on C++ to manage symbols, but are instead -// needed when DSL objects are being constructed programmatically (as in Parser). - -/** - * Pushes a new symbol table onto the symbol table stack. - */ -void PushSymbolTable(); - -/** - * Pops the top symbol table from the stack. As symbol tables are shared pointers, this will only - * destroy the symbol table if it was never attached to anything (e.g. passed into a Block - * constructor). - */ -void PopSymbolTable(); - -/** - * Returns the current symbol table. Outside of SkSL itself, this is an opaque pointer, used only - * for passing it to DSL methods that require it. - */ -std::shared_ptr CurrentSymbolTable(); - -/** - * Returns an expression referring to the named symbol. - */ -DSLExpression Symbol(std::string_view name, Position pos = {}); - -/** - * Adds a variable to the current symbol table. - */ -void AddToSymbolTable(DSLVarBase& var, Position pos = {}); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h deleted file mode 100644 index d15e01b3a3eac..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_TYPE -#define SKSL_DSL_TYPE - -#include "include/core/SkSpan.h" -#include "include/core/SkTypes.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include - -namespace SkSL { - -class Compiler; -class Type; - -namespace dsl { - -class DSLField; -class DSLVarBase; - -enum TypeConstant : uint8_t { - kBool_Type, - kBool2_Type, - kBool3_Type, - kBool4_Type, - kHalf_Type, - kHalf2_Type, - kHalf3_Type, - kHalf4_Type, - kHalf2x2_Type, - kHalf3x2_Type, - kHalf4x2_Type, - kHalf2x3_Type, - kHalf3x3_Type, - kHalf4x3_Type, - kHalf2x4_Type, - kHalf3x4_Type, - kHalf4x4_Type, - kFloat_Type, - kFloat2_Type, - kFloat3_Type, - kFloat4_Type, - kFragmentProcessor_Type, - kFloat2x2_Type, - kFloat3x2_Type, - kFloat4x2_Type, - kFloat2x3_Type, - kFloat3x3_Type, - kFloat4x3_Type, - kFloat2x4_Type, - kFloat3x4_Type, - kFloat4x4_Type, - kInt_Type, - kInt2_Type, - kInt3_Type, - kInt4_Type, - kShader_Type, - kShort_Type, - kShort2_Type, - kShort3_Type, - kShort4_Type, - kUInt_Type, - kUInt2_Type, - kUInt3_Type, - kUInt4_Type, - kUShort_Type, - kUShort2_Type, - kUShort3_Type, - kUShort4_Type, - kVoid_Type, - kPoison_Type, -}; - -class DSLType { -public: - DSLType(TypeConstant tc, Position pos = {}); - - DSLType(const SkSL::Type* type, Position pos = {}); - - DSLType(std::string_view name, Position pos = {}); - - DSLType(std::string_view name, - DSLModifiers* modifiers, - Position pos = {}); - - /** - * Returns true if the SkSL type is non-null. - */ - bool hasValue() const { return fSkSLType != nullptr; } - - /** - * Returns true if this type is a bool. - */ - bool isBoolean() const; - - /** - * Returns true if this is a numeric scalar type. - */ - bool isNumber() const; - - /** - * Returns true if this is a floating-point scalar type (float or half). - */ - bool isFloat() const; - - /** - * Returns true if this is a signed scalar type (int or short). - */ - bool isSigned() const; - - /** - * Returns true if this is an unsigned scalar type (uint or ushort). - */ - bool isUnsigned() const; - - /** - * Returns true if this is a signed or unsigned integer. - */ - bool isInteger() const; - - /** - * Returns true if this is a scalar type. - */ - bool isScalar() const; - - /** - * Returns true if this is a vector type. - */ - bool isVector() const; - - /** - * Returns true if this is a matrix type. - */ - bool isMatrix() const; - - /** - * Returns true if this is a array type. - */ - bool isArray() const; - - /** - * Returns true if this is a struct type. - */ - bool isStruct() const; - - /** - * Returns true if this is a Skia object type (shader, colorFilter, blender). - */ - bool isEffectChild() const; - - template - static DSLExpression Construct(DSLType type, DSLVarBase& var, Args&&... args) { - DSLExpression argArray[] = {var, args...}; - return Construct(type, SkSpan(argArray)); - } - - template - static DSLExpression Construct(DSLType type, DSLExpression expr, Args&&... args) { - DSLExpression argArray[] = {std::move(expr), std::move(args)...}; - return Construct(type, SkSpan(argArray)); - } - - static DSLExpression Construct(DSLType type, SkSpan argArray); - -private: - const SkSL::Type& skslType() const { - SkASSERT(fSkSLType); - return *fSkSLType; - } - - const SkSL::Type* fSkSLType = nullptr; - - friend DSLType Array(const DSLType& base, int count, Position pos); - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); - friend DSLType UnsizedArray(const DSLType& base, Position pos); - friend class DSLCore; - friend class DSLFunction; - friend class DSLVarBase; - friend class DSLWriter; - friend class SkSL::Compiler; -}; - -#define TYPE(T) \ - template \ - DSLExpression T(Args&&... args) { \ - return DSLType::Construct(k ## T ## _Type, std::forward(args)...); \ - } - -#define VECTOR_TYPE(T) \ - TYPE(T) \ - TYPE(T ## 2) \ - TYPE(T ## 3) \ - TYPE(T ## 4) - -#define MATRIX_TYPE(T) \ - TYPE(T ## 2x2) \ - TYPE(T ## 3x2) \ - TYPE(T ## 4x2) \ - TYPE(T ## 2x3) \ - TYPE(T ## 3x3) \ - TYPE(T ## 4x3) \ - TYPE(T ## 2x4) \ - TYPE(T ## 3x4) \ - TYPE(T ## 4x4) - -VECTOR_TYPE(Bool) -VECTOR_TYPE(Float) -VECTOR_TYPE(Half) -VECTOR_TYPE(Int) -VECTOR_TYPE(UInt) -VECTOR_TYPE(Short) -VECTOR_TYPE(UShort) - -MATRIX_TYPE(Float) -MATRIX_TYPE(Half) - -#undef TYPE -#undef VECTOR_TYPE -#undef MATRIX_TYPE - -DSLType Array(const DSLType& base, int count, Position pos = {}); - -DSLType UnsizedArray(const DSLType& base, Position pos = {}); - -class DSLField { -public: - DSLField(const DSLType type, std::string_view name, - Position pos = {}) - : DSLField(DSLModifiers(), type, name, pos) {} - - DSLField(const DSLModifiers& modifiers, const DSLType type, std::string_view name, - Position pos = {}) - : fModifiers(modifiers) - , fType(type) - , fName(name) - , fPosition(pos) {} - -private: - DSLModifiers fModifiers; - const DSLType fType; - std::string_view fName; - Position fPosition; - - friend class DSLCore; - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); -}; - -DSLType Struct(std::string_view name, SkSpan fields, - Position pos = {}); - -template -DSLType Struct(std::string_view name, Field... fields) { - DSLField fieldTypes[] = {std::move(fields)...}; - return Struct(name, SkSpan(fieldTypes), Position()); -} - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h deleted file mode 100644 index f052a525e355d..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_VAR -#define SKSL_DSL_VAR - -#include "include/private/SkSLStatement.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/DSLType.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Expression; -class ExpressionArray; -class Variable; -enum class VariableStorage : int8_t; - -namespace dsl { - -class DSLVarBase { -public: - /** - * Constructs a new variable with the specified type and name. - */ - DSLVarBase(VariableStorage storage, DSLType type, std::string_view name, - DSLExpression initialValue, Position pos, Position namePos); - - DSLVarBase(VariableStorage storage, const DSLModifiers& modifiers, DSLType type, - std::string_view name, DSLExpression initialValue, Position pos, Position namePos); - - DSLVarBase(DSLVarBase&&) = default; - - std::string_view name() const { - return fName; - } - - const DSLModifiers& modifiers() const { - return fModifiers; - } - - VariableStorage storage() const { - return fStorage; - } - - DSLExpression x() { - return DSLExpression(*this).x(); - } - - DSLExpression y() { - return DSLExpression(*this).y(); - } - - DSLExpression z() { - return DSLExpression(*this).z(); - } - - DSLExpression w() { - return DSLExpression(*this).w(); - } - - DSLExpression r() { - return DSLExpression(*this).r(); - } - - DSLExpression g() { - return DSLExpression(*this).g(); - } - - DSLExpression b() { - return DSLExpression(*this).b(); - } - - DSLExpression a() { - return DSLExpression(*this).a(); - } - - DSLExpression field(std::string_view name) { - return DSLExpression(*this).field(name); - } - - DSLExpression operator[](DSLExpression&& index); - - DSLExpression operator++() { - return ++DSLExpression(*this); - } - - DSLExpression operator++(int) { - return DSLExpression(*this)++; - } - - DSLExpression operator--() { - return --DSLExpression(*this); - } - - DSLExpression operator--(int) { - return DSLExpression(*this)--; - } - - template DSLExpression assign(T&& param) { - return this->assignExpression(DSLExpression(std::forward(param))); - } - -protected: - /** - * Creates an empty, unpopulated var. Can be replaced with a real var later via `swap`. - */ - DSLVarBase(VariableStorage storage) : fType(kVoid_Type), fStorage(storage) {} - - DSLExpression assignExpression(DSLExpression other); - - void swap(DSLVarBase& other); - - DSLModifiers fModifiers; - // We only need to keep track of the type here so that we can create the SkSL::Variable. For - // predefined variables this field is unnecessary, so we don't bother tracking it and just set - // it to kVoid; in other words, you shouldn't generally be relying on this field to be correct. - // If you need to determine the variable's type, look at DSLWriter::Var(...)->type() instead. - DSLType fType; - std::unique_ptr fDeclaration; - SkSL::Variable* fVar = nullptr; - Position fNamePosition; - std::string_view fName; - DSLExpression fInitialValue; - Position fPosition; - VariableStorage fStorage; - bool fInitialized = false; - - friend class DSLCore; - friend class DSLFunction; - friend class DSLWriter; -}; - -/** - * A local variable. - */ -class DSLVar : public DSLVarBase { -public: - DSLVar(); - - DSLVar(DSLType type, std::string_view name, DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLVar(const DSLModifiers& modifiers, DSLType type, std::string_view name, - DSLExpression initialValue = DSLExpression(), Position pos = {}, Position namePos = {}); - - DSLVar(DSLVar&&) = default; - - void swap(DSLVar& other); - -private: - using INHERITED = DSLVarBase; -}; - -/** - * A global variable. - */ -class DSLGlobalVar : public DSLVarBase { -public: - DSLGlobalVar(); - - DSLGlobalVar(DSLType type, std::string_view name, DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLGlobalVar(const DSLModifiers& modifiers, DSLType type, std::string_view name, - DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLGlobalVar(const char* name); - - DSLGlobalVar(DSLGlobalVar&&) = default; - - void swap(DSLGlobalVar& other); - - /** - * Implements the following method calls: - * half4 shader::eval(float2 coords); - * half4 colorFilter::eval(half4 input); - */ - DSLExpression eval(DSLExpression x, Position pos = {}); - - /** - * Implements the following method call: - * half4 blender::eval(half4 src, half4 dst); - */ - DSLExpression eval(DSLExpression x, DSLExpression y, Position pos = {}); - -private: - DSLExpression eval(ExpressionArray args, Position pos); - - std::unique_ptr methodCall(std::string_view methodName, Position pos); - - using INHERITED = DSLVarBase; -}; - -/** - * A function parameter. - */ -class DSLParameter : public DSLVarBase { -public: - DSLParameter(); - - DSLParameter(DSLType type, std::string_view name, Position pos = {}, Position namePos = {}); - - DSLParameter(const DSLModifiers& modifiers, DSLType type, std::string_view name, - Position pos = {}, Position namePos = {}); - - DSLParameter(DSLParameter&&) = default; - - void swap(DSLParameter& other); - -private: - using INHERITED = DSLVarBase; -}; - -} // namespace dsl - -} // namespace SkSL - - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h deleted file mode 100644 index 4abf4631b8b17..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_ERROR_REPORTER -#define SKSL_ERROR_REPORTER - -#include "include/core/SkTypes.h" - -#include - -namespace SkSL { - -class Position; - -/** - * Class which is notified in the event of an error. - */ -class ErrorReporter { -public: - ErrorReporter() {} - - virtual ~ErrorReporter() {} - - void error(Position position, std::string_view msg); - - std::string_view source() const { return fSource; } - - void setSource(std::string_view source) { fSource = source; } - - int errorCount() const { - return fErrorCount; - } - - void resetErrorCount() { - fErrorCount = 0; - } - -protected: - /** - * Called when an error is reported. - */ - virtual void handleError(std::string_view msg, Position position) = 0; - -private: - Position position(int offset) const; - - std::string_view fSource; - int fErrorCount = 0; -}; - -/** - * Error reporter for tests that need an SkSL context; aborts immediately if an error is reported. - */ -class TestingOnly_AbortErrorReporter : public ErrorReporter { -public: - void handleError(std::string_view msg, Position pos) override; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h deleted file mode 100644 index 1e47dce618856..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_OPERATOR -#define SKSL_OPERATOR - -#include -#include - -namespace SkSL { - -class Context; -class Type; - -enum class OperatorKind : uint8_t { - PLUS, - MINUS, - STAR, - SLASH, - PERCENT, - SHL, - SHR, - LOGICALNOT, - LOGICALAND, - LOGICALOR, - LOGICALXOR, - BITWISENOT, - BITWISEAND, - BITWISEOR, - BITWISEXOR, - EQ, - EQEQ, - NEQ, - LT, - GT, - LTEQ, - GTEQ, - PLUSEQ, - MINUSEQ, - STAREQ, - SLASHEQ, - PERCENTEQ, - SHLEQ, - SHREQ, - BITWISEANDEQ, - BITWISEOREQ, - BITWISEXOREQ, - PLUSPLUS, - MINUSMINUS, - COMMA -}; - -enum class OperatorPrecedence : uint8_t { - kParentheses = 1, - kPostfix = 2, - kPrefix = 3, - kMultiplicative = 4, - kAdditive = 5, - kShift = 6, - kRelational = 7, - kEquality = 8, - kBitwiseAnd = 9, - kBitwiseXor = 10, - kBitwiseOr = 11, - kLogicalAnd = 12, - kLogicalXor = 13, - kLogicalOr = 14, - kTernary = 15, - kAssignment = 16, - kSequence = 17, - kTopLevel = kSequence -}; - -class Operator { -public: - using Kind = OperatorKind; - - Operator(Kind op) : fKind(op) {} - - Kind kind() const { return fKind; } - - bool isEquality() const { - return fKind == Kind::EQEQ || fKind == Kind::NEQ; - } - - OperatorPrecedence getBinaryPrecedence() const; - - // Returns the operator name surrounded by the expected whitespace for a tidy binary expression. - const char* operatorName() const; - - // Returns the operator name without any surrounding whitespace. - std::string_view tightOperatorName() const; - - // Returns true if op is '=' or any compound assignment operator ('+=', '-=', etc.) - bool isAssignment() const; - - // Given a compound assignment operator, returns the non-assignment version of the operator - // (e.g. '+=' becomes '+') - Operator removeAssignment() const; - - /** - * Defines the set of relational (comparison) operators: - * < <= > >= - */ - bool isRelational() const; - - /** - * Defines the set of operators which are only valid on integral types: - * << <<= >> >>= & &= | |= ^ ^= % %= - */ - bool isOnlyValidForIntegralTypes() const; - - /** - * Defines the set of operators which perform vector/matrix math. - * + += - -= * *= / /= % %= << <<= >> >>= & &= | |= ^ ^= - */ - bool isValidForMatrixOrVector() const; - - /* - * Defines the set of operators allowed by The OpenGL ES Shading Language 1.00, Section 5.1. - * The set of illegal (reserved) operators are the ones that only make sense with integral - * types. This is not a coincidence: It's because ES2 doesn't require 'int' to be anything but - * syntactic sugar for floats with truncation after each operation. - */ - bool isAllowedInStrictES2Mode() const { - return !this->isOnlyValidForIntegralTypes(); - } - - /** - * Determines the operand and result types of a binary expression. Returns true if the - * expression is legal, false otherwise. If false, the values of the out parameters are - * undefined. - */ - bool determineBinaryType(const Context& context, - const Type& left, - const Type& right, - const Type** outLeftType, - const Type** outRightType, - const Type** outResultType) const; - -private: - bool isOperator() const; - bool isMatrixMultiply(const Type& left, const Type& right) const; - - Kind fKind; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h deleted file mode 100644 index 5f8e80a607b8f..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_POSITION -#define SKSL_POSITION - -#include "include/core/SkTypes.h" - -#include -#include - -namespace SkSL { - -class Position { -public: - Position() - : fStartOffset(-1) - , fLength(0) {} - - static Position Range(int startOffset, int endOffset) { - SkASSERT(startOffset <= endOffset); - SkASSERT(startOffset <= 0xFFFFFF); - int length = endOffset - startOffset; - Position result; - result.fStartOffset = startOffset; - result.fLength = length <= 0xFF ? length : 0xFF; - return result; - } - - bool valid() const { - return fStartOffset != -1; - } - - int line(std::string_view source) const; - - int startOffset() const { - SkASSERT(this->valid()); - return fStartOffset; - } - - int endOffset() const { - SkASSERT(this->valid()); - return fStartOffset + fLength; - } - - // Returns the position from this through, and including the entirety of, end. - Position rangeThrough(Position end) const { - if (fStartOffset == -1 || end.fStartOffset == -1) { - return *this; - } - SkASSERTF(this->startOffset() <= end.startOffset() && this->endOffset() <= end.endOffset(), - "Invalid range: (%d-%d) - (%d-%d)\n", this->startOffset(), this->endOffset(), - end.startOffset(), end.endOffset()); - return Range(this->startOffset(), end.endOffset()); - } - - // Returns a position representing the character immediately after this position - Position after() const { - int endOffset = this->endOffset(); - return Range(endOffset, endOffset + 1); - } - - bool operator==(const Position& other) const { - return fStartOffset == other.fStartOffset && fLength == other.fLength; - } - - bool operator!=(const Position& other) const { - return !(*this == other); - } - - bool operator>(const Position& other) const { - return fStartOffset > other.fStartOffset; - } - - bool operator>=(const Position& other) const { - return fStartOffset >= other.fStartOffset; - } - - bool operator<(const Position& other) const { - return fStartOffset < other.fStartOffset; - } - - bool operator<=(const Position& other) const { - return fStartOffset <= other.fStartOffset; - } - -private: - int32_t fStartOffset : 24; - uint32_t fLength : 8; -}; - -struct ForLoopPositions { - Position initPosition = Position(); - Position conditionPosition = Position(); - Position nextPosition = Position(); -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h index d2c8b8b23b964..536691875e4f4 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h @@ -14,7 +14,7 @@ #include "include/core/SkMatrix.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" // NOTE -- This entire header / impl is deprecated, and will be removed from Skia soon. // diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h index afdf91e5ebcb8..d387fb24ca6bc 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h @@ -14,12 +14,15 @@ #include "include/core/SkPath.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" +#include #include class SkStream; -class SkTypeface; +class SkStreamAsset; +struct SkFontArguments; class SK_API SkCustomTypefaceBuilder { public: @@ -33,6 +36,9 @@ class SK_API SkCustomTypefaceBuilder { sk_sp detach(); + static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('u','s','e','r'); + static sk_sp MakeFromStream(std::unique_ptr, const SkFontArguments&); + private: struct GlyphRec { // logical union diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h index 5ef7a103a98af..87c6916b39f09 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h @@ -9,17 +9,14 @@ #ifndef SkNWayCanvas_DEFINED #define SkNWayCanvas_DEFINED -#include "include/core/SkBlendMode.h" -#include "include/core/SkCanvas.h" #include "include/core/SkCanvasVirtualEnforcer.h" -#include "include/core/SkClipOp.h" #include "include/core/SkColor.h" #include "include/core/SkM44.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSamplingOptions.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" #include "include/utils/SkNoDrawCanvas.h" #include @@ -28,6 +25,7 @@ namespace sktext { class GlyphRunList; } +class SkCanvas; class SkData; class SkDrawable; class SkImage; @@ -40,12 +38,14 @@ class SkRegion; class SkShader; class SkTextBlob; class SkVertices; +enum class SkBlendMode; +enum class SkClipOp; struct SkDrawShadowRec; struct SkPoint; struct SkRSXform; struct SkRect; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) namespace sktext::gpu { class Slug; } @@ -77,7 +77,7 @@ class SK_API SkNWayCanvas : public SkCanvasVirtualEnforcer { void onDrawGlyphRunList(const sktext::GlyphRunList&, const SkPaint&) override; void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) override; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) void onDrawSlug(const sktext::gpu::Slug* slug) override; #endif void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h index a03bfdb54108a..0b686e5edc5af 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h @@ -39,14 +39,15 @@ class SK_API SkOrderedFontMgr : public SkFontMgr { protected: int onCountFamilies() const override; void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onCreateStyleSet(int index)const override; + sk_sp onCreateStyleSet(int index)const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkTypeface* onMatchFamilyStyle(const char familyName[], const SkFontStyle&) const override; - SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const override; + sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle&) const override; + sk_sp onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const override; // Note: all of these always return null sk_sp onMakeFromData(sk_sp, int ttcIndex) const override; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h index 5ce3c26f1dc74..9a836bc7c2551 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h @@ -8,7 +8,6 @@ #ifndef SkPaintFilterCanvas_DEFINED #define SkPaintFilterCanvas_DEFINED -#include "include/core/SkBlendMode.h" #include "include/core/SkCanvas.h" #include "include/core/SkCanvasVirtualEnforcer.h" #include "include/core/SkColor.h" @@ -18,7 +17,7 @@ #include "include/core/SkScalar.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" #include "include/utils/SkNWayCanvas.h" #include @@ -42,6 +41,7 @@ class SkSurface; class SkSurfaceProps; class SkTextBlob; class SkVertices; +enum class SkBlendMode; struct SkDrawShadowRec; struct SkPoint; struct SkRSXform; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h index f1c81b2f28d3c..acd0ef2305c03 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h @@ -19,7 +19,7 @@ class SK_API SkParsePath { static bool FromSVGString(const char str[], SkPath*); enum class PathEncoding { Absolute, Relative }; - static void ToSVGString(const SkPath&, SkString*, PathEncoding = PathEncoding::Absolute); + static SkString ToSVGString(const SkPath&, PathEncoding = PathEncoding::Absolute); }; #endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h deleted file mode 100644 index ba40732b9cf7a..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2006 The Android Open Source Project - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkRandom_DEFINED -#define SkRandom_DEFINED - -#include "include/core/SkScalar.h" -#include "include/private/SkFixed.h" -#include "include/private/SkFloatBits.h" - -/** \class SkRandom - - Utility class that implements pseudo random 32bit numbers using Marsaglia's - multiply-with-carry "mother of all" algorithm. Unlike rand(), this class holds - its own state, so that multiple instances can be used with no side-effects. - - Has a large period and all bits are well-randomized. - */ -class SkRandom { -public: - SkRandom() { init(0); } - SkRandom(uint32_t seed) { init(seed); } - SkRandom(const SkRandom& rand) : fK(rand.fK), fJ(rand.fJ) {} - - SkRandom& operator=(const SkRandom& rand) { - fK = rand.fK; - fJ = rand.fJ; - - return *this; - } - - /** Return the next pseudo random number as an unsigned 32bit value. - */ - uint32_t nextU() { - fK = kKMul*(fK & 0xffff) + (fK >> 16); - fJ = kJMul*(fJ & 0xffff) + (fJ >> 16); - return (((fK << 16) | (fK >> 16)) + fJ); - } - - /** Return the next pseudo random number as a signed 32bit value. - */ - int32_t nextS() { return (int32_t)this->nextU(); } - - /** - * Returns value [0...1) as an IEEE float - */ - float nextF() { - int floatint = 0x3f800000 | (int)(this->nextU() >> 9); - float f = SkBits2Float(floatint) - 1.0f; - return f; - } - - /** - * Returns value [min...max) as a float - */ - float nextRangeF(float min, float max) { - return min + this->nextF() * (max - min); - } - - /** Return the next pseudo random number, as an unsigned value of - at most bitCount bits. - @param bitCount The maximum number of bits to be returned - */ - uint32_t nextBits(unsigned bitCount) { - SkASSERT(bitCount > 0 && bitCount <= 32); - return this->nextU() >> (32 - bitCount); - } - - /** Return the next pseudo random unsigned number, mapped to lie within - [min, max] inclusive. - */ - uint32_t nextRangeU(uint32_t min, uint32_t max) { - SkASSERT(min <= max); - uint32_t range = max - min + 1; - if (0 == range) { - return this->nextU(); - } else { - return min + this->nextU() % range; - } - } - - /** Return the next pseudo random unsigned number, mapped to lie within - [0, count). - */ - uint32_t nextULessThan(uint32_t count) { - SkASSERT(count > 0); - return this->nextRangeU(0, count - 1); - } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [0..SK_Scalar1). - */ - SkScalar nextUScalar1() { return SkFixedToScalar(this->nextUFixed1()); } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [min..max). - */ - SkScalar nextRangeScalar(SkScalar min, SkScalar max) { - return this->nextUScalar1() * (max - min) + min; - } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [-SK_Scalar1..SK_Scalar1). - */ - SkScalar nextSScalar1() { return SkFixedToScalar(this->nextSFixed1()); } - - /** Return the next pseudo random number as a bool. - */ - bool nextBool() { return this->nextU() >= 0x80000000; } - - /** A biased version of nextBool(). - */ - bool nextBiasedBool(SkScalar fractionTrue) { - SkASSERT(fractionTrue >= 0 && fractionTrue <= SK_Scalar1); - return this->nextUScalar1() <= fractionTrue; - } - - /** Reset the random object. - */ - void setSeed(uint32_t seed) { init(seed); } - -private: - // Initialize state variables with LCG. - // We must ensure that both J and K are non-zero, otherwise the - // multiply-with-carry step will forevermore return zero. - void init(uint32_t seed) { - fK = NextLCG(seed); - if (0 == fK) { - fK = NextLCG(fK); - } - fJ = NextLCG(fK); - if (0 == fJ) { - fJ = NextLCG(fJ); - } - SkASSERT(0 != fK && 0 != fJ); - } - static uint32_t NextLCG(uint32_t seed) { return kMul*seed + kAdd; } - - /** Return the next pseudo random number expressed as an unsigned SkFixed - in the range [0..SK_Fixed1). - */ - SkFixed nextUFixed1() { return this->nextU() >> 16; } - - /** Return the next pseudo random number expressed as a signed SkFixed - in the range [-SK_Fixed1..SK_Fixed1). - */ - SkFixed nextSFixed1() { return this->nextS() >> 15; } - - // See "Numerical Recipes in C", 1992 page 284 for these constants - // For the LCG that sets the initial state from a seed - enum { - kMul = 1664525, - kAdd = 1013904223 - }; - // Constants for the multiply-with-carry steps - enum { - kKMul = 30345, - kJMul = 18000, - }; - - uint32_t fK; - uint32_t fJ; -}; - -#endif diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h index 2ee56934ade6d..322549b38f7ed 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h @@ -51,6 +51,17 @@ SKCMS_API float skcms_TransferFunction_eval (const skcms_TransferFunction*, flo SKCMS_API bool skcms_TransferFunction_invert(const skcms_TransferFunction*, skcms_TransferFunction*); +typedef enum skcms_TFType { + skcms_TFType_Invalid, + skcms_TFType_sRGBish, + skcms_TFType_PQish, + skcms_TFType_HLGish, + skcms_TFType_HLGinvish, +} skcms_TFType; + +// Identify which kind of transfer function is encoded in an skcms_TransferFunction +SKCMS_API skcms_TFType skcms_TransferFunction_getType(const skcms_TransferFunction*); + // We can jam a couple alternate transfer function forms into skcms_TransferFunction, // including those matching the general forms of the SMPTE ST 2084 PQ function or HLG. // @@ -307,6 +318,9 @@ typedef enum skcms_PixelFormat { skcms_PixelFormat_BGR_fff, // Pointers must be 32-bit aligned. skcms_PixelFormat_RGBA_ffff, skcms_PixelFormat_BGRA_ffff, + + skcms_PixelFormat_RGB_101010x_XR, // Note: This is located here to signal no clamping. + skcms_PixelFormat_BGR_101010x_XR, // Compatible with MTLPixelFormatBGR10_XR. } skcms_PixelFormat; // We always store any alpha channel linearly. In the chart below, tf-1() is the inverse diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h index 7b8aa8ac1c50f..350f6a20a6c6b 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h @@ -903,6 +903,16 @@ static void exec_ops(const Op* ops, const void** args, a = cast((rgba >> 30) & 0x3 ) * (1/ 3.0f); } break; + case Op_load_101010x_XR:{ + static constexpr float min = -0.752941f; + static constexpr float max = 1.25098f; + static constexpr float range = max - min; + U32 rgba = load(src + 4*i); + r = cast((rgba >> 0) & 0x3ff) * (1/1023.0f) * range + min; + g = cast((rgba >> 10) & 0x3ff) * (1/1023.0f) * range + min; + b = cast((rgba >> 20) & 0x3ff) * (1/1023.0f) * range + min; + } break; + case Op_load_161616LE:{ uintptr_t ptr = (uintptr_t)(src + 6*i); assert( (ptr & 1) == 0 ); // src must be 2-byte aligned for this @@ -1313,6 +1323,15 @@ static void exec_ops(const Op* ops, const void** args, | cast(to_fixed(a * 255)) << 24); } return; + case Op_store_101010x_XR: { + static constexpr float min = -0.752941f; + static constexpr float max = 1.25098f; + static constexpr float range = max - min; + store(dst + 4*i, cast(to_fixed(((r - min) / range) * 1023)) << 0 + | cast(to_fixed(((g - min) / range) * 1023)) << 10 + | cast(to_fixed(((b - min) / range) * 1023)) << 20); + return; + } case Op_store_1010102: { store(dst + 4*i, cast(to_fixed(r * 1023)) << 0 | cast(to_fixed(g * 1023)) << 10 diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h index a119e4b28d2c7..bc895f99c6e81 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h @@ -7,10 +7,10 @@ #include #include "include/core/SkFontMgr.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTHash.h" #include "modules/skparagraph/include/FontArguments.h" #include "modules/skparagraph/include/ParagraphCache.h" #include "modules/skparagraph/include/TextStyle.h" +#include "src/core/SkTHash.h" namespace skia { namespace textlayout { @@ -69,7 +69,7 @@ class FontCollection : public SkRefCnt { }; bool fEnableFontFallback; - SkTHashMap>, FamilyKey::Hasher> fTypefaces; + skia_private::THashMap>, FamilyKey::Hasher> fTypefaces; sk_sp fDefaultFontManager; sk_sp fAssetFontManager; sk_sp fDynamicFontManager; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h index 5c5503876bec8..c78b0798412a1 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h @@ -12,6 +12,8 @@ class SkCanvas; namespace skia { namespace textlayout { +class ParagraphPainter; + class Paragraph { public: @@ -39,6 +41,8 @@ class Paragraph { virtual void paint(SkCanvas* canvas, SkScalar x, SkScalar y) = 0; + virtual void paint(ParagraphPainter* painter, SkScalar x, SkScalar y) = 0; + // Returns a vector of bounding boxes that enclose all text between // start and end glyph indexes, including start and excluding end virtual std::vector getRectsForRange(unsigned start, @@ -66,9 +70,9 @@ class Paragraph { // -1 if not applicable (has not been shaped yet - valid case) virtual int32_t unresolvedGlyphs() = 0; - // Experimental API that allows fast way to update "immutable" paragraph + // Experimental API that allows fast way to update some of "immutable" paragraph attributes + // but not the text itself virtual void updateTextAlign(TextAlign textAlign) = 0; - virtual void updateText(size_t from, SkString text) = 0; virtual void updateFontSize(size_t from, size_t to, SkScalar fontSize) = 0; virtual void updateForegroundPaint(size_t from, size_t to, SkPaint paint) = 0; virtual void updateBackgroundPaint(size_t from, size_t to, SkPaint paint) = 0; @@ -91,6 +95,72 @@ class Paragraph { using Visitor = std::function; virtual void visit(const Visitor&) = 0; + // Editing API + virtual int getLineNumberAt(TextIndex codeUnitIndex) const = 0; + + /* Returns line metrics info for the line + * + * @param lineNumber a line number + * @param lineMetrics an address to return the info (in case of null just skipped) + * @return true if the line is found; false if not + */ + virtual bool getLineMetricsAt(int lineNumber, LineMetrics* lineMetrics) const = 0; + + /* Returns the visible text on the line (excluding a possible ellipsis) + * + * @param lineNumber a line number + * @param includeSpaces indicates if the whitespaces should be included + * @return the range of the text that is shown in the line + */ + virtual TextRange getActualTextRange(int lineNumber, bool includeSpaces) const = 0; + + struct GlyphClusterInfo { + SkRect fBounds; + TextRange fClusterTextRange; + TextDirection fGlyphClusterPosition; + }; + + /** Finds a glyph cluster for text index + * + * @param codeUnitIndex a text index + * @param glyphInfo a glyph cluster info filled if not null + * @return true if glyph cluster was found; false if not + */ + virtual bool getGlyphClusterAt(TextIndex codeUnitIndex, GlyphClusterInfo* glyphInfo) = 0; + + /** Finds the closest glyph cluster for a visual text position + * + * @param dx x coordinate + * @param dy y coordinate + * @param glyphInfo a glyph cluster info filled if not null + * @return + */ + virtual bool getClosestGlyphClusterAt(SkScalar dx, + SkScalar dy, + GlyphClusterInfo* glyphInfo) = 0; + + struct FontInfo { + FontInfo(const SkFont font, const TextRange textRange) + : fFont(font), fTextRange(textRange) { } + virtual ~FontInfo() = default; + FontInfo(const FontInfo& ) = default; + SkFont fFont; + TextRange fTextRange; + }; + + /** Returns the font that is used to shape the text at the position + * + * @param codeUnitIndex text index + * @return font info or an empty font info if the text is not found + */ + virtual SkFont getFontAt(TextIndex codeUnitIndex) const = 0; + + /** Returns the information about all the fonts used to shape the paragraph text + * + * @return a list of fonts and text ranges + */ + virtual std::vector getFonts() const = 0; + protected: sk_sp fFontCollection; ParagraphStyle fParagraphStyle; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h index 90ffb7019d8e8..45652ae79912c 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h @@ -2,7 +2,7 @@ #ifndef ParagraphCache_DEFINED #define ParagraphCache_DEFINED -#include "include/private/SkMutex.h" +#include "include/private/base/SkMutex.h" #include "src/core/SkLRUCache.h" #include // std::function @@ -11,16 +11,6 @@ namespace skia { namespace textlayout { -enum InternalState { - kUnknown = 0, - kShaped = 2, - kClusterized = 3, - kMarked = 4, - kLineBroken = 5, - kFormatted = 6, - kDrawn = 7 -}; - class ParagraphImpl; class ParagraphCacheKey; class ParagraphCacheValue; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h new file mode 100644 index 0000000000000..56388e64f17bd --- /dev/null +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h @@ -0,0 +1,63 @@ +// Copyright 2019 Google LLC. +#ifndef ParagraphPainter_DEFINED +#define ParagraphPainter_DEFINED + +#include "include/core/SkPaint.h" +#include "include/core/SkTextBlob.h" + +#include +#include + +namespace skia { +namespace textlayout { + +class ParagraphPainter { +public: + typedef int PaintID; + typedef std::variant SkPaintOrID; + + struct DashPathEffect { + DashPathEffect(SkScalar onLength, SkScalar offLength); + + SkScalar fOnLength; + SkScalar fOffLength; + }; + + class DecorationStyle { + public: + DecorationStyle(); + DecorationStyle(SkColor color, SkScalar strokeWidth, + std::optional dashPathEffect); + + SkColor getColor() const { return fColor; } + SkScalar getStrokeWidth() const { return fStrokeWidth; } + std::optional getDashPathEffect() const { return fDashPathEffect; } + const SkPaint& skPaint() const { return fPaint; } + + private: + SkColor fColor; + SkScalar fStrokeWidth; + std::optional fDashPathEffect; + SkPaint fPaint; + }; + + virtual ~ParagraphPainter() = default; + + virtual void drawTextBlob(const sk_sp& blob, SkScalar x, SkScalar y, const SkPaintOrID& paint) = 0; + virtual void drawTextShadow(const sk_sp& blob, SkScalar x, SkScalar y, SkColor color, SkScalar blurSigma) = 0; + virtual void drawRect(const SkRect& rect, const SkPaintOrID& paint) = 0; + virtual void drawFilledRect(const SkRect& rect, const DecorationStyle& decorStyle) = 0; + virtual void drawPath(const SkPath& path, const DecorationStyle& decorStyle) = 0; + virtual void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const DecorationStyle& decorStyle) = 0; + + virtual void clipRect(const SkRect& rect) = 0; + virtual void translate(SkScalar dx, SkScalar dy) = 0; + + virtual void save() = 0; + virtual void restore() = 0; +}; + +} // namespace textlayout +} // namespace skia + +#endif // ParagraphPainter_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h index 82b4a7cb13cb4..e6f0ae46302d9 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h @@ -12,6 +12,7 @@ #include "include/core/SkScalar.h" #include "modules/skparagraph/include/DartTypes.h" #include "modules/skparagraph/include/FontArguments.h" +#include "modules/skparagraph/include/ParagraphPainter.h" #include "modules/skparagraph/include/TextShadow.h" // TODO: Make it external so the other platforms (Android) could use it @@ -165,19 +166,41 @@ class TextStyle { void setColor(SkColor color) { fColor = color; } bool hasForeground() const { return fHasForeground; } - SkPaint getForeground() const { return fForeground; } + SkPaint getForeground() const { + const SkPaint* paint = std::get_if(&fForeground); + return paint ? *paint : SkPaint(); + } + ParagraphPainter::SkPaintOrID getForegroundPaintOrID() const { + return fForeground; + } void setForegroundColor(SkPaint paint) { fHasForeground = true; fForeground = std::move(paint); } + // Set the foreground to a paint ID. This is intended for use by clients + // that implement a custom ParagraphPainter that can not accept an SkPaint. + void setForegroundPaintID(ParagraphPainter::PaintID paintID) { + fHasForeground = true; + fForeground = paintID; + } void clearForegroundColor() { fHasForeground = false; } bool hasBackground() const { return fHasBackground; } - SkPaint getBackground() const { return fBackground; } + SkPaint getBackground() const { + const SkPaint* paint = std::get_if(&fBackground); + return paint ? *paint : SkPaint(); + } + ParagraphPainter::SkPaintOrID getBackgroundPaintOrID() const { + return fBackground; + } void setBackgroundColor(SkPaint paint) { fHasBackground = true; fBackground = std::move(paint); } + void setBackgroundPaintID(ParagraphPainter::PaintID paintID) { + fHasBackground = true; + fBackground = paintID; + } void clearBackgroundColor() { fHasBackground = false; } // Decorations @@ -291,9 +314,9 @@ class TextStyle { SkColor fColor = SK_ColorWHITE; bool fHasBackground = false; - SkPaint fBackground; + ParagraphPainter::SkPaintOrID fBackground; bool fHasForeground = false; - SkPaint fForeground; + ParagraphPainter::SkPaintOrID fForeground; std::vector fTextShadows; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h index df759b125ad24..c51110cd4fea9 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h @@ -2,8 +2,8 @@ #ifndef TypefaceFontProvider_DEFINED #define TypefaceFontProvider_DEFINED -#include "include/private/SkTArray.h" -#include "include/private/SkTHash.h" +#include "include/private/base/SkTArray.h" +#include "src/core/SkTHash.h" #include #include #include @@ -20,15 +20,15 @@ class TypefaceFontStyleSet : public SkFontStyleSet { int count() override; void getStyle(int index, SkFontStyle*, SkString* name) override; - SkTypeface* createTypeface(int index) override; - SkTypeface* matchStyle(const SkFontStyle& pattern) override; + sk_sp createTypeface(int index) override; + sk_sp matchStyle(const SkFontStyle& pattern) override; SkString getFamilyName() const { return fFamilyName; } SkString getAlias() const { return fAlias; } void appendTypeface(sk_sp typeface); private: - SkTArray> fStyles; + skia_private::TArray> fStyles; SkString fFamilyName; SkString fAlias; }; @@ -42,15 +42,15 @@ class TypefaceFontProvider : public SkFontMgr { void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkFontStyleSet* onCreateStyleSet(int) const override { return nullptr; } - SkTypeface* onMatchFamilyStyle(const char[], const SkFontStyle&) const override { + sk_sp onCreateStyleSet(int) const override { return nullptr; } + sk_sp onMatchFamilyStyle(const char[], const SkFontStyle&) const override { return nullptr; } - SkTypeface* onMatchFamilyStyleCharacter(const char[], const SkFontStyle&, - const char*[], int, - SkUnichar) const override { + sk_sp onMatchFamilyStyleCharacter(const char[], const SkFontStyle&, + const char*[], int, + SkUnichar) const override { return nullptr; } @@ -71,8 +71,8 @@ class TypefaceFontProvider : public SkFontMgr { } private: - SkTHashMap> fRegisteredFamilies; - SkTArray fFamilyNames; + skia_private::THashMap> fRegisteredFamilies; + skia_private::TArray fFamilyNames; }; } // namespace textlayout diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h index f59471198b066..a0f44a83be116 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h @@ -15,8 +15,8 @@ #include "include/core/SkString.h" #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTHash.h" +#include "include/private/base/SkMutex.h" +#include "src/core/SkTHash.h" #include @@ -50,6 +50,18 @@ class SK_API ImageAsset : public SkRefCnt { */ virtual sk_sp getFrame(float t); + // Describes how the frame image is to be scaled to the animation-declared asset size. + enum class SizeFit { + // See SkMatrix::ScaleToFit + kFill = SkMatrix::kFill_ScaleToFit, + kStart = SkMatrix::kStart_ScaleToFit, + kCenter = SkMatrix::kCenter_ScaleToFit, + kEnd = SkMatrix::kEnd_ScaleToFit, + + // No scaling. + kNone, + }; + struct FrameData { // SkImage payload. sk_sp image; @@ -57,6 +69,8 @@ class SK_API ImageAsset : public SkRefCnt { SkSamplingOptions sampling; // Additional image transform to be applied before AE scaling rules. SkMatrix matrix = SkMatrix::I(); + // Strategy for image size -> AE asset size scaling. + SizeFit scaling = SizeFit::kCenter; }; /** @@ -227,8 +241,8 @@ class SK_API CachingResourceProvider final : public ResourceProviderProxyBase { sk_sp loadImageAsset(const char[], const char[], const char[]) const override; - mutable SkMutex fMutex; - mutable SkTHashMap> fImageCache; + mutable SkMutex fMutex; + mutable skia_private::THashMap> fImageCache; using INHERITED = ResourceProviderProxyBase; }; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h index d6996638ccdcf..8e4d56caee221 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h @@ -9,7 +9,7 @@ #define SkSVGAttribute_DEFINED #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGRenderContext; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h index e4ac579f7966d..9513232218668 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h @@ -10,9 +10,9 @@ #include -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGAttributeParser : public SkNoncopyable { public: diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h index 560271854f5b6..e5e9516c32e68 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h @@ -8,7 +8,7 @@ #ifndef SkSVGContainer_DEFINED #define SkSVGContainer_DEFINED -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include "modules/svg/include/SkSVGTransformableNode.h" class SkSVGContainer : public SkSVGTransformableNode { @@ -27,7 +27,7 @@ class SkSVGContainer : public SkSVGTransformableNode { bool hasChildren() const final; // TODO: add some sort of child iterator, and hide the container. - SkSTArray<1, sk_sp, true> fChildren; + skia_private::STArray<1, sk_sp, true> fChildren; private: using INHERITED = SkSVGTransformableNode; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h index a035179b70e7b..f0bd467d28aee 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h @@ -11,7 +11,7 @@ #include "include/core/SkFontMgr.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include "modules/skresources/include/SkResources.h" #include "modules/svg/include/SkSVGIDMapper.h" diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h index edd503403c130..dcd938d1e1838 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h @@ -11,8 +11,8 @@ #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" #include "include/core/SkString.h" -#include "include/private/SkTHash.h" #include "modules/svg/include/SkSVGTypes.h" +#include "src/core/SkTHash.h" class SkImageFilter; class SkSVGFeInputType; @@ -61,7 +61,7 @@ class SkSVGFilterContext { SkSVGObjectBoundingBoxUnits fPrimitiveUnits; - SkTHashMap fResults; + skia_private::THashMap fResults; Result fPreviousResult; }; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h index 2c1e45afcf5d8..16053e83c85fd 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h @@ -37,8 +37,8 @@ class SkSVGGradient : public SkSVGHiddenContainer { SkTileMode, const SkMatrix& localMatrix) const = 0; private: - using StopPositionArray = SkSTArray<2, SkScalar , true>; - using StopColorArray = SkSTArray<2, SkColor4f, true>; + using StopPositionArray = skia_private::STArray<2, SkScalar , true>; + using StopColorArray = skia_private::STArray<2, SkColor4f, true>; void collectColorStops(const SkSVGRenderContext&, StopPositionArray*, StopColorArray*) const; SkColor4f resolveStopColor(const SkSVGRenderContext&, const SkSVGStop&) const; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h index ea0d9165fcbae..e78f28de37368 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h @@ -9,11 +9,11 @@ #define SkSVGIDMapper_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkTHash.h" +#include "src/core/SkTHash.h" class SkString; class SkSVGNode; -using SkSVGIDMapper = SkTHashMap>; +using SkSVGIDMapper = skia_private::THashMap>; #endif // SkSVGIDMapper_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h index 27a86395cb4b4..32ee8a08e415f 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h @@ -15,11 +15,11 @@ #include "include/core/SkRect.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" -#include "include/private/SkTHash.h" #include "modules/skresources/include/SkResources.h" #include "modules/svg/include/SkSVGAttribute.h" #include "modules/svg/include/SkSVGIDMapper.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" +#include "src/core/SkTHash.h" class SkCanvas; class SkSVGLength; @@ -52,7 +52,7 @@ struct SkSVGPresentationContext { SkSVGPresentationContext(const SkSVGPresentationContext&) = default; SkSVGPresentationContext& operator=(const SkSVGPresentationContext&) = default; - const SkTHashMap* fNamedColors = nullptr; + const skia_private::THashMap* fNamedColors = nullptr; // Inherited presentation attributes, computed for the current node. SkSVGPresentationAttributes fInherited; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h index 91f33dea9a3c2..41e041de3f76c 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h @@ -10,7 +10,7 @@ #include "modules/svg/include/SkSVGContainer.h" #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGLengthContext; diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h index db103bef59179..77c5fbef40562 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h @@ -18,8 +18,9 @@ #include "include/core/SkSpan.h" #include "include/core/SkString.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" -#include "src/core/SkTLazy.h" + +#include +#include using SkSVGColorType = SkColor; using SkSVGIntegerType = int; @@ -27,7 +28,7 @@ using SkSVGNumberType = SkScalar; using SkSVGStringType = SkString; using SkSVGViewBoxType = SkRect; using SkSVGTransformType = SkMatrix; -using SkSVGPointsType = SkTDArray; +using SkSVGPointsType = std::vector; enum class SkSVGPropertyState { kUnspecified, @@ -45,17 +46,17 @@ template class SkSVGProperty { explicit SkSVGProperty(SkSVGPropertyState state) : fState(state) {} explicit SkSVGProperty(const T& value) : fState(SkSVGPropertyState::kValue) { - fValue.set(value); + fValue = value; } explicit SkSVGProperty(T&& value) : fState(SkSVGPropertyState::kValue) { - fValue.set(std::move(value)); + fValue = std::move(value); } template void init(Args&&... args) { fState = SkSVGPropertyState::kValue; - fValue.init(std::forward(args)...); + fValue.emplace(std::forward(args)...); } constexpr bool isInheritable() const { return kInheritable; } @@ -63,7 +64,7 @@ template class SkSVGProperty { bool isValue() const { return fState == SkSVGPropertyState::kValue; } T* getMaybeNull() const { - return fValue.getMaybeNull(); + return fValue.has_value() ? &fValue.value() : nullptr; } void set(SkSVGPropertyState state) { @@ -75,41 +76,41 @@ template class SkSVGProperty { void set(const T& value) { fState = SkSVGPropertyState::kValue; - fValue.set(value); + fValue = value; } void set(T&& value) { fState = SkSVGPropertyState::kValue; - fValue.set(std::move(value)); + fValue = std::move(value); } T* operator->() { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); - return fValue.get(); + SkASSERT(fValue.has_value()); + return &fValue.value(); } const T* operator->() const { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); - return fValue.get(); + SkASSERT(fValue.has_value()); + return &fValue.value(); } T& operator*() { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); + SkASSERT(fValue.has_value()); return *fValue; } const T& operator*() const { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); + SkASSERT(fValue.has_value()); return *fValue; } private: SkSVGPropertyState fState; - SkTLazy fValue; + std::optional fValue; }; class SkSVGLength { @@ -180,7 +181,7 @@ class SkSVGColor { kColor, kICCColor, }; - using Vars = SkSTArray<1, SkString>; + using Vars = std::vector; SkSVGColor() : SkSVGColor(SK_ColorBLACK) {} explicit SkSVGColor(const SkSVGColorType& c) : fType(Type::kColor), fColor(c), fVars(nullptr) {} @@ -400,7 +401,7 @@ class SkSVGDashArray { SkSVGDashArray() : fType(Type::kNone) {} explicit SkSVGDashArray(Type t) : fType(t) {} - explicit SkSVGDashArray(SkTDArray&& dashArray) + explicit SkSVGDashArray(std::vector&& dashArray) : fType(Type::kDashArray) , fDashArray(std::move(dashArray)) {} @@ -414,11 +415,11 @@ class SkSVGDashArray { Type type() const { return fType; } - const SkTDArray& dashArray() const { return fDashArray; } + const std::vector& dashArray() const { return fDashArray; } private: Type fType; - SkTDArray fDashArray; + std::vector fDashArray; }; class SkSVGStopColor { @@ -673,7 +674,7 @@ enum class SkSVGFeColorMatrixType { kLuminanceToAlpha, }; -using SkSVGFeColorMatrixValues = SkTDArray; +using SkSVGFeColorMatrixValues = std::vector; enum class SkSVGFeCompositeOperator { kOver, diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h index eb1977feb356e..d03afa6d9fa98 100644 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h @@ -12,7 +12,7 @@ #include "include/core/SkMatrix.h" #include "include/core/SkPath.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/svg/include/SkSVGTypes.h" class SkSVGValue : public SkNoncopyable { diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h deleted file mode 100644 index 50429d500f25c..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkLRUCache_DEFINED -#define SkLRUCache_DEFINED - -#include "include/private/SkChecksum.h" -#include "include/private/SkTHash.h" -#include "src/core/SkTInternalLList.h" - -/** - * A generic LRU cache. - */ -template -class SkLRUCache : public SkNoncopyable { -private: - struct Entry { - Entry(const K& key, V&& value) - : fKey(key) - , fValue(std::move(value)) {} - - K fKey; - V fValue; - - SK_DECLARE_INTERNAL_LLIST_INTERFACE(Entry); - }; - -public: - explicit SkLRUCache(int maxCount) - : fMaxCount(maxCount) {} - - ~SkLRUCache() { - Entry* node = fLRU.head(); - while (node) { - fLRU.remove(node); - delete node; - node = fLRU.head(); - } - } - - V* find(const K& key) { - Entry** value = fMap.find(key); - if (!value) { - return nullptr; - } - Entry* entry = *value; - if (entry != fLRU.head()) { - fLRU.remove(entry); - fLRU.addToHead(entry); - } // else it's already at head position, don't need to do anything - return &entry->fValue; - } - - V* insert(const K& key, V value) { - SkASSERT(!this->find(key)); - - Entry* entry = new Entry(key, std::move(value)); - fMap.set(entry); - fLRU.addToHead(entry); - while (fMap.count() > fMaxCount) { - this->remove(fLRU.tail()->fKey); - } - return &entry->fValue; - } - - V* insert_or_update(const K& key, V value) { - if (V* found = this->find(key)) { - *found = std::move(value); - return found; - } else { - return this->insert(key, std::move(value)); - } - } - - int count() { - return fMap.count(); - } - - template // f(K*, V*) - void foreach(Fn&& fn) { - typename SkTInternalLList::Iter iter; - for (Entry* e = iter.init(fLRU, SkTInternalLList::Iter::kHead_IterStart); e; - e = iter.next()) { - fn(&e->fKey, &e->fValue); - } - } - - void reset() { - fMap.reset(); - for (Entry* e = fLRU.head(); e; e = fLRU.head()) { - fLRU.remove(e); - delete e; - } - } - -private: - struct Traits { - static const K& GetKey(Entry* e) { - return e->fKey; - } - - static uint32_t Hash(const K& k) { - return HashK()(k); - } - }; - - void remove(const K& key) { - Entry** value = fMap.find(key); - SkASSERT(value); - Entry* entry = *value; - SkASSERT(key == entry->fKey); - fMap.remove(key); - fLRU.remove(entry); - delete entry; - } - - int fMaxCount; - SkTHashTable fMap; - SkTInternalLList fLRU; -}; - -#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h similarity index 89% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h rename to ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h index 7fe6d33c70c84..e72483b501df1 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h +++ b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h @@ -10,13 +10,15 @@ #include "include/core/SkTypes.h" #include "include/private/SkChecksum.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include #include #include -// Before trying to use SkTHashTable, look below to see if SkTHashMap or SkTHashSet works for you. +namespace skia_private { + +// Before trying to use THashTable, look below to see if THashMap or THashSet works for you. // They're easier to use, usually perform the same, and have fewer sharp edges. // T and K are treated as ordinary copyable C++ types. @@ -26,15 +28,15 @@ // If the key is large and stored inside T, you may want to make K a const&. // Similarly, if T is large you might want it to be a pointer. template -class SkTHashTable { +class THashTable { public: - SkTHashTable() = default; - ~SkTHashTable() = default; + THashTable() = default; + ~THashTable() = default; - SkTHashTable(const SkTHashTable& that) { *this = that; } - SkTHashTable( SkTHashTable&& that) { *this = std::move(that); } + THashTable(const THashTable& that) { *this = that; } + THashTable( THashTable&& that) { *this = std::move(that); } - SkTHashTable& operator=(const SkTHashTable& that) { + THashTable& operator=(const THashTable& that) { if (this != &that) { fCount = that.fCount; fCapacity = that.fCapacity; @@ -46,7 +48,7 @@ class SkTHashTable { return *this; } - SkTHashTable& operator=(SkTHashTable&& that) { + THashTable& operator=(THashTable&& that) { if (this != &that) { fCount = that.fCount; fCapacity = that.fCapacity; @@ -58,7 +60,7 @@ class SkTHashTable { } // Clear the table. - void reset() { *this = SkTHashTable(); } + void reset() { *this = THashTable(); } // How many entries are in the table? int count() const { return fCount; } @@ -75,7 +77,7 @@ class SkTHashTable { // If you change an entry so that it no longer has the same key, all hell // will break loose. Do not do that! // - // Please prefer to use SkTHashMap or SkTHashSet, which do not have this danger. + // Please prefer to use THashMap or THashSet, which do not have this danger. // The pointers returned by set() and find() are valid only until the next call to set(). // The pointers you receive in foreach() are only valid for its duration. @@ -103,7 +105,7 @@ class SkTHashTable { } index = this->next(index); } - SkASSERT(fCapacity == 0); + SkASSERT(fCapacity == fCount); return nullptr; } @@ -145,8 +147,8 @@ class SkTHashTable { fCount = 0; fCapacity = capacity; - SkAutoTArray oldSlots = std::move(fSlots); - fSlots = SkAutoTArray(capacity); + AutoTArray oldSlots = std::move(fSlots); + fSlots = AutoTArray(capacity); for (int i = 0; i < oldCapacity; i++) { Slot& s = oldSlots[i]; @@ -178,12 +180,12 @@ class SkTHashTable { } // A basic iterator-like class which disallows mutation; sufficient for range-based for loops. - // Intended for use by SkTHashMap and SkTHashSet via begin() and end(). + // Intended for use by THashMap and THashSet via begin() and end(). // Adding or removing elements may invalidate all iterators. template class Iter { public: - using TTable = SkTHashTable; + using TTable = THashTable; Iter(const TTable* table, int slot) : fTable(table), fSlot(slot) {} @@ -411,22 +413,22 @@ class SkTHashTable { int fCount = 0, fCapacity = 0; - SkAutoTArray fSlots; + AutoTArray fSlots; }; -// Maps K->V. A more user-friendly wrapper around SkTHashTable, suitable for most use cases. +// Maps K->V. A more user-friendly wrapper around THashTable, suitable for most use cases. // K and V are treated as ordinary copyable C++ types, with no assumed relationship between the two. template -class SkTHashMap { +class THashMap { public: // Allow default construction and assignment. - SkTHashMap() = default; + THashMap() = default; - SkTHashMap(SkTHashMap&& that) = default; - SkTHashMap(const SkTHashMap& that) = default; + THashMap(THashMap&& that) = default; + THashMap(const THashMap& that) = default; - SkTHashMap& operator=(SkTHashMap&& that) = default; - SkTHashMap& operator=(const SkTHashMap& that) = default; + THashMap& operator=(THashMap&& that) = default; + THashMap& operator=(const THashMap& that) = default; // Construct with an initializer list of key-value pairs. struct Pair : public std::pair { @@ -435,7 +437,7 @@ class SkTHashMap { static auto Hash(const K& key) { return HashK()(key); } }; - SkTHashMap(std::initializer_list pairs) { + THashMap(std::initializer_list pairs) { fTable.resize(pairs.size() * 5 / 3); for (const Pair& p : pairs) { fTable.set(p); @@ -498,7 +500,7 @@ class SkTHashMap { } // Dereferencing an iterator gives back a key-value pair, suitable for structured binding. - using Iter = typename SkTHashTable::template Iter>; + using Iter = typename THashTable::template Iter>; Iter begin() const { return Iter::MakeBegin(&fTable); @@ -509,24 +511,24 @@ class SkTHashMap { } private: - SkTHashTable fTable; + THashTable fTable; }; // A set of T. T is treated as an ordinary copyable C++ type. template -class SkTHashSet { +class THashSet { public: // Allow default construction and assignment. - SkTHashSet() = default; + THashSet() = default; - SkTHashSet(SkTHashSet&& that) = default; - SkTHashSet(const SkTHashSet& that) = default; + THashSet(THashSet&& that) = default; + THashSet(const THashSet& that) = default; - SkTHashSet& operator=(SkTHashSet&& that) = default; - SkTHashSet& operator=(const SkTHashSet& that) = default; + THashSet& operator=(THashSet&& that) = default; + THashSet& operator=(const THashSet& that) = default; // Construct with an initializer list of Ts. - SkTHashSet(std::initializer_list vals) { + THashSet(std::initializer_list vals) { fTable.resize(vals.size() * 5 / 3); for (const T& val : vals) { fTable.set(val); @@ -574,7 +576,7 @@ class SkTHashSet { }; public: - using Iter = typename SkTHashTable::template Iter; + using Iter = typename THashTable::template Iter; Iter begin() const { return Iter::MakeBegin(&fTable); @@ -585,7 +587,9 @@ class SkTHashSet { } private: - SkTHashTable fTable; + THashTable fTable; }; -#endif//SkTHash_DEFINED +} // namespace skia_private + +#endif // SkTHash_DEFINED diff --git a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h b/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h deleted file mode 100644 index a5cb615556e56..0000000000000 --- a/ios/vendored/sdk48/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkTInternalLList_DEFINED -#define SkTInternalLList_DEFINED - -#include "include/core/SkTypes.h" - -/** - * This macro creates the member variables required by the SkTInternalLList class. It should be - * placed in the private section of any class that will be stored in a double linked list. - */ -#define SK_DECLARE_INTERNAL_LLIST_INTERFACE(ClassName) \ - friend class SkTInternalLList; \ - /* back pointer to the owning list - for debugging */ \ - SkDEBUGCODE(SkTInternalLList* fList = nullptr;) \ - ClassName* fPrev = nullptr; \ - ClassName* fNext = nullptr - -/** - * This class implements a templated internal doubly linked list data structure. - */ -template class SkTInternalLList { -public: - SkTInternalLList() {} - - void reset() { - fHead = nullptr; - fTail = nullptr; - } - - void remove(T* entry) { - SkASSERT(fHead && fTail); - SkASSERT(this->isInList(entry)); - - T* prev = entry->fPrev; - T* next = entry->fNext; - - if (prev) { - prev->fNext = next; - } else { - fHead = next; - } - if (next) { - next->fPrev = prev; - } else { - fTail = prev; - } - - entry->fPrev = nullptr; - entry->fNext = nullptr; - -#ifdef SK_DEBUG - entry->fList = nullptr; -#endif - } - - void addToHead(T* entry) { - SkASSERT(nullptr == entry->fPrev && nullptr == entry->fNext); - SkASSERT(nullptr == entry->fList); - - entry->fPrev = nullptr; - entry->fNext = fHead; - if (fHead) { - fHead->fPrev = entry; - } - fHead = entry; - if (nullptr == fTail) { - fTail = entry; - } - -#ifdef SK_DEBUG - entry->fList = this; -#endif - } - - void addToTail(T* entry) { - SkASSERT(nullptr == entry->fPrev && nullptr == entry->fNext); - SkASSERT(nullptr == entry->fList); - - entry->fPrev = fTail; - entry->fNext = nullptr; - if (fTail) { - fTail->fNext = entry; - } - fTail = entry; - if (nullptr == fHead) { - fHead = entry; - } - -#ifdef SK_DEBUG - entry->fList = this; -#endif - } - - /** - * Inserts a new list entry before an existing list entry. The new entry must not already be - * a member of this or any other list. If existingEntry is NULL then the new entry is added - * at the tail. - */ - void addBefore(T* newEntry, T* existingEntry) { - SkASSERT(newEntry); - - if (nullptr == existingEntry) { - this->addToTail(newEntry); - return; - } - - SkASSERT(this->isInList(existingEntry)); - newEntry->fNext = existingEntry; - T* prev = existingEntry->fPrev; - existingEntry->fPrev = newEntry; - newEntry->fPrev = prev; - if (nullptr == prev) { - SkASSERT(fHead == existingEntry); - fHead = newEntry; - } else { - prev->fNext = newEntry; - } -#ifdef SK_DEBUG - newEntry->fList = this; -#endif - } - - /** - * Inserts a new list entry after an existing list entry. The new entry must not already be - * a member of this or any other list. If existingEntry is NULL then the new entry is added - * at the head. - */ - void addAfter(T* newEntry, T* existingEntry) { - SkASSERT(newEntry); - - if (nullptr == existingEntry) { - this->addToHead(newEntry); - return; - } - - SkASSERT(this->isInList(existingEntry)); - newEntry->fPrev = existingEntry; - T* next = existingEntry->fNext; - existingEntry->fNext = newEntry; - newEntry->fNext = next; - if (nullptr == next) { - SkASSERT(fTail == existingEntry); - fTail = newEntry; - } else { - next->fPrev = newEntry; - } -#ifdef SK_DEBUG - newEntry->fList = this; -#endif - } - - void concat(SkTInternalLList&& list) { - if (list.isEmpty()) { - return; - } - - list.fHead->fPrev = fTail; - if (!fHead) { - SkASSERT(!list.fHead->fPrev); - fHead = list.fHead; - } else { - SkASSERT(fTail); - fTail->fNext = list.fHead; - } - fTail = list.fTail; - -#ifdef SK_DEBUG - for (T* node = list.fHead; node; node = node->fNext) { - SkASSERT(node->fList == &list); - node->fList = this; - } -#endif - - list.fHead = list.fTail = nullptr; - } - - bool isEmpty() const { - SkASSERT(SkToBool(fHead) == SkToBool(fTail)); - return !fHead; - } - - T* head() const { return fHead; } - T* tail() const { return fTail; } - - class Iter { - public: - enum IterStart { - kHead_IterStart, - kTail_IterStart - }; - - Iter() : fCurr(nullptr) {} - Iter(const Iter& iter) : fCurr(iter.fCurr) {} - Iter& operator= (const Iter& iter) { fCurr = iter.fCurr; return *this; } - - T* init(const SkTInternalLList& list, IterStart startLoc) { - if (kHead_IterStart == startLoc) { - fCurr = list.fHead; - } else { - SkASSERT(kTail_IterStart == startLoc); - fCurr = list.fTail; - } - - return fCurr; - } - - T* get() { return fCurr; } - - /** - * Return the next/previous element in the list or NULL if at the end. - */ - T* next() { - if (nullptr == fCurr) { - return nullptr; - } - - fCurr = fCurr->fNext; - return fCurr; - } - - T* prev() { - if (nullptr == fCurr) { - return nullptr; - } - - fCurr = fCurr->fPrev; - return fCurr; - } - - /** - * C++11 range-for interface. - */ - bool operator!=(const Iter& that) { return fCurr != that.fCurr; } - T* operator*() { return this->get(); } - void operator++() { this->next(); } - - private: - T* fCurr; - }; - - Iter begin() const { - Iter iter; - iter.init(*this, Iter::kHead_IterStart); - return iter; - } - - Iter end() const { return Iter(); } - -#ifdef SK_DEBUG - void validate() const { - SkASSERT(!fHead == !fTail); - Iter iter; - for (T* item = iter.init(*this, Iter::kHead_IterStart); item; item = iter.next()) { - SkASSERT(this->isInList(item)); - if (nullptr == item->fPrev) { - SkASSERT(fHead == item); - } else { - SkASSERT(item->fPrev->fNext == item); - } - if (nullptr == item->fNext) { - SkASSERT(fTail == item); - } else { - SkASSERT(item->fNext->fPrev == item); - } - } - } - - /** - * Debugging-only method that uses the list back pointer to check if 'entry' is indeed in 'this' - * list. - */ - bool isInList(const T* entry) const { - return entry->fList == this; - } - - /** - * Debugging-only method that laboriously counts the list entries. - */ - int countEntries() const { - int count = 0; - for (T* entry = fHead; entry; entry = entry->fNext) { - ++count; - } - return count; - } -#endif // SK_DEBUG - -private: - T* fHead = nullptr; - T* fTail = nullptr; - - SkTInternalLList(const SkTInternalLList&) = delete; - SkTInternalLList& operator=(const SkTInternalLList&) = delete; -}; - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkColorFilter.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkColorFilter.h index d5c3a361ef5d9..06410738e20ab 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkColorFilter.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkColorFilter.h @@ -23,23 +23,8 @@ class JsiSkColorFilter : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(colorFilter)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "ColorFilter"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkColorFilter, - __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkColorFilter, "ColorFilter") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkColorFilter, dispose)) }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasure.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasure.h index 36331765e1266..3dff4ebdd856c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasure.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasure.h @@ -68,26 +68,12 @@ class JsiSkContourMeasure return JsiSkPath::toValue(runtime, getContext(), std::move(path)); } - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "ContourMeasure"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkContourMeasure, - __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkContourMeasure, "ContourMeasure") JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkContourMeasure, getPosTan), JSI_EXPORT_FUNC(JsiSkContourMeasure, length), JSI_EXPORT_FUNC(JsiSkContourMeasure, isClosed), - JSI_EXPORT_FUNC(JsiSkContourMeasure, getSegment)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + JSI_EXPORT_FUNC(JsiSkContourMeasure, getSegment), + JSI_EXPORT_FUNC(JsiSkContourMeasure, dispose)) }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasureIter.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasureIter.h index c945a3e3b0a8a..8ea8d7cd1da24 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasureIter.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkContourMeasureIter.h @@ -29,14 +29,6 @@ class JsiSkContourMeasureIter std::move(context), std::make_shared( path, forceClosed, resScale)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "ContourMeasureIter"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkContourMeasureIter, - __typename__), ) - JSI_HOST_FUNCTION(next) { auto next = getObject()->next(); if (next == nullptr) { @@ -48,17 +40,10 @@ class JsiSkContourMeasureIter return jsi::Object::createFromHostObject(runtime, std::move(nextObject)); } - JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkContourMeasureIter, next)) + EXPORT_JSI_API_TYPENAME(JsiSkContourMeasureIter, "ContourMeasureIter") - /** - Returns the underlying object from a host object of this type - */ - static std::shared_ptr - fromValue(jsi::Runtime &runtime, const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkContourMeasureIter, next), + JSI_EXPORT_FUNC(JsiSkContourMeasureIter, dispose)) /** * Creates the function for construction a new instance of the diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkData.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkData.h index b791c300d13a7..3e24df5119f45 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkData.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkData.h @@ -24,17 +24,7 @@ class JsiSkData : public JsiSkWrappingSkPtrHostObject { JsiSkData(std::shared_ptr context, sk_sp asset) : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(asset)) {} - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Data"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkData, __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, const jsi::Value &obj) { - return obj.asObject(runtime).asHostObject(runtime)->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkData, "Data") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkData, dispose)) }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkFont.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkFont.h index 4cb11c6003951..917791ee90538 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkFont.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkFont.h @@ -6,7 +6,7 @@ #include #include "JsiSkHostObjects.h" -#include +#include "RNSkLog.h" #include #include "JsiSkPaint.h" @@ -28,11 +28,6 @@ namespace jsi = facebook::jsi; class JsiSkFont : public JsiSkWrappingSharedPtrHostObject { public: - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Font"); - } - JSI_HOST_FUNCTION(getGlyphWidths) { auto jsiGlyphs = arguments[0].asObject(runtime).asArray(runtime); std::vector glyphs; @@ -244,6 +239,8 @@ class JsiSkFont : public JsiSkWrappingSharedPtrHostObject { return jsi::Value::undefined(); } + EXPORT_JSI_API_TYPENAME(JsiSkFont, "Font") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFont, getSize), JSI_EXPORT_FUNC(JsiSkFont, getMetrics), JSI_EXPORT_FUNC(JsiSkFont, getGlyphIDs), @@ -262,20 +259,13 @@ class JsiSkFont : public JsiSkWrappingSharedPtrHostObject { JSI_EXPORT_FUNC(JsiSkFont, setSubpixel), JSI_EXPORT_FUNC(JsiSkFont, setTypeface), JSI_EXPORT_FUNC(JsiSkFont, getGlyphWidths), - JSI_EXPORT_FUNC(JsiSkFont, getTextWidth)) + JSI_EXPORT_FUNC(JsiSkFont, getTextWidth), + JSI_EXPORT_FUNC(JsiSkFont, dispose)) JsiSkFont(std::shared_ptr context, const SkFont &font) : JsiSkWrappingSharedPtrHostObject(std::move(context), std::make_shared(font)) {} - /** - Returns the underlying object from a host object of this type - */ - static std::shared_ptr fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime).asHostObject(runtime)->getObject(); - } - /** * Creates the function for construction a new instance of the SkFont * wrapper diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkHostObjects.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkHostObjects.h index 660761d8583e1..68410f9c45bbc 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkHostObjects.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkHostObjects.h @@ -3,15 +3,16 @@ #include #include +#include "JsiHostObject.h" #include "RNSkPlatformContext.h" -#include namespace RNSkia { namespace jsi = facebook::jsi; /** - * Base class for jsi host objects + * Base class for jsi host objects - these are all implemented as JsiHostObjects + * and has a pointer to the platform context. */ class JsiSkHostObject : public RNJsi::JsiHostObject { public: @@ -32,6 +33,15 @@ class JsiSkHostObject : public RNJsi::JsiHostObject { std::shared_ptr _context; }; +#define JSI_API_TYPENAME(A) \ + JSI_PROPERTY_GET(__typename__) { \ + return jsi::String::createFromUtf8(runtime, #A); \ + } + +#define EXPORT_JSI_API_TYPENAME(CLASS, TYPENAME) \ + JSI_API_TYPENAME(TYPENAME) \ + JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(CLASS, __typename__)) + template class JsiSkWrappingHostObject : public JsiSkHostObject { public: /** @@ -39,32 +49,65 @@ template class JsiSkWrappingHostObject : public JsiSkHostObject { * @param context Platform context */ JsiSkWrappingHostObject(std::shared_ptr context, - T &&object) + T object) : JsiSkHostObject(std::move(context)), _object(std::move(object)) {} - JsiSkWrappingHostObject(std::shared_ptr context, - const T &object) - : JsiSkHostObject(std::move(context)), _object(object) {} - /** * Returns the underlying object exposed by this host object. This object * should be wrapped in a shared pointer of some kind * @return Underlying object */ - T &getObject() { return _object; } - const T &getObject() const { return _object; } + T getObject() { return _object; } + const T getObject() const { return _object; } /** Updates the inner object with a new version of the object. */ - void setObject(T &object) { _object = object; } - void setObject(const T &object) { _object = object; } + void setObject(T object) { _object = object; } + + /** + Dispose function that can be exposed to JS by using the JSI_API_TYPENAME + macro + */ + JSI_HOST_FUNCTION(dispose) { + safeDispose(); + return jsi::Value::undefined(); + } + +protected: + /** + Override to implement disposale of allocated resources like smart pointers + etc. This method will only be called once for each instance of this class. + */ + virtual void releaseResources() = 0; + + /** + Throws a runtime error if this method is called after the object has been + disposed. + */ + void ensureNotDisposed() { + if (_isDisposed) { + throw std::runtime_error("API Object accessed after it was disposed"); + } + } private: + void safeDispose() { + if (!_isDisposed) { + _isDisposed = true; + releaseResources(); + } + } + /** * Wrapped object */ T _object; + + /** + Resource disposed flag + */ + std::atomic _isDisposed = {false}; }; template @@ -75,6 +118,22 @@ class JsiSkWrappingSharedPtrHostObject std::shared_ptr object) : JsiSkWrappingHostObject>(std::move(context), std::move(object)) {} + + /** + Returns the underlying object from a host object of this type + */ + static std::shared_ptr fromValue(jsi::Runtime &runtime, + const jsi::Value &obj) { + return std::static_pointer_cast( + obj.asObject(runtime).asHostObject(runtime)) + ->getObject(); + } + +protected: + void releaseResources() override { + // Clear internally allocated objects + this->setObject(nullptr); + } }; template @@ -84,5 +143,21 @@ class JsiSkWrappingSkPtrHostObject : public JsiSkWrappingHostObject> { sk_sp object) : JsiSkWrappingHostObject>(std::move(context), std::move(object)) {} + + /** + Returns the underlying object from a host object of this type + */ + static sk_sp fromValue(jsi::Runtime &runtime, const jsi::Value &obj) { + return std::static_pointer_cast( + obj.asObject(runtime).asHostObject(runtime)) + ->getObject(); + } + +protected: + void releaseResources() override { + // Clear internally allocated objects + this->setObject(nullptr); + } }; + } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImage.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImage.h index e60245b60f14f..9591906ef160b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImage.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImage.h @@ -4,9 +4,9 @@ #include #include +#include "JsiSkHostObjects.h" #include "JsiSkMatrix.h" #include "JsiSkShader.h" -#include #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -14,7 +14,9 @@ #include "SkBase64.h" #include "SkImage.h" #include "SkStream.h" -#include +#include "codec/SkEncodedImageFormat.h" +#include "include/encode/SkJpegEncoder.h" +#include "include/encode/SkPngEncoder.h" #pragma clang diagnostic pop @@ -70,7 +72,15 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject { auto quality = count == 2 ? arguments[1].asNumber() : 100.0; // Get data - auto data = getObject()->encodeToData(format, quality); + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, getObject().get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, getObject().get(), options); + } auto arrayCtor = runtime.global().getPropertyAsFunction(runtime, "Uint8Array"); size_t size = data->size(); @@ -95,8 +105,19 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject { : SkEncodedImageFormat::kPNG; auto quality = count == 2 ? arguments[1].asNumber() : 100.0; - - auto data = getObject()->encodeToData(format, quality); + auto image = getObject(); + if (image->isTextureBacked()) { + image = image->makeNonTextureImage(); + } + sk_sp data; + if (format == SkEncodedImageFormat::kJPEG) { + SkJpegEncoder::Options options; + options.fQuality = quality; + data = SkJpegEncoder::Encode(nullptr, image.get(), options); + } else { + SkPngEncoder::Options options; + data = SkPngEncoder::Encode(nullptr, image.get(), options); + } auto len = SkBase64::Encode(data->bytes(), data->size(), nullptr); auto buffer = std::string(len, 0); SkBase64::Encode(data->bytes(), data->size(), @@ -104,25 +125,27 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject { return jsi::String::createFromAscii(runtime, buffer); } + JSI_HOST_FUNCTION(makeNonTextureImage) { + auto image = getObject()->makeNonTextureImage(); + return jsi::Object::createFromHostObject( + runtime, std::make_shared(getContext(), std::move(image))); + } + + EXPORT_JSI_API_TYPENAME(JsiSkImage, "Image") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkImage, width), JSI_EXPORT_FUNC(JsiSkImage, height), JSI_EXPORT_FUNC(JsiSkImage, makeShaderOptions), JSI_EXPORT_FUNC(JsiSkImage, makeShaderCubic), JSI_EXPORT_FUNC(JsiSkImage, encodeToBytes), - JSI_EXPORT_FUNC(JsiSkImage, encodeToBase64)) + JSI_EXPORT_FUNC(JsiSkImage, encodeToBase64), + JSI_EXPORT_FUNC(JsiSkImage, makeNonTextureImage), + JSI_EXPORT_FUNC(JsiSkImage, dispose)) JsiSkImage(std::shared_ptr context, const sk_sp image) : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(image)) {} - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime).asHostObject(runtime)->getObject(); - } }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h index ab2756be3de52..2ccb32af0d626 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFactory.h @@ -18,7 +18,7 @@ class JsiSkImageFactory : public JsiSkHostObject { public: JSI_HOST_FUNCTION(MakeImageFromEncoded) { auto data = JsiSkData::fromValue(runtime, arguments[0]); - auto image = SkImage::MakeFromEncoded(data); + auto image = SkImages::DeferredFromEncodedData(data); if (image == nullptr) { return jsi::Value::null(); } @@ -30,7 +30,7 @@ class JsiSkImageFactory : public JsiSkHostObject { auto imageInfo = JsiSkImageInfo::fromValue(runtime, arguments[0]); auto pixelData = JsiSkData::fromValue(runtime, arguments[1]); auto bytesPerRow = arguments[2].asNumber(); - auto image = SkImage::MakeRasterData(*imageInfo, pixelData, bytesPerRow); + auto image = SkImages::RasterFromData(*imageInfo, pixelData, bytesPerRow); if (image == nullptr) { return jsi::Value::null(); } @@ -38,7 +38,36 @@ class JsiSkImageFactory : public JsiSkHostObject { runtime, std::make_shared(getContext(), std::move(image))); } + JSI_HOST_FUNCTION(MakeImageFromViewTag) { + auto viewTag = arguments[0].asNumber(); + auto context = getContext(); + return react::createPromiseAsJSIValue( + runtime, + [context = std::move(context), + viewTag](jsi::Runtime &runtime, + std::shared_ptr promise) -> void { + // Create a stream operation - this will be run on the main thread + context->makeViewScreenshot( + viewTag, [&runtime, context = std::move(context), + promise = std::move(promise)](sk_sp image) { + context->runOnJavascriptThread([&runtime, + context = std::move(context), + promise = std::move(promise), + result = std::move(image)]() { + if (result == nullptr) { + promise->reject("Failed to create image from view tag"); + return; + } + promise->resolve(jsi::Object::createFromHostObject( + runtime, std::make_shared( + std::move(context), std::move(result)))); + }); + }); + }); + } + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkImageFactory, MakeImageFromEncoded), + JSI_EXPORT_FUNC(JsiSkImageFactory, MakeImageFromViewTag), JSI_EXPORT_FUNC(JsiSkImageFactory, MakeImage), ) explicit JsiSkImageFactory(std::shared_ptr context) diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFilter.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFilter.h index c70fe83c7eb79..1969add100b75 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFilter.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkImageFilter.h @@ -25,23 +25,7 @@ class JsiSkImageFilter : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(imageFilter)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "ImageFilter"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkImageFilter, - __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkImageFilter, "ImageFilter") }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMaskFilter.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMaskFilter.h index b382da6b909c0..664193d3ee83d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMaskFilter.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMaskFilter.h @@ -25,23 +25,7 @@ class JsiSkMaskFilter : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(maskFilter)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "MaskFilter"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkMaskFilter, - __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkMaskFilter, "MaskFilter") }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMatrix.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMatrix.h index ad17c1ea57949..262ab87da54aa 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMatrix.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkMatrix.h @@ -40,46 +40,42 @@ class JsiSkMatrix : public JsiSkWrappingSharedPtrHostObject { pers0, pers1, pers2); } - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Matrix"); - } - JSI_HOST_FUNCTION(concat) { auto m3 = JsiSkMatrix::fromValue(runtime, arguments[0]); getObject()->preConcat(*m3); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(translate) { auto x = arguments[0].asNumber(); auto y = arguments[1].asNumber(); getObject()->preTranslate(x, y); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(scale) { auto x = arguments[0].asNumber(); auto y = count > 1 ? arguments[1].asNumber() : 1; getObject()->preScale(x, y); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(skew) { auto x = arguments[0].asNumber(); auto y = arguments[1].asNumber(); getObject()->preSkew(x, y); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(rotate) { auto a = arguments[0].asNumber(); getObject()->preRotate(SkRadiansToDegrees(a)); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(identity) { getObject()->setIdentity(); - return jsi::Value::undefined(); + return thisValue.asObject(runtime); } JSI_HOST_FUNCTION(get) { @@ -90,7 +86,7 @@ class JsiSkMatrix : public JsiSkWrappingSharedPtrHostObject { return values; } - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkMatrix, __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkMatrix, "Matrix") JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkMatrix, concat), JSI_EXPORT_FUNC(JsiSkMatrix, translate), @@ -98,7 +94,8 @@ class JsiSkMatrix : public JsiSkWrappingSharedPtrHostObject { JSI_EXPORT_FUNC(JsiSkMatrix, skew), JSI_EXPORT_FUNC(JsiSkMatrix, rotate), JSI_EXPORT_FUNC(JsiSkMatrix, identity), - JSI_EXPORT_FUNC(JsiSkMatrix, get), ) + JSI_EXPORT_FUNC(JsiSkMatrix, get), + JSI_EXPORT_FUNC(JsiSkMatrix, dispose)) /** * Returns the underlying object from a host object of this type diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPaint.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPaint.h index 46f2a051afb4e..fdf54033f5f44 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPaint.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPaint.h @@ -5,13 +5,13 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "JsiSkColor.h" +#include "JsiSkColorFilter.h" +#include "JsiSkHostObjects.h" +#include "JsiSkImageFilter.h" +#include "JsiSkMaskFilter.h" +#include "JsiSkPathEffect.h" +#include "JsiSkShader.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -25,12 +25,7 @@ namespace jsi = facebook::jsi; class JsiSkPaint : public JsiSkWrappingSharedPtrHostObject { public: - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Paint"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkPaint, __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkPaint, "Paint") JSI_HOST_FUNCTION(copy) { const auto *paint = getObject().get(); @@ -183,7 +178,8 @@ class JsiSkPaint : public JsiSkWrappingSharedPtrHostObject { JSI_EXPORT_FUNC(JsiSkPaint, setStrokeWidth), JSI_EXPORT_FUNC(JsiSkPaint, setStyle), JSI_EXPORT_FUNC(JsiSkPaint, setColor), - JSI_EXPORT_FUNC(JsiSkPaint, setAlphaf)) + JSI_EXPORT_FUNC(JsiSkPaint, setAlphaf), + JSI_EXPORT_FUNC(JsiSkPaint, dispose)) JsiSkPaint(std::shared_ptr context, SkPaint paint) : JsiSkWrappingSharedPtrHostObject( @@ -196,14 +192,6 @@ class JsiSkPaint : public JsiSkWrappingSharedPtrHostObject { setObject(std::make_shared(std::move(paint))); } - /** - Returns the underlying object from a host object of this type - */ - static std::shared_ptr fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime).asHostObject(runtime)->getObject(); - } - /** * Creates the function for construction a new instance of the SkPaint * wrapper diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPath.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPath.h index f6f6daec9e77f..7938ca885f383 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPath.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPath.h @@ -7,6 +7,7 @@ #include #include "JsiSkHostObjects.h" +#include "JsiSkMatrix.h" #include "JsiSkPoint.h" #include "JsiSkRRect.h" #include "JsiSkRect.h" @@ -20,13 +21,12 @@ #include "SkPathEffect.h" #include "SkPathOps.h" #include "SkPathTypes.h" +#include "SkPathUtils.h" #include "SkString.h" #include "SkStrokeRec.h" #include "SkTextUtils.h" #include "SkTrimPathEffect.h" -#include "JsiSkMatrix.h" - #pragma clang diagnostic pop namespace RNSkia { @@ -36,11 +36,6 @@ namespace jsi = facebook::jsi; class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { public: - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Path"); - } - JSI_HOST_FUNCTION(addPath) { auto src = JsiSkPath::fromValue(runtime, arguments[0]); auto matrix = @@ -289,8 +284,11 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { auto jsiPrecision = opts.getProperty(runtime, "precision"); auto precision = jsiPrecision.isUndefined() ? 1 : jsiPrecision.asNumber(); - auto result = p.getFillPath(path, &path, nullptr, precision); - getObject()->swap(path); + auto result = + skpathutils::FillPathWithPaint(path, p, &path, nullptr, precision); + if (result) { + getObject()->swap(path); + } return result ? thisValue.getObject(runtime) : jsi::Value::null(); } @@ -325,8 +323,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { JSI_HOST_FUNCTION(toSVGString) { SkPath path = *getObject(); - SkString s; - SkParsePath::ToSVGString(path, &s); + auto s = SkParsePath::ToSVGString(path); return jsi::String::createFromUtf8(runtime, s.c_str()); } @@ -526,7 +523,7 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { return cmds; } - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkPath, __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkPath, "Path") JSI_EXPORT_FUNCTIONS( JSI_EXPORT_FUNC(JsiSkPath, addPath), JSI_EXPORT_FUNC(JsiSkPath, addArc), @@ -562,20 +559,12 @@ class JsiSkPath : public JsiSkWrappingSharedPtrHostObject { JSI_EXPORT_FUNC(JsiSkPath, op), JSI_EXPORT_FUNC(JsiSkPath, isInterpolatable), JSI_EXPORT_FUNC(JsiSkPath, interpolate), - JSI_EXPORT_FUNC(JsiSkPath, toCmds), ) + JSI_EXPORT_FUNC(JsiSkPath, toCmds), JSI_EXPORT_FUNC(JsiSkPath, dispose)) JsiSkPath(std::shared_ptr context, SkPath path) : JsiSkWrappingSharedPtrHostObject( std::move(context), std::make_shared(std::move(path))) {} - /** - Returns the underlying object from a host object of this type - */ - static std::shared_ptr fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime).asHostObject(runtime)->getObject(); - } - static jsi::Value toValue(jsi::Runtime &runtime, std::shared_ptr context, const SkPath &path) { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathEffect.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathEffect.h index 3e410db89c571..925dd46441946 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathEffect.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathEffect.h @@ -25,23 +25,8 @@ class JsiSkPathEffect : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(pathEffect)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "PathEffect"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkPathEffect, - __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkPathEffect, "PathEffect") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkColorFilter, dispose)) }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathFactory.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathFactory.h index d7bccf42f8892..143ef95bffaa4 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathFactory.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPathFactory.h @@ -11,9 +11,9 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" +#include "RNSkLog.h" #include "SkPath.h" #include "SkPathOps.h" -#include #pragma clang diagnostic pop diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPicture.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPicture.h index a38383e1ef637..1c375e0fe53c9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPicture.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPicture.h @@ -2,9 +2,9 @@ #include +#include "JsiSkData.h" #include "JsiSkHostObjects.h" -#include -#include +#include "JsiSkShader.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -23,12 +23,6 @@ class JsiSkPicture : public JsiSkWrappingSkPtrHostObject { const sk_sp picture) : JsiSkWrappingSkPtrHostObject(context, picture) {} - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Picture"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkPicture, __typename__)) - JSI_HOST_FUNCTION(makeShader) { auto tmx = (SkTileMode)arguments[0].asNumber(); auto tmy = (SkTileMode)arguments[1].asNumber(); @@ -66,18 +60,10 @@ class JsiSkPicture : public JsiSkWrappingSkPtrHostObject { return array; } + EXPORT_JSI_API_TYPENAME(JsiSkPicture, "Picture") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPicture, makeShader), - JSI_EXPORT_FUNC(JsiSkPicture, serialize)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - .get() - ->getObject(); - } + JSI_EXPORT_FUNC(JsiSkPicture, serialize), + JSI_EXPORT_FUNC(JsiSkPicture, dispose)) }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPictureRecorder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPictureRecorder.h index c8561127261a0..fc8601020595f 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPictureRecorder.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPictureRecorder.h @@ -40,9 +40,12 @@ class JsiSkPictureRecorder runtime, std::make_shared(getContext(), picture)); } + EXPORT_JSI_API_TYPENAME(JsiSkPictureRecorder, "PictureRecorder") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPictureRecorder, beginRecording), JSI_EXPORT_FUNC(JsiSkPictureRecorder, - finishRecordingAsPicture)) + finishRecordingAsPicture), + JSI_EXPORT_FUNC(JsiSkPictureRecorder, dispose)) static const jsi::HostFunctionType createCtor(std::shared_ptr context) { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPoint.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPoint.h index 660f01087e69c..d14593d93992c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPoint.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkPoint.h @@ -24,8 +24,13 @@ class JsiSkPoint : public JsiSkWrappingSharedPtrHostObject { JSI_PROPERTY_GET(y) { return static_cast(getObject()->y()); } + JSI_API_TYPENAME("Point"); + JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkPoint, x), - JSI_EXPORT_PROP_GET(JsiSkPoint, y)) + JSI_EXPORT_PROP_GET(JsiSkPoint, y), + JSI_EXPORT_PROP_GET(JsiSkPoint, __typename__)) + + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkPoint, dispose)) JsiSkPoint(std::shared_ptr context, const SkPoint &point) : JsiSkWrappingSharedPtrHostObject( diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRRect.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRRect.h index 73ac73121350a..b77c48a683592 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRRect.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRRect.h @@ -34,9 +34,14 @@ class JsiSkRRect : public JsiSkWrappingSharedPtrHostObject { std::make_shared(getContext(), getObject()->getBounds())); } + JSI_API_TYPENAME("RRect"); + JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkRRect, rx), JSI_EXPORT_PROP_GET(JsiSkRRect, ry), - JSI_EXPORT_PROP_GET(JsiSkRRect, rect)) + JSI_EXPORT_PROP_GET(JsiSkRRect, rect), + JSI_EXPORT_PROP_GET(JsiSkRRect, __typename__)) + + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRRect, dispose)) JsiSkRRect(std::shared_ptr context, const SkRRect &rect) : JsiSkWrappingSharedPtrHostObject( diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRSXform.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRSXform.h index 5fd43fcb59053..2d4e69092fcc3 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRSXform.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRSXform.h @@ -25,11 +25,7 @@ class JsiSkRSXform : public JsiSkWrappingSharedPtrHostObject { : JsiSkWrappingSharedPtrHostObject( std::move(context), std::make_shared(rsxform)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "RSXform"); - } + JSI_API_TYPENAME("RSXform"); JSI_PROPERTY_GET(scos) { return jsi::Value(SkScalarToDouble(getObject()->fSCos)); @@ -48,7 +44,9 @@ class JsiSkRSXform : public JsiSkWrappingSharedPtrHostObject { JSI_EXPORT_PROP_GET(JsiSkRSXform, scos), JSI_EXPORT_PROP_GET(JsiSkRSXform, ssin), JSI_EXPORT_PROP_GET(JsiSkRSXform, tx), - JSI_EXPORT_PROP_GET(JsiSkRSXform, ty), ) + JSI_EXPORT_PROP_GET(JsiSkRSXform, ty)) + + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRSXform, dispose)) /** Returns the underlying object from a host object of this type diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRect.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRect.h index 2d74f6f554955..c37a042f8db2e 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRect.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRect.h @@ -33,10 +33,13 @@ class JsiSkRect : public JsiSkWrappingSharedPtrHostObject { return static_cast(getObject()->bottom()); } + JSI_API_TYPENAME("Rect"); + JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkRect, x), JSI_EXPORT_PROP_GET(JsiSkRect, y), JSI_EXPORT_PROP_GET(JsiSkRect, width), - JSI_EXPORT_PROP_GET(JsiSkRect, height)) + JSI_EXPORT_PROP_GET(JsiSkRect, height), + JSI_EXPORT_PROP_GET(JsiSkRect, __typename__)) JSI_HOST_FUNCTION(setXYWH) { getObject()->setXYWH(arguments[0].asNumber(), arguments[1].asNumber(), @@ -51,7 +54,8 @@ class JsiSkRect : public JsiSkWrappingSharedPtrHostObject { } JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRect, setXYWH), - JSI_EXPORT_FUNC(JsiSkRect, setLTRB), ) + JSI_EXPORT_FUNC(JsiSkRect, setLTRB), + JSI_EXPORT_FUNC(JsiSkRect, dispose)) /** Constructor diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeEffect.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeEffect.h index 8987d206812a6..698a01a37e3f1 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeEffect.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeEffect.h @@ -5,9 +5,9 @@ #include #include -#include -#include -#include +#include "JsiSkHostObjects.h" +#include "JsiSkMatrix.h" +#include "JsiSkShader.h" #include @@ -32,12 +32,6 @@ struct RuntimeEffectUniform { class JsiSkRuntimeEffect : public JsiSkWrappingSkPtrHostObject { public: - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - const auto &object = obj.asObject(runtime); - return object.asHostObject(runtime)->getObject(); - } - JSI_HOST_FUNCTION(makeShader) { auto uniforms = castUniforms(runtime, arguments[0]); @@ -121,6 +115,8 @@ class JsiSkRuntimeEffect return jsi::String::createFromAscii(runtime, getObject()->source()); } + EXPORT_JSI_API_TYPENAME(JsiSkRuntimeEffect, "RuntimeEffect") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeEffect, makeShader), JSI_EXPORT_FUNC(JsiSkRuntimeEffect, makeShaderWithChildren), @@ -129,7 +125,8 @@ class JsiSkRuntimeEffect getUniformFloatCount), JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformName), JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniform), - JSI_EXPORT_FUNC(JsiSkRuntimeEffect, source)) + JSI_EXPORT_FUNC(JsiSkRuntimeEffect, source), + JSI_EXPORT_FUNC(JsiSkRuntimeEffect, dispose)) JsiSkRuntimeEffect(std::shared_ptr context, sk_sp rt) diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeShaderBuilder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeShaderBuilder.h index d51126b6aa631..99deecdb67f8d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeShaderBuilder.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkRuntimeShaderBuilder.h @@ -47,16 +47,8 @@ class JsiSkRuntimeShaderBuilder return jsi::Value::undefined(); } - JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeShaderBuilder, setUniform)) - - /** - Returns the underlying object from a host object of this type - */ - static std::shared_ptr - fromValue(jsi::Runtime &runtime, const jsi::Value &obj) { - const auto &object = obj.asObject(runtime); - return object.asHostObject(runtime)->getObject(); - } + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeShaderBuilder, setUniform), + JSI_EXPORT_FUNC(JsiSkRuntimeShaderBuilder, dispose)) /** Returns the jsi object from a host object of this type diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSVG.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSVG.h index 1838965f2b826..e715481181b2c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSVG.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSVG.h @@ -5,7 +5,7 @@ #include -#include +#include "JsiSkHostObjects.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -24,11 +24,19 @@ class JsiSkSVG : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(svgdom)) {} - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "SVG"); + EXPORT_JSI_API_TYPENAME(JsiSkSVG, "SVG") + + JSI_HOST_FUNCTION(width) { + return static_cast(getObject()->containerSize().width()); + } + + JSI_HOST_FUNCTION(height) { + return static_cast(getObject()->containerSize().height()); } - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkSVG, __typename__)) + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSVG, width), + JSI_EXPORT_FUNC(JsiSkSVG, height), + JSI_EXPORT_FUNC(JsiSkSVG, dispose)) /** Returns the underlying object from a host object of this type diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkShader.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkShader.h index 2dd3f77746c40..eee6753e9f7bf 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkShader.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkShader.h @@ -5,7 +5,7 @@ #include -#include +#include "JsiSkHostObjects.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -26,21 +26,7 @@ class JsiSkShader : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(shader)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Shader"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkShader, __typename__)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkShader, "Shader") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkShader, dispose)) }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurface.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurface.h index f4ddaf9ab0858..0ea0d1820450b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurface.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurface.h @@ -7,9 +7,9 @@ #include "JsiSkHostObjects.h" -#include -#include -#include +#include "JsiSkCanvas.h" +#include "JsiSkImage.h" +#include "JsiSkSurfaceFactory.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -29,10 +29,7 @@ class JsiSkSurface : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(surface)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Surface"); - } + EXPORT_JSI_API_TYPENAME(JsiSkSurface, "Surface") JSI_HOST_FUNCTION(getCanvas) { return jsi::Object::createFromHostObject( @@ -40,6 +37,11 @@ class JsiSkSurface : public JsiSkWrappingSkPtrHostObject { std::make_shared(getContext(), getObject()->getCanvas())); } + JSI_HOST_FUNCTION(flush) { + getObject()->flush(); + return jsi::Value::undefined(); + } + JSI_HOST_FUNCTION(makeImageSnapshot) { sk_sp image; if (count == 1) { @@ -53,19 +55,10 @@ class JsiSkSurface : public JsiSkWrappingSkPtrHostObject { runtime, std::make_shared(getContext(), std::move(image))); } - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkSurface, __typename__)) JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurface, getCanvas), - JSI_EXPORT_FUNC(JsiSkSurface, makeImageSnapshot)) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + JSI_EXPORT_FUNC(JsiSkSurface, makeImageSnapshot), + JSI_EXPORT_FUNC(JsiSkSurface, flush), + JSI_EXPORT_FUNC(JsiSkSurface, dispose)) }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurfaceFactory.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurfaceFactory.h index e068b6bbc3437..1f83f8b8f0302 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurfaceFactory.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkSurfaceFactory.h @@ -7,12 +7,11 @@ #include "JsiSkHostObjects.h" -#include +#include "JsiSkSurface.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include "SkImage.h" #include "SkSurface.h" #pragma clang diagnostic pop @@ -35,7 +34,21 @@ class JsiSkSurfaceFactory : public JsiSkHostObject { std::make_shared(getContext(), std::move(surface))); } - JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurfaceFactory, Make)) + JSI_HOST_FUNCTION(MakeOffscreen) { + auto width = static_cast(arguments[0].asNumber()); + auto height = static_cast(arguments[1].asNumber()); + auto context = getContext(); + auto surface = context->makeOffscreenSurface(width, height); + if (surface == nullptr) { + return jsi::Value::null(); + } + return jsi::Object::createFromHostObject( + runtime, + std::make_shared(getContext(), std::move(surface))); + } + + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurfaceFactory, Make), + JSI_EXPORT_FUNC(JsiSkSurfaceFactory, MakeOffscreen)) explicit JsiSkSurfaceFactory(std::shared_ptr context) : JsiSkHostObject(std::move(context)) {} diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTextBlob.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTextBlob.h index e4c2f68888b2e..9874f888e9a03 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTextBlob.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTextBlob.h @@ -25,23 +25,7 @@ class JsiSkTextBlob : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(shader)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "TextBlob"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkTextBlob, - __typename__), ) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + EXPORT_JSI_API_TYPENAME(JsiSkTextBlob, "TextBlob") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTextBlob, dispose)) }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTypeface.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTypeface.h index 0e52d7c7a4f25..e043543212edd 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTypeface.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkTypeface.h @@ -6,7 +6,7 @@ #include #include "JsiSkHostObjects.h" -#include +#include "RNSkLog.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -22,27 +22,13 @@ namespace jsi = facebook::jsi; class JsiSkTypeface : public JsiSkWrappingSkPtrHostObject { public: - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Typeface"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkTypeface, __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkTypeface, "Typeface") + JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkTypeface, dispose)) JsiSkTypeface(std::shared_ptr context, sk_sp typeface) : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(typeface)) {} - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } - /** Returns the jsi object from a host object of this type */ diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkVertices.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkVertices.h index e1cf0ba7777fb..8c84a0abcf9b2 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkVertices.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/api/JsiSkVertices.h @@ -25,12 +25,7 @@ class JsiSkVertices : public JsiSkWrappingSkPtrHostObject { : JsiSkWrappingSkPtrHostObject(std::move(context), std::move(vertices)) {} - // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter? - JSI_PROPERTY_GET(__typename__) { - return jsi::String::createFromUtf8(runtime, "Vertices"); - } - - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkVertices, __typename__)) + EXPORT_JSI_API_TYPENAME(JsiSkVertices, "Vertices") JSI_HOST_FUNCTION(bounds) { const auto &result = getObject()->bounds(); @@ -43,17 +38,8 @@ class JsiSkVertices : public JsiSkWrappingSkPtrHostObject { } JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkVertices, bounds), - JSI_EXPORT_FUNC(JsiSkVertices, uniqueID), ) - - /** - Returns the underlying object from a host object of this type - */ - static sk_sp fromValue(jsi::Runtime &runtime, - const jsi::Value &obj) { - return obj.asObject(runtime) - .asHostObject(runtime) - ->getObject(); - } + JSI_EXPORT_FUNC(JsiSkVertices, uniqueID), + JSI_EXPORT_FUNC(JsiSkVertices, dispose)) /** * Creates the function for construction a new instance of the SkVertices diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.cpp b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.cpp index 3e4a67ba1f0b6..684168de1d6f8 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.cpp +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.cpp @@ -55,12 +55,18 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime, const jsi::PropNameID &name) { auto nameStr = name.utf8(runtime); - // Do the happy-paths first + // Happy path - cached host functions are cheapest to look up + const JsiFunctionMap &funcs = getExportedFunctionMap(); + auto func = funcs.find(nameStr); // Check function cache - auto cachedFunc = _hostFunctionCache.find(nameStr); - if (cachedFunc != _hostFunctionCache.end()) { - return cachedFunc->second.asFunction(runtime); + if (func != funcs.end()) { + std::map &runtimeCache = + _hostFunctionCache.get(runtime); + auto cachedFunc = runtimeCache.find(nameStr); + if (cachedFunc != runtimeCache.end()) { + return cachedFunc->second.asFunction(runtime); + } } // Check the static getters map @@ -72,9 +78,9 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime, } // Check the static function map - const JsiFunctionMap &funcs = getExportedFunctionMap(); - auto func = funcs.find(nameStr); if (func != funcs.end()) { + + // Create dispatcher auto dispatcher = std::bind(func->second, reinterpret_cast(this), std::placeholders::_1, std::placeholders::_2, @@ -82,7 +88,7 @@ jsi::Value JsiHostObject::get(jsi::Runtime &runtime, // Add to cache - it is important to cache the results from the // createFromHostFunction function which takes some time. - return _hostFunctionCache + return _hostFunctionCache.get(runtime) .emplace(nameStr, jsi::Function::createFromHostFunction(runtime, name, 0, dispatcher)) .first->second.asFunction(runtime); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.h index 4a96b48c4706c..79c1fe42441f4 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/JsiHostObject.h @@ -9,6 +9,8 @@ #include #include +#include "RuntimeAwareCache.h" + #define STR_CAT_NX(A, B) A##B #define STR_CAT(A, B) STR_CAT_NX(A, B) #define STR_GET get_ @@ -363,6 +365,6 @@ class JsiHostObject : public jsi::HostObject { std::unordered_map _funcMap; std::unordered_map _propMap; - std::map _hostFunctionCache; + RuntimeAwareCache> _hostFunctionCache; }; } // namespace RNJsi diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.cpp b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.cpp new file mode 100644 index 0000000000000..ec9d5bad74242 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.cpp @@ -0,0 +1,7 @@ +#include "RuntimeAwareCache.h" + +namespace RNJsi { + +jsi::Runtime *BaseRuntimeAwareCache::_mainRuntime = nullptr; + +} // namespace RNJsi diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.h new file mode 100644 index 0000000000000..2b5f16b53af7e --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeAwareCache.h @@ -0,0 +1,101 @@ +#pragma once + +#include + +#include +#include +#include + +#include "RuntimeLifecycleMonitor.h" + +namespace RNJsi { + +namespace jsi = facebook::jsi; + +class BaseRuntimeAwareCache { +public: + static void setMainJsRuntime(jsi::Runtime *rt) { _mainRuntime = rt; } + +protected: + static jsi::Runtime *getMainJsRuntime() { + assert(_mainRuntime != nullptr && + "Expected main Javascript runtime to be set in the " + "BaseRuntimeAwareCache class."); + + return _mainRuntime; + } + +private: + static jsi::Runtime *_mainRuntime; +}; + +/** + * Provides a way to keep data specific to a jsi::Runtime instance that gets + * cleaned up when that runtime is destroyed. This is necessary because JSI does + * not allow for its associated objects to be retained past the runtime + * lifetime. If an object (e.g. jsi::Values or jsi::Function instances) is kept + * after the runtime is torn down, its destructor (once it is destroyed + * eventually) will result in a crash (JSI objects keep a pointer to memory + * managed by the runtime, accessing that portion of the memory after runtime is + * deleted is the root cause of that crash). + * + * In order to provide an efficient implementation that does not add an overhead + * for the cases when only a single runtiome is used, which is the primary + * usecase, the following assumption has been made: Only for secondary runtimes + * we track destruction and clean up the store associated with that runtime. For + * the first runtime we assume that the object holding the store is destroyed + * prior to the destruction of that runtime. + * + * The above assumption makes it work without any overhead when only single + * runtime is in use. Specifically, we don't perform any additional operations + * related to tracking runtime lifecycle when only a single runtime is used. + */ +template +class RuntimeAwareCache : public BaseRuntimeAwareCache, + public RuntimeLifecycleListener { + +public: + void onRuntimeDestroyed(jsi::Runtime *rt) override { + if (getMainJsRuntime() != rt) { + // We are removing a secondary runtime + _secondaryRuntimeCaches.erase(rt); + } + } + + ~RuntimeAwareCache() { + for (auto &cache : _secondaryRuntimeCaches) { + RuntimeLifecycleMonitor::removeListener( + *static_cast(cache.first), this); + } + } + + T &get(jsi::Runtime &rt) { + // We check if we're accessing the main runtime - this is the happy path + // to avoid us having to lookup by runtime for caches that only has a single + // runtime + if (getMainJsRuntime() == &rt) { + return _primaryCache; + } else { + if (_secondaryRuntimeCaches.count(&rt) == 0) { + // we only add listener when the secondary runtime is used, this assumes + // that the secondary runtime is terminated first. This lets us avoid + // additional complexity for the majority of cases when objects are not + // shared between runtimes. Otherwise we'd have to register all objecrts + // with the RuntimeMonitor as opposed to only registering ones that are + // used in secondary runtime. Note that we can't register listener here + // with the primary runtime as it may run on a separate thread. + RuntimeLifecycleMonitor::addListener(rt, this); + + T cache; + _secondaryRuntimeCaches.emplace(&rt, std::move(cache)); + } + } + return _secondaryRuntimeCaches.at(&rt); + } + +private: + std::unordered_map _secondaryRuntimeCaches; + T _primaryCache; +}; + +} // namespace RNJsi diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.cpp b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.cpp new file mode 100644 index 0000000000000..d94b3717c5eac --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.cpp @@ -0,0 +1,57 @@ +#include "RuntimeLifecycleMonitor.h" + +#include +#include +#include + +namespace RNJsi { + +static std::unordered_map> + listeners; + +struct RuntimeLifecycleMonitorObject : public jsi::HostObject { + jsi::Runtime *_rt; + explicit RuntimeLifecycleMonitorObject(jsi::Runtime *rt) : _rt(rt) {} + ~RuntimeLifecycleMonitorObject() { + auto listenersSet = listeners.find(_rt); + if (listenersSet != listeners.end()) { + for (auto listener : listenersSet->second) { + listener->onRuntimeDestroyed(_rt); + } + listeners.erase(listenersSet); + } + } +}; + +void RuntimeLifecycleMonitor::addListener(jsi::Runtime &rt, + RuntimeLifecycleListener *listener) { + auto listenersSet = listeners.find(&rt); + if (listenersSet == listeners.end()) { + // We install a global host object in the provided runtime, this way we can + // use that host object destructor to get notified when the runtime is being + // terminated. We use a unique name for the object as it gets saved with the + // runtime's global object. + rt.global().setProperty( + rt, "__rnskia_rt_lifecycle_monitor", + jsi::Object::createFromHostObject( + rt, std::make_shared(&rt))); + std::unordered_set newSet; + newSet.insert(listener); + listeners.emplace(&rt, std::move(newSet)); + } else { + listenersSet->second.insert(listener); + } +} + +void RuntimeLifecycleMonitor::removeListener( + jsi::Runtime &rt, RuntimeLifecycleListener *listener) { + auto listenersSet = listeners.find(&rt); + if (listenersSet == listeners.end()) { + // nothing to do here + } else { + listenersSet->second.erase(listener); + } +} + +} // namespace RNJsi diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.h new file mode 100644 index 0000000000000..baec54f51a4de --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/jsi/RuntimeLifecycleMonitor.h @@ -0,0 +1,32 @@ +#pragma once + +#include + +#include + +namespace RNJsi { + +namespace jsi = facebook::jsi; + +/** + * Listener interface that allows for getting notified when a jsi::Runtime + * instance is destroyed. + */ +struct RuntimeLifecycleListener { + virtual ~RuntimeLifecycleListener() {} + virtual void onRuntimeDestroyed(jsi::Runtime *) = 0; +}; + +/** + * This class provides an API via static methods for registering and + * unregistering runtime lifecycle listeners. The listeners can be used to + * cleanup any data that references a given jsi::Runtime instance before it gets + * destroyed. + */ +struct RuntimeLifecycleMonitor { + static void addListener(jsi::Runtime &rt, RuntimeLifecycleListener *listener); + static void removeListener(jsi::Runtime &rt, + RuntimeLifecycleListener *listener); +}; + +} // namespace RNJsi diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkAnimation.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkAnimation.h index 87ee94e8192c7..9abd4418b57f4 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkAnimation.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkAnimation.h @@ -3,9 +3,9 @@ #include #include -#include -#include -#include +#include "JsiHostObject.h" +#include "RNSkClockValue.h" +#include "RNSkPlatformContext.h" #include namespace RNSkia { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.cpp b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.cpp index 6762a0e47ed0f..9226a5649bb80 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.cpp +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.cpp @@ -22,7 +22,7 @@ RNSkDomRenderer::RNSkDomRenderer(std::function requestRedraw, RNSkDomRenderer::~RNSkDomRenderer() { if (_root != nullptr) { - _root->dispose(); + _root->dispose(true); _root = nullptr; } } @@ -63,7 +63,7 @@ void RNSkDomRenderer::renderImmediate( void RNSkDomRenderer::setRoot(std::shared_ptr node) { std::lock_guard lock(_rootLock); if (_root != nullptr) { - _root->dispose(); + _root->dispose(true); _root = nullptr; } _root = node; @@ -79,14 +79,12 @@ void RNSkDomRenderer::renderCanvas(SkCanvas *canvas, float scaledWidth, _renderTimingInfo.beginTiming(); auto pd = _platformContext->getPixelDensity(); - + canvas->clear(SK_ColorTRANSPARENT); canvas->save(); canvas->scale(pd, pd); if (_drawingContext == nullptr) { - auto paint = std::make_shared(); - paint->setAntiAlias(true); - _drawingContext = std::make_shared(paint); + _drawingContext = std::make_shared(); _drawingContext->setRequestRedraw([weakSelf = weak_from_this()]() { auto self = weakSelf.lock(); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.h index 12e246f387f1d..5832d3dbcfbb6 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkDomView.h @@ -9,21 +9,21 @@ #include -#include -#include +#include "JsiValueWrapper.h" +#include "RNSkView.h" #include "JsiDomRenderNode.h" -#include -#include -#include -#include +#include "RNSkInfoParameter.h" +#include "RNSkLog.h" +#include "RNSkPlatformContext.h" +#include "RNSkTimingInfo.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include -#include -#include +#include "SkBBHFactory.h" +#include "SkCanvas.h" +#include "SkPictureRecorder.h" #pragma clang diagnostic pop diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkInfoParameter.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkInfoParameter.h index 49a3ad2c9cedb..aa981d63a3b8a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkInfoParameter.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkInfoParameter.h @@ -8,8 +8,8 @@ #include -#include -#include +#include "JsiHostObject.h" +#include "RNSkView.h" namespace RNSkia { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.cpp b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.cpp index facdc0a775271..3c4abb892f398 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.cpp +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.cpp @@ -8,7 +8,7 @@ RNSkJsRenderer::RNSkJsRenderer(std::function requestRedraw, std::shared_ptr context) : RNSkRenderer(requestRedraw), _jsiCanvas(std::make_shared(context)), - _platformContext(std::move(context)), + _platformContext(context), _infoObject(std::make_shared()), _jsDrawingLock(std::make_shared()), _gpuDrawingLock(std::make_shared()), @@ -197,11 +197,14 @@ void RNSkJsRenderer::drawInJsiCanvas(std::shared_ptr jsiCanvas, if (_drawCallback != nullptr && skCanvas != nullptr) { // Make sure to scale correctly auto pd = _platformContext->getPixelDensity(); + skCanvas->clear(SK_ColorTRANSPARENT); skCanvas->save(); skCanvas->scale(pd, pd); // Call draw function. callJsDrawCallback(jsiCanvas, width / pd, height / pd, time); + + skCanvas->restore(); } } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.h index 71e65e2ba8489..f286682d13c0a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsView.h @@ -9,14 +9,14 @@ #include -#include -#include - -#include -#include -#include -#include -#include +#include "JsiValueWrapper.h" +#include "RNSkView.h" + +#include "JsiSkCanvas.h" +#include "RNSkInfoParameter.h" +#include "RNSkLog.h" +#include "RNSkPlatformContext.h" +#include "RNSkTimingInfo.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsiViewApi.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsiViewApi.h index eb4a97628370c..5096c6dfc288f 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsiViewApi.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkJsiViewApi.h @@ -7,11 +7,11 @@ #include #include -#include -#include -#include -#include -#include +#include "JsiHostObject.h" +#include "JsiValueWrapper.h" +#include "RNSkPlatformContext.h" +#include "RNSkValue.h" +#include "RNSkView.h" #include namespace RNSkia { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkManager.cpp b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkManager.cpp index 5bb6b11fd4ec4..819e491d66ba6 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkManager.cpp +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkManager.cpp @@ -11,6 +11,7 @@ #include #include +#include namespace RNSkia { namespace jsi = facebook::jsi; @@ -23,6 +24,9 @@ RNSkManager::RNSkManager( _platformContext(platformContext), _viewApi(std::make_shared(platformContext)) { + // Register main runtime + BaseRuntimeAwareCache::setMainJsRuntime(_jsRuntime); + // Install bindings installBindings(); } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPictureView.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPictureView.h index 666f83f6f4edd..71cd91e023274 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPictureView.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPictureView.h @@ -9,14 +9,14 @@ #include -#include -#include +#include "JsiValueWrapper.h" +#include "RNSkView.h" -#include -#include -#include -#include -#include +#include "JsiSkPicture.h" +#include "RNSkInfoParameter.h" +#include "RNSkLog.h" +#include "RNSkPlatformContext.h" +#include "RNSkTimingInfo.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -72,10 +72,13 @@ class RNSkPictureRenderer canvasProvider->renderToCanvas([=](SkCanvas *canvas) { // Make sure to scale correctly auto pd = _platformContext->getPixelDensity(); + canvas->clear(SK_ColorTRANSPARENT); canvas->save(); canvas->scale(pd, pd); canvas->drawPicture(_picture->getObject()); + + canvas->restore(); }); } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPlatformContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPlatformContext.h index 1b008a3f74a2b..f7f9827d40d85 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPlatformContext.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkPlatformContext.h @@ -9,12 +9,15 @@ #include #include -#include +#include "RNSkDispatchQueue.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" +#include "SkData.h" +#include "SkImage.h" #include "SkStream.h" +#include "SkSurface.h" #pragma clang diagnostic pop @@ -87,6 +90,18 @@ class RNSkPlatformContext { _dispatchQueue->dispatch(std::move(func)); } + /** + * Runs the passed function on the main thread + * @param func Function to run. + */ + virtual void runOnMainThread(std::function func) = 0; + + /** + * Takes a screenshot of a given view represented by the view tag + * @param tag React view tag + */ + virtual sk_sp takeScreenshotFromViewTag(size_t tag) = 0; + /** Returns the javascript runtime */ @@ -109,6 +124,29 @@ class RNSkPlatformContext { */ virtual void raiseError(const std::exception &err) = 0; + /** + * Creates an offscreen surface + * @param width Width of the offscreen surface + * @param height Height of the offscreen surface + * @return sk_sp + */ + virtual sk_sp makeOffscreenSurface(int width, int height) = 0; + + /** + * Creates an skImage containing the screenshot of a native view and its + * children. + * @param viewTag React viewtag + * @param callback Called when image is ready or with null if something + * failed. + */ + virtual void + makeViewScreenshot(int viewTag, + std::function)> callback) { + runOnMainThread([this, callback, viewTag]() { + callback(takeScreenshotFromViewTag(viewTag)); + }); + } + /** * Raises an exception on the platform. This function does not necessarily * throw an exception and stop execution, so it is important to stop execution diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkValueApi.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkValueApi.h index facc0d6343c3a..302f9755db2b9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkValueApi.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkValueApi.h @@ -2,11 +2,11 @@ #include -#include -#include -#include -#include -#include +#include "JsiHostObject.h" +#include "RNSkAnimation.h" +#include "RNSkComputedValue.h" +#include "RNSkPlatformContext.h" +#include "RNSkValue.h" #include namespace RNSkia { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkView.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkView.h index d93f7a41cbdf7..ba52e1fec8924 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkView.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/RNSkView.h @@ -6,13 +6,13 @@ #include #include -#include -#include -#include +#include "JsiValueWrapper.h" +#include "RNSkPlatformContext.h" +#include "RNSkValue.h" -#include -#include -#include +#include "JsiSkImage.h" +#include "JsiSkPoint.h" +#include "JsiSkRect.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" @@ -88,23 +88,26 @@ class RNSkRenderer { class RNSkImageCanvasProvider : public RNSkCanvasProvider { public: - RNSkImageCanvasProvider(std::function requestRedraw, float width, + RNSkImageCanvasProvider(std::shared_ptr context, + std::function requestRedraw, float width, float height) : RNSkCanvasProvider(requestRedraw), _width(width), _height(height) { - _surface = SkSurface::MakeRasterN32Premul(_width, _height); + _surface = context->makeOffscreenSurface(_width, _height); } /** Returns a snapshot of the current surface/canvas */ sk_sp makeSnapshot(std::shared_ptr bounds) { + sk_sp image; if (bounds != nullptr) { SkIRect b = SkIRect::MakeXYWH(bounds->x(), bounds->y(), bounds->width(), bounds->height()); - return _surface->makeImageSnapshot(b); + image = _surface->makeImageSnapshot(b); } else { - return _surface->makeImageSnapshot(); + image = _surface->makeImageSnapshot(); } + return image->makeNonTextureImage(); } /** @@ -261,8 +264,9 @@ class RNSkView : public std::enable_shared_from_this { Renders the view into an SkImage instead of the screen. */ sk_sp makeImageSnapshot(std::shared_ptr bounds) { + auto provider = std::make_shared( - std::bind(&RNSkView::requestRedraw, this), + getPlatformContext(), std::bind(&RNSkView::requestRedraw, this), _canvasProvider->getScaledWidth(), _canvasProvider->getScaledHeight()); _renderer->renderImmediate(provider); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/JsiDomApi.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/JsiDomApi.h index 2d5731fbcd91d..8a84498b06608 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/JsiDomApi.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/JsiDomApi.h @@ -2,6 +2,7 @@ /* Enable output of dom trees and paint contexts */ #define SKIA_DOM_DEBUG 0 +#define SKIA_DOM_DEBUG_VERBOSE 0 #include diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.cpp b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.cpp new file mode 100644 index 0000000000000..1f56372a0dd47 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.cpp @@ -0,0 +1,117 @@ +#include "ConcatablePaint.h" + +#include "DeclarationContext.h" +#include "JsiDomNode.h" +#include "PaintProps.h" + +namespace RNSkia { + +ConcatablePaint::ConcatablePaint( + DeclarationContext *declarationContext, PaintProps *paintProps, + const std::vector> &children) + : _declarationContext(declarationContext), _paintProps(paintProps), + _children(children) { + + auto hasPropertyValues = _paintProps->getColor()->isSet() || + _paintProps->getStrokeWidth()->isSet() || + _paintProps->getBlendMode()->isSet() || + _paintProps->getStyle()->isSet() || + _paintProps->getStrokeJoin()->isSet() || + _paintProps->getStrokeCap()->isSet() || + _paintProps->getStrokeMiter()->isSet() || + _paintProps->getOpacity()->isSet() || + _paintProps->getAntiAlias()->isSet(); + + _declarationContext->save(); + + for (auto &child : _children) { + child->decorateContext(_declarationContext); + } + + _imageFilter = declarationContext->getImageFilters()->popAsOne(); + _colorFilter = declarationContext->getColorFilters()->popAsOne(); + _shader = declarationContext->getShaders()->pop(); + _maskFilter = declarationContext->getMaskFilters()->pop(); + _pathEffect = declarationContext->getPathEffects()->popAsOne(); + + _declarationContext->restore(); + + _isEmpty = !hasPropertyValues && _imageFilter == nullptr && + _colorFilter == nullptr && _shader == nullptr && + _maskFilter == nullptr && _pathEffect == nullptr; +} + +bool ConcatablePaint::isEmpty() { return _isEmpty; } + +void ConcatablePaint::concatTo(std::shared_ptr paint) { + + if (_paintProps->getOpacity()->isSet()) { + paint->setAlphaf(paint->getAlphaf() * + _paintProps->getOpacity()->value().getAsNumber()); + } + + if (_paintProps->getColor()->isSet()) { + auto currentOpacity = paint->getAlphaf(); + paint->setShader(nullptr); + paint->setColor(*_paintProps->getColor()->getDerivedValue()); + paint->setAlphaf(paint->getAlphaf() * currentOpacity); + } + + if (_paintProps->getStrokeWidth()->isSet()) { + paint->setStrokeWidth(_paintProps->getStrokeWidth()->value().getAsNumber()); + } + + if (_paintProps->getBlendMode()->isSet()) { + paint->setBlendMode(*_paintProps->getBlendMode()->getDerivedValue()); + } + + if (_paintProps->getStyle()->isSet()) { + auto styleValue = _paintProps->getStyle()->value().getAsString(); + if (styleValue == "stroke") { + paint->setStyle(SkPaint::Style::kStroke_Style); + } else if (styleValue == "fill") { + paint->setStyle(SkPaint::Style::kFill_Style); + } else { + throw std::runtime_error(styleValue + + " is not a valud value for the style property."); + } + } + + if (_paintProps->getStrokeJoin()->isSet()) { + paint->setStrokeJoin(*_paintProps->getStrokeJoin()->getDerivedValue()); + } + + if (_paintProps->getStrokeCap()->isSet()) { + paint->setStrokeCap(*_paintProps->getStrokeCap()->getDerivedValue()); + } + + if (_paintProps->getStrokeMiter()->isSet()) { + paint->setStrokeMiter(_paintProps->getStrokeMiter()->value().getAsNumber()); + } + + if (_paintProps->getAntiAlias()->isSet()) { + paint->setAntiAlias(_paintProps->getAntiAlias()->value().getAsBool()); + } + + if (_imageFilter) { + paint->setImageFilter(_imageFilter); + } + + if (_colorFilter) { + paint->setColorFilter(_colorFilter); + } + + if (_shader) { + paint->setShader(_shader); + } + + if (_maskFilter) { + paint->setMaskFilter(_maskFilter); + } + + if (_pathEffect) { + paint->setPathEffect(_pathEffect); + } +} + +} // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.h new file mode 100644 index 0000000000000..dd4c2f0b52bdb --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/ConcatablePaint.h @@ -0,0 +1,49 @@ +#pragma once + +#include +#include + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdocumentation" + +#include "SkColorFilter.h" +#include "SkImageFilter.h" +#include "SkMaskFilter.h" +#include "SkPaint.h" +#include "SkPathEffect.h" +#include "SkShader.h" + +#pragma clang diagnostic pop + +namespace RNSkia { + +class JsiDomNode; +class PaintProps; +class DeclarationContext; + +/** + Class for concatenating SkPaint objects. + */ +class ConcatablePaint { +public: + ConcatablePaint(DeclarationContext *context, PaintProps *paintProps, + const std::vector> &children); + + void concatTo(std::shared_ptr paint); + bool isEmpty(); + +private: + DeclarationContext *_declarationContext; + const std::vector> _children; + PaintProps *_paintProps; + + bool _isEmpty{true}; + + sk_sp _imageFilter; + sk_sp _colorFilter; + sk_sp _pathEffect; + sk_sp _maskFilter; + sk_sp _shader; +}; + +} // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/Declaration.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/Declaration.h new file mode 100644 index 0000000000000..f95478c7b341d --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/Declaration.h @@ -0,0 +1,86 @@ +#pragma once + +#include +#include +#include +#include +#include + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdocumentation" + +#include "SkRefCnt.h" + +#pragma clang diagnostic pop + +namespace RNSkia { + +/** + Small container for shaders, filters, masks and effects + */ +template class Declaration { +public: + // Pushes to the stack + void push(T el) { _elements.push(el); } + + // Clears and returns all elements + std::vector popAll() { + auto size = _elements.size(); + std::vector tmp; + tmp.reserve(size); + for (size_t i = 0; i < size; ++i) { + tmp.push_back(_elements.top()); + _elements.pop(); + } + std::reverse(std::begin(tmp), std::end(tmp)); + return tmp; + } + + T pop() { + if (_elements.size() == 0) { + return nullptr; + } + auto tmp = _elements.top(); + _elements.pop(); + return tmp; + } + + // Clears and returns through reducer function in reversed order + T popAsOne(std::function composer) { + auto tmp = popAll(); + std::reverse(std::begin(tmp), std::end(tmp)); + return std::accumulate(std::begin(tmp), std::end(tmp), + static_cast(nullptr), [=](T inner, T outer) { + if (inner == nullptr) { + return outer; + } + return composer(inner, outer); + }); + } + + // Returns the size of the elements + size_t size() { return _elements.size(); } + +private: + std::stack _elements; +}; + +/** + Small container for shaders, filters, masks and effects + */ +template class ComposableDeclaration : public Declaration { +public: + /** + Constructor + */ + explicit ComposableDeclaration(std::function composer) + : Declaration(), _composer(composer) {} + + // Clears and returns through reducer function in reversed order + T popAsOne() { return Declaration::popAsOne(_composer); } + +private: + std::function _composer; +}; + +} // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DeclarationContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DeclarationContext.h new file mode 100644 index 0000000000000..dcb33f891b9bc --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DeclarationContext.h @@ -0,0 +1,79 @@ +#pragma once + +#include "Declaration.h" + +#include +#include +#include + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdocumentation" + +#include "SkColorFilter.h" +#include "SkImageFilter.h" +#include "SkImageFilters.h" +#include "SkMaskFilter.h" +#include "SkPaint.h" +#include "SkPathEffect.h" +#include "SkShader.h" + +#pragma clang diagnostic pop + +namespace RNSkia { + +class DeclarationContext { +public: + DeclarationContext() { save(); } + + Declaration> *getShaders() { return &_shaders.top(); } + ComposableDeclaration> *getImageFilters() { + return &_imageFilters.top(); + } + ComposableDeclaration> *getColorFilters() { + return &_colorFilters.top(); + } + ComposableDeclaration> *getPathEffects() { + return &_pathEffects.top(); + } + Declaration> *getMaskFilters() { + return &_maskFilters.top(); + } + Declaration> *getPaints() { return &_paints.top(); } + + void save() { + _paints.emplace(); + _shaders.emplace(); + _imageFilters.emplace( + [](sk_sp inner, sk_sp outer) { + return SkImageFilters::Compose(outer, inner); + }); + _colorFilters.emplace( + [](sk_sp inner, sk_sp outer) { + return SkColorFilters::Compose(outer, inner); + }); + _pathEffects.emplace( + [](sk_sp inner, sk_sp outer) { + return SkPathEffect::MakeCompose(outer, inner); + }); + _maskFilters.emplace(); + } + + void restore() { + _shaders.pop(); + _imageFilters.pop(); + _colorFilters.pop(); + _pathEffects.pop(); + _maskFilters.pop(); + _paints.pop(); + } + +private: + std::stack>> _shaders; + std::stack>> _imageFilters; + std::stack>> _colorFilters; + std::stack>> _pathEffects; + std::stack>> _maskFilters; + std::stack>> _paints; +}; + +} // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DerivedNodeProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DerivedNodeProp.h index 27c97c45913e5..3a9ecb4476b1b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DerivedNodeProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DerivedNodeProp.h @@ -15,7 +15,8 @@ namespace RNSkia { */ class BaseDerivedProp : public BaseNodeProp { public: - BaseDerivedProp() : BaseNodeProp() {} + explicit BaseDerivedProp(const std::function &onChange) + : _onChange(onChange), BaseNodeProp() {} /** Starts the process of updating and reading props @@ -70,7 +71,11 @@ class BaseDerivedProp : public BaseNodeProp { /** Adds a property to the derived property child props. */ - template P *addProperty(std::shared_ptr

prop) { + template ::value>> + _Tp *defineProperty(_Args &&...__args) { + auto prop = + std::make_shared<_Tp>(std::forward<_Args>(__args)..., _onChange); _properties.push_back(prop); return prop.get(); } @@ -104,6 +109,7 @@ class BaseDerivedProp : public BaseNodeProp { private: std::vector> _properties; std::atomic _isChanged = {false}; + std::function _onChange; }; /** @@ -111,12 +117,21 @@ class BaseDerivedProp : public BaseNodeProp { */ template class DerivedProp : public BaseDerivedProp { public: - DerivedProp() : BaseDerivedProp() {} + explicit DerivedProp(const std::function &onChange) + : BaseDerivedProp(onChange) {} /** Returns the derived value */ - std::shared_ptr getDerivedValue() { return _derivedValue; } + std::shared_ptr getDerivedValue() { + return std::const_pointer_cast(_derivedValue); + } + + /** + Returns a mutable version of the derived value. Used by the paint props to + keep a drawing context + */ + std::shared_ptr getUnsafeDerivedValue() { return _derivedValue; } /** Returns true if is optional and one of the child props has a value, or all @@ -128,7 +143,7 @@ template class DerivedProp : public BaseDerivedProp { /** Set derived value from sub classes */ - void setDerivedValue(std::shared_ptr value) { + void setDerivedValue(std::shared_ptr value) { setIsChanged(_derivedValue != value); _derivedValue = value; } @@ -136,13 +151,13 @@ template class DerivedProp : public BaseDerivedProp { /** Set derived value from sub classes */ - void setDerivedValue(const T &&value) { + void setDerivedValue(T &&value) { setIsChanged(true); - _derivedValue = std::make_shared(std::move(value)); + _derivedValue = std::make_shared(std::move(value)); } private: - std::shared_ptr _derivedValue; + std::shared_ptr _derivedValue; }; /** @@ -150,7 +165,8 @@ template class DerivedProp : public BaseDerivedProp { */ template class DerivedSkProp : public BaseDerivedProp { public: - DerivedSkProp() : BaseDerivedProp() {} + explicit DerivedSkProp(const std::function &onChange) + : BaseDerivedProp(onChange) {} /** Returns the derived value diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.cpp b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.cpp index c4c87d5bf019e..b8cd985a42aac 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.cpp +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.cpp @@ -1,209 +1,55 @@ #include "DrawingContext.h" -namespace RNSkia { - -DrawingContext::DrawingContext(std::shared_ptr paint) - : DrawingContext("root") { - _paint = paint; -} - -DrawingContext::DrawingContext(DrawingContext *parent, const char *source) - : DrawingContext(source) { - _parent = parent; -} - -std::shared_ptr -DrawingContext::inheritContext(const char *source) { - auto result = std::make_shared(this, source); - _children.push_back(result); - return result; -} - -std::string DrawingContext::getDebugDescription() { - std::string v = "ctx for " + std::string(_source) + ":"; - - if (_paint != nullptr) { - auto clr = _paint->getColor(); - auto a = SkColorGetA(clr); - auto r = SkColorGetR(clr); - auto g = SkColorGetG(clr); - auto b = SkColorGetB(clr); - - if (r > 0 || g > 0 || b > 0) { - v += " color:rgba(" + std::to_string(r) + ", " + std::to_string(g) + - ", " + std::to_string(b) + ", " + std::to_string(a) + ")"; - } - - if (_paint->getMaskFilter() != nullptr) { - v += " maskFilter:set"; - } - auto blendMode = _paint->getBlendMode_or(SkBlendMode::kSrc); - if (blendMode != SkBlendMode::kSrc) { - v += " blendMode:" + std::to_string(static_cast(blendMode)); - } - - auto opacity = _paint->getAlphaf(); - v += " opacity:" + std::to_string(opacity); +#include "ConcatablePaint.h" +#include "JsiDomNode.h" +#include "PaintProps.h" - if (_paint->getPathEffect() != nullptr) { - v += " [PathEffect]"; - } - - if (_paint->getShader() != nullptr) { - v += " [Shader]"; - } - - if (_paint->getImageFilter() != nullptr) { - v += " [ImageFilter]"; - } - - if (_paint->getMaskFilter() != nullptr) { - v += " [MaskFilter]"; - } - - if (_paint->getColorFilter() != nullptr) { - v += " [ColorFilter]"; - } - - } else { - v = v + "[inherited] " + - (_parent != nullptr ? _parent->getDebugDescription() : ""); - } - - v = v + "\n"; - - return v; -} - -/** - Invalidate cache - */ -void DrawingContext::markAsChanged() { - markChildrenAsChanged(); - _paint = nullptr; - _isChanged = true; -} +#include -/** - Call to reset invalidate flag after render cycle - */ -void DrawingContext::resetChangedFlag() { _isChanged = false; } - -/** - Dispose and remove the drawing context from its parent. - */ -void DrawingContext::dispose() { - if (_parent != nullptr) { - auto position = std::find(_parent->_children.begin(), - _parent->_children.end(), shared_from_this()); +namespace RNSkia { - if (position != _parent->_children.end()) { - _parent->_children.erase(position); - } - // TODO: This is called from the JS thread so we need somehow to avoid - // rendering after setting this to null, and we also need to protect this - // section. - _parent = nullptr; - } +DrawingContext::DrawingContext(std::shared_ptr paint) { + _declarationContext = std::make_unique(); + paint->setAntiAlias(true); + _paints.push_back(paint); } -/** - Returns true if the current cache is changed - */ -bool DrawingContext::isChanged() { return _isChanged; } +DrawingContext::DrawingContext() + : DrawingContext(std::make_shared()) {} -/** - Get/Sets the canvas object - */ -SkCanvas *DrawingContext::getCanvas() { - if (_parent != nullptr) { - return _parent->getCanvas(); - } - - return _canvas; -} +bool DrawingContext::saveAndConcat( + PaintProps *paintProps, + const std::vector> &children, + std::shared_ptr paintCache) { -/** - Sets the canvas - */ -void DrawingContext::setCanvas(SkCanvas *canvas) { _canvas = canvas; } - -/** - Gets the paint object - */ -std::shared_ptr DrawingContext::getPaint() { - if (_paint != nullptr) { - return _paint; + if (paintCache) { + _paints.push_back(paintCache); + return true; } - return _parent->getPaint(); -} -/** - To be able to mutate and change the paint in a context we need to mutate the - underlying paint object - otherwise we'll just use the parent paint object - (to avoid having to create multiple paint objects for nodes that does not - change the paint). - */ -std::shared_ptr DrawingContext::getMutablePaint() { - if (_paint == nullptr) { - auto parentPaint = _parent->getPaint(); - _paint = std::make_shared(*parentPaint); + ConcatablePaint paint(_declarationContext.get(), paintProps, children); + if (!paint.isEmpty()) { + save(); + paint.concatTo(getPaint()); + return true; } - // Calling the getMutablePaint accessor implies that the paint - // is about to be mutatet and will therefore invalidate - // any child contexts to pick up changes from this context as - // the parent context. - markChildrenAsChanged(); - return _paint; -} - -/** - Sets the paint in the current sub context - */ -void DrawingContext::setMutablePaint(std::shared_ptr paint) { - _paint = paint; -} -float DrawingContext::getScaledWidth() { - if (_parent != nullptr) { - return _parent->getScaledWidth(); - } - return _scaledWidth; + return false; } -float DrawingContext::getScaledHeight() { - if (_parent != nullptr) { - return _parent->getScaledHeight(); - } - return _scaledHeight; +void DrawingContext::save() { + // Copy paint and push + _paints.push_back(std::make_shared(*getPaint())); } -DrawingContext *DrawingContext::getParent() { return _parent; } +void DrawingContext::restore() { _paints.pop_back(); } -void DrawingContext::setScaledWidth(float v) { _scaledWidth = v; } -void DrawingContext::setScaledHeight(float v) { _scaledHeight = v; } - -void DrawingContext::setRequestRedraw(std::function &&requestRedraw) { - if (_parent != nullptr) { - _parent->setRequestRedraw(std::move(requestRedraw)); - } else { - _requestRedraw = std::move(requestRedraw); - } -} +SkCanvas *DrawingContext::getCanvas() { return _canvas; } -const std::function &DrawingContext::getRequestRedraw() { - if (_parent != nullptr) { - return _parent->getRequestRedraw(); - } - return _requestRedraw; -} - -DrawingContext::DrawingContext(const char *source) { _source = source; } +void DrawingContext::setCanvas(SkCanvas *canvas) { _canvas = canvas; } -void DrawingContext::markChildrenAsChanged() { - for (auto &child : _children) { - child->markAsChanged(); - } +std::shared_ptr DrawingContext::getPaint() { + return _paints[_paints.size() - 1]; } } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.h index 184a1eebdb279..b347acd550505 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/DrawingContext.h @@ -2,6 +2,9 @@ #include "JsiHostObject.h" +#include "Declaration.h" +#include "DeclarationContext.h" + #include #include #include @@ -10,49 +13,57 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include -#include +#include "SkCanvas.h" +#include "SkPaint.h" +#include "SkRefCnt.h" #pragma clang diagnostic pop namespace RNSkia { -class DrawingContext : public std::enable_shared_from_this { +class PaintProps; +class JsiDomNode; + +class DomRenderContext { public: - /** - Creates a root drawing context with paint and opacity - */ - explicit DrawingContext(std::shared_ptr paint); + float getScaledWidth() { return _scaledWidth; } + float getScaledHeight() { return _scaledHeight; } - /** - Initilalizes a new draw context. - */ - DrawingContext(DrawingContext *parent, const char *source); + void setScaledWidth(float v) { _scaledWidth = v; } + void setScaledHeight(float v) { _scaledHeight = v; } - /** - Factory for creating a child context that inherits from this context - */ - std::shared_ptr inheritContext(const char *source); + void setRequestRedraw(std::function &&requestRedraw) { + _requestRedraw = std::move(requestRedraw); + } - /** - Returns the debug description for the context - */ - std::string getDebugDescription(); + const std::function &getRequestRedraw() { return _requestRedraw; } + +private: + float _scaledWidth = -1; + float _scaledHeight = -1; + std::function _requestRedraw; +}; +class DrawingContext : public DomRenderContext, + public std::enable_shared_from_this { +public: /** - Mark the drawing context and any child contexts as changed + Creates a root drawing context with paint and opacity */ - void markAsChanged(); + DrawingContext(); /** - Call to reset invalidate flag after render cycle - */ - void resetChangedFlag(); + Creates a drawing context with the given paint as its starting paint object + */ + explicit DrawingContext(std::shared_ptr paint); /** - Dispose and remove the drawing context from its parent. + Factory for saving/restoring the context for a node */ - void dispose(); + bool saveAndConcat(PaintProps *paintProps, + const std::vector> &children, + std::shared_ptr paintCache); + void restore(); /** Returns true if the current cache is changed @@ -72,52 +83,22 @@ class DrawingContext : public std::enable_shared_from_this { /** Gets the paint object */ - std::shared_ptr getPaint(); - - /** - To be able to mutate and change the paint in a context we need to mutate the - underlying paint object - otherwise we'll just use the parent paint object - (to avoid having to create multiple paint objects for nodes that does not - change the paint). - */ - std::shared_ptr getMutablePaint(); + std::shared_ptr getPaint(); - /** - Sets the paint in the current sub context + /* + Returns the root declaratiins object */ - void setMutablePaint(std::shared_ptr paint); - - float getScaledWidth(); - - float getScaledHeight(); - - void setScaledWidth(float v); - void setScaledHeight(float v); - - void setRequestRedraw(std::function &&requestRedraw); - const std::function &getRequestRedraw(); - - DrawingContext *getParent(); + DeclarationContext *getDeclarationContext() { + return _declarationContext.get(); + } private: - explicit DrawingContext(const char *source); - - void markChildrenAsChanged(); - - bool _isChanged = true; - - std::shared_ptr _paint; + void save(); + explicit DrawingContext(const char *source); SkCanvas *_canvas = nullptr; - const char *_source; - - DrawingContext *_parent = nullptr; - std::vector> _children; - - float _scaledWidth = -1; - float _scaledHeight = -1; - - std::function _requestRedraw; + std::vector> _paints; + std::unique_ptr _declarationContext; }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDependencyManager.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDependencyManager.h index d8ed4be35548d..6fb59310f8fa1 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDependencyManager.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDependencyManager.h @@ -23,8 +23,10 @@ class JsiDependencyManager public std::enable_shared_from_this { public: JsiDependencyManager(std::shared_ptr context, - jsi::Object &®isterValuesCallback) - : _registerValuesCallback(std::move(registerValuesCallback)), + jsi::Runtime &runtime, + const jsi::Value ®isterValuesCallback) + : _registerValuesCallback(std::make_shared( + registerValuesCallback.asObject(runtime))), JsiHostObject() {} ~JsiDependencyManager() { unsubscribeAll(); } @@ -62,53 +64,53 @@ class JsiDependencyManager // Enumerate registered keys for the given node to only handle known // properties - for (const auto &propMapping : - node->getPropsContainer()->getMappedProperties()) { - auto key = propMapping.first; - auto jsValue = nextProps.getProperty(runtime, key); - JsiValue nativeValue(runtime, jsValue); - - if (isAnimatedValue(nativeValue)) { - // Handle Skia Animation Values - auto animatedValue = getAnimatedValue(nativeValue); - auto unsubscribe = animatedValue->addListener( - [animatedValue, propMapping](jsi::Runtime &runtime) { - // Get value from animation value - auto nextJsValue = animatedValue->getCurrent(runtime); - // Update all props that listens to this animation value - for (auto &prop : propMapping.second) { - prop->updateValue(runtime, nextJsValue); - } - }); - - // Save unsubscribe methods - unsubscribers.push_back(std::make_pair(animatedValue, unsubscribe)); - - } else if (isSelector(nativeValue)) { - // Handle Skia Animation Value Selectors - auto animatedValue = std::dynamic_pointer_cast( - nativeValue.getValue(PropNameValue).getAsHostObject()); - - auto selector = nativeValue.getValue(PropNameSelector).getAsFunction(); - // Add subscription to animated value in selector - auto unsubscribe = animatedValue->addListener( - [nativeValue, propMapping, selector = std::move(selector), - animatedValue](jsi::Runtime &runtime) { - // Get value from animation value - jsi::Value jsValue = animatedValue->getCurrent(runtime); - // Call selector to transform new value - auto selectedJsValue = - selector(runtime, jsi::Value::null(), &jsValue, 1); - // Update all props that listens to this animation value - for (auto &prop : propMapping.second) { - prop->updateValue(runtime, selectedJsValue); - } - }); - - // Save unsubscribe methods - unsubscribers.push_back(std::make_pair(animatedValue, unsubscribe)); - } - } + node->getPropsContainer()->enumerateMappedProps( + [&](const PropId key, const std::vector &propMapping) { + auto jsValue = nextProps.getProperty(runtime, key); + JsiValue nativeValue(runtime, jsValue); + + if (isAnimatedValue(nativeValue)) { + // Handle Skia Animation Values + auto animatedValue = getAnimatedValue(nativeValue); + auto unsubscribe = animatedValue->addListener( + [animatedValue, propMapping](jsi::Runtime &runtime) { + // Get value from animation value + auto nextJsValue = animatedValue->getCurrent(runtime); + // Update all props that listens to this animation value + for (auto &prop : propMapping) { + prop->updateValue(runtime, nextJsValue); + } + }); + + // Save unsubscribe methods + unsubscribers.push_back(std::make_pair(animatedValue, unsubscribe)); + + } else if (isSelector(nativeValue)) { + // Handle Skia Animation Value Selectors + auto animatedValue = std::dynamic_pointer_cast( + nativeValue.getValue(PropNameValue).getAsHostObject()); + + auto selector = + nativeValue.getValue(PropNameSelector).getAsFunction(); + // Add subscription to animated value in selector + auto unsubscribe = animatedValue->addListener( + [nativeValue, propMapping, selector = std::move(selector), + animatedValue](jsi::Runtime &runtime) { + // Get value from animation value + jsi::Value jsValue = animatedValue->getCurrent(runtime); + // Call selector to transform new value + auto selectedJsValue = + selector(runtime, jsi::Value::null(), &jsValue, 1); + // Update all props that listens to this animation value + for (auto &prop : propMapping) { + prop->updateValue(runtime, selectedJsValue); + } + }); + + // Save unsubscribe methods + unsubscribers.push_back(std::make_pair(animatedValue, unsubscribe)); + } + }); // Now let's store the subscription info _subscriptions.emplace(node.get(), unsubscribers); @@ -158,7 +160,7 @@ class JsiDependencyManager } // Call JS registerValues callback - auto func = _registerValuesCallback.asFunction(runtime); + auto func = _registerValuesCallback->asFunction(runtime); _unregisterValues = std::make_shared( func.call(runtime, array, 1).asObject(runtime)); @@ -187,6 +189,8 @@ class JsiDependencyManager unsubscribeAll(); + _registerValuesCallback = nullptr; + return jsi::Value::undefined(); } @@ -203,8 +207,8 @@ class JsiDependencyManager return JSI_HOST_FUNCTION_LAMBDA { // Params: registerValues: (values: Array>) => () => // void - auto obj = std::make_shared( - context, getArgumentAsObject(runtime, arguments, count, 0)); + auto obj = std::make_shared(context, runtime, + arguments[0]); return jsi::Object::createFromHostObject(runtime, std::move(obj)); }; @@ -283,7 +287,7 @@ class JsiDependencyManager return false; } - jsi::Object _registerValuesCallback; + std::shared_ptr _registerValuesCallback; std::shared_ptr _unregisterValues; std::map, diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDeclarationNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDeclarationNode.h index ccf1d9f4427e4..d9ec57debedfb 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDeclarationNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDeclarationNode.h @@ -9,17 +9,29 @@ namespace RNSkia { -class JsiBaseDomDeclarationNode : public JsiDomNode { +enum DeclarationType { + Unknown = 0, + Paint = 1, + Shader = 2, + ImageFilter = 3, + ColorFilter = 4, + PathEffect = 5, + MaskFilter = 6, +}; + +class JsiDomDeclarationNode : public JsiDomNode { public: - JsiBaseDomDeclarationNode(std::shared_ptr context, - const char *type) - : JsiDomNode(context, type) {} + JsiDomDeclarationNode(std::shared_ptr context, + const char *type, DeclarationType declarationType) + : JsiDomNode(context, type, NodeClass::DeclarationNode), + _declarationType(declarationType) {} JSI_PROPERTY_GET(declarationType) { + // FIXME: Shouldn't this be the declaration type instead? It has been return jsi::String::createFromUtf8(runtime, std::string(getType())); } - JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiBaseDomDeclarationNode, + JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiDomDeclarationNode, declarationType), JSI_EXPORT_PROP_GET(JsiDomNode, type)) @@ -34,30 +46,27 @@ class JsiBaseDomDeclarationNode : public JsiDomNode { /** Called when rendering the tree to create all derived values from all nodes. */ - virtual void decorateContext(DrawingContext *context) { + void decorateContext(DeclarationContext *context) override { + JsiDomNode::decorateContext(context); + #if SKIA_DOM_DEBUG - printDebugInfo("Begin Materialize " + std::string(getType())); + printDebugInfo("Begin decorate " + std::string(getType())); #endif - // Materialize children first so that any inner nodes get the opportunity - // to calculate their state before this node continues. - for (auto &child : getChildren()) { - if (child->getNodeClass() == JsiDomNodeClass::DeclarationNode) { - std::static_pointer_cast(child) - ->decorateContext(context); - } - } // decorate drawing context decorate(context); #if SKIA_DOM_DEBUG - printDebugInfo("End / Commit Materialize " + std::string(getType())); + printDebugInfo("End / Commit decorate " + std::string(getType())); #endif } - JsiDomNodeClass getNodeClass() override { - return JsiDomNodeClass::DeclarationNode; - } + DeclarationType getDeclarationType() { return _declarationType; } + + /** + Override to implement materialization + */ + virtual void decorate(DeclarationContext *context) = 0; protected: /** @@ -71,16 +80,15 @@ class JsiBaseDomDeclarationNode : public JsiDomNode { } /** - Override to implement materialization + A property changed */ - virtual void decorate(DrawingContext *context) = 0; + void onPropertyChanged(BaseNodeProp *prop) override { invalidateContext(); } /** Validates that only declaration nodes can be children */ void addChild(std::shared_ptr child) override { - if (std::dynamic_pointer_cast(child) == - nullptr) { + if (child->getNodeClass() != NodeClass::DeclarationNode) { getContext()->raiseError(std::runtime_error( "Cannot add a child of type \"" + std::string(child->getType()) + "\" to a \"" + std::string(getType()) + "\".")); @@ -93,98 +101,19 @@ class JsiBaseDomDeclarationNode : public JsiDomNode { */ void insertChildBefore(std::shared_ptr child, std::shared_ptr before) override { - if (std::dynamic_pointer_cast(child) == - nullptr) { + if (child->getNodeClass() != NodeClass::DeclarationNode) { getContext()->raiseError(std::runtime_error( "Cannot add a child of type \"" + std::string(child->getType()) + "\" to a \"" + std::string(getType()) + "\".")); } JsiDomNode::insertChildBefore(child, before); } -}; - -template -class JsiDomDeclarationNode : public JsiBaseDomDeclarationNode { -public: - JsiDomDeclarationNode(std::shared_ptr context, - const char *type) - : JsiBaseDomDeclarationNode(context, type) {} - - bool isChanged(DrawingContext *context) { - return getCurrent() == nullptr || context->isChanged() || - getPropsContainer()->isChanged(); - } - - /** - Returns the inner element - */ - ST getCurrent() { return _current; } - - /** - Clears the current - */ - void clearCurrent() { _current = nullptr; } - -protected: - /** - Sets the current value - */ - void setCurrent(ST c) { _current = c; } - - /** - Returns a required child image filter by index - */ - ST requireChild(size_t index) { - auto filter = optionalChild(index); - if (filter == nullptr) { - throw std::runtime_error("Expected child node at index " + - std::to_string(index) + " in node " + getType()); - } - return filter; - } - - /** - Returns an optional child image filter by index - */ - ST optionalChild(size_t index) { - if (index >= getChildren().size()) { - return nullptr; - } - - auto child = getChildren()[index]; - // Support all types here!! ImageFilters, ColorFilters - // package/src/dom/nodes/paint/ImageFilters.ts#80 - return resolve(child); - } - - /** - Returns child as inner type or nullptr - */ - virtual ST resolve(std::shared_ptr child) = 0; +private: /** - Sets or composes the image filter + Type of declaration */ - virtual void set(DrawingContext *context, ST imageFilter) = 0; - - void removeChild(std::shared_ptr child) override { - JsiBaseDomDeclarationNode::removeChild(child); - clearCurrent(); - } - - void addChild(std::shared_ptr child) override { - JsiBaseDomDeclarationNode::addChild(child); - clearCurrent(); - } - - void insertChildBefore(std::shared_ptr child, - std::shared_ptr before) override { - JsiBaseDomDeclarationNode::insertChildBefore(child, before); - clearCurrent(); - } - -private: - ST _current; + DeclarationType _declarationType; }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDrawingNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDrawingNode.h index 62174ab6b7329..302c49bfd3cf4 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDrawingNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomDrawingNode.h @@ -16,7 +16,7 @@ class JsiDomDrawingNode : public JsiDomRenderNode { protected: void defineProperties(NodePropsContainer *container) override { JsiDomRenderNode::defineProperties(container); - container->defineProperty(); + _paintProp = container->defineProperty(); } /** @@ -28,23 +28,42 @@ class JsiDomDrawingNode : public JsiDomRenderNode { #if SKIA_DOM_DEBUG printDebugInfo("Begin Draw", 1); #endif - -#if SKIA_DOM_DEBUG - printDebugInfo(context->getDebugDescription(), 2); -#endif - draw(context); + // Save paint if the paint property is set + if (_paintProp->isSet()) { + draw(_paintProp->getUnsafeDerivedValue().get()); + } else { + // Call abstract draw method + draw(context); + } // Draw once more for each child paint node + auto declarationCtx = context->getDeclarationContext(); for (auto &child : getChildren()) { - auto ptr = std::dynamic_pointer_cast(child); - if (ptr != nullptr) { - draw(ptr->getDrawingContext()); + if (child->getNodeClass() == NodeClass::DeclarationNode && + std::static_pointer_cast(child) + ->getDeclarationType() == DeclarationType::Paint) { + auto paintNode = std::static_pointer_cast(child); + // Draw once again with the paint + declarationCtx->save(); + paintNode->decorate(declarationCtx); + auto paint = declarationCtx->getPaints()->pop(); + declarationCtx->restore(); + + // FIXME: Can we avoid creating a new drawing context here each time? + auto localContext = + std::make_shared(std::shared_ptr(paint)); + localContext->setCanvas(context->getCanvas()); + draw(localContext.get()); } } + #if SKIA_DOM_DEBUG printDebugInfo("End Draw", 1); #endif } + +private: + PaintDrawingContextProp *_paintProp; }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomNode.h index 45c296f580905..3d47ec57cf85c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomNode.h @@ -33,7 +33,7 @@ static std::atomic NodeIdent = 1000; typedef enum { RenderNode = 1, DeclarationNode = 2, -} JsiDomNodeClass; +} NodeClass; /** Implements an abstract base class for nodes in the Skia Reconciler. This node @@ -46,8 +46,22 @@ class JsiDomNode : public JsiHostObject, Contructor. Takes as parameters the values comming from the JS world that initialized the class. */ - JsiDomNode(std::shared_ptr context, const char *type) - : _type(type), _context(context), _nodeId(NodeIdent++), JsiHostObject() {} + JsiDomNode(std::shared_ptr context, const char *type, + NodeClass nodeClass) + : _type(type), _context(context), _nodeClass(nodeClass), + _nodeId(NodeIdent++), JsiHostObject() { +#if SKIA_DOM_DEBUG + printDebugInfo("JsiDomNode." + std::string(_type) + + " CTOR - nodeId: " + std::to_string(_nodeId)); +#endif + } + + virtual ~JsiDomNode() { +#if SKIA_DOM_DEBUG + printDebugInfo("JsiDomNode." + std::string(_type) + + " DTOR - nodeId: " + std::to_string(_nodeId)); +#endif + } /** Called when creating the node, resolves properties from the node constructor. @@ -63,7 +77,7 @@ class JsiDomNode : public JsiHostObject, JSI_HOST_FUNCTION(setProps) { if (count == 1) { // Initialize properties container - setProps(runtime, getArgumentAsObject(runtime, arguments, count, 0)); + setProps(runtime, arguments[0]); } else { setEmptyProps(); } @@ -71,16 +85,35 @@ class JsiDomNode : public JsiHostObject, } /** - Empty setProp implementation - compatibility with JS node + Updates the selected property value */ - JSI_HOST_FUNCTION(setProp) { return jsi::Value::undefined(); } + JSI_HOST_FUNCTION(setProp) { + if (_propsContainer == nullptr) { + // TODO: we ignore individual properties updates if the initial properties + // hasn't been defined. It is likely an error if we reach this branch and + // perhaps should throw an exception but platformContext isn't available + // here. + return jsi::Value::undefined(); + } + auto propName = arguments[0].asString(runtime).utf8(runtime); + const jsi::Value &propValue = arguments[1]; + + // Enumerate all props with this name and update. The + // enumerateMappedPropsByName function is thread safe and locks props so it + // can be called from all threads. + _propsContainer->enumerateMappedPropsByName(propName, [&](NodeProp *prop) { + prop->updateValue(runtime, propValue); + }); + + return jsi::Value::undefined(); + } /** JS Function to be called when the node is no longer part of the reconciler tree. Use for cleaning up. */ JSI_HOST_FUNCTION(dispose) { - dispose(); + dispose(false); return jsi::Value::undefined(); } @@ -183,7 +216,7 @@ class JsiDomNode : public JsiHostObject, Returns the class of node so that we can do loops faster without having to check using runtime type information */ - virtual JsiDomNodeClass getNodeClass() = 0; + NodeClass getNodeClass() { return _nodeClass; } /** Updates any pending property changes in all nodes and child nodes. This @@ -205,11 +238,6 @@ class JsiDomNode : public JsiHostObject, op(); } - // If there are any ops here we should invalidate the cached context - if (_queuedNodeOps.size() > 0) { - invalidateContext(); - } - _queuedNodeOps.clear(); } @@ -230,36 +258,9 @@ class JsiDomNode : public JsiHostObject, _propsContainer->markAsResolved(); } - // Now let's dispose if needed + // Now let's invalidate if needed if (_isDisposing && !_isDisposed) { - _isDisposed = true; - - this->setParent(nullptr); - - // Callback signaling that we're done - if (_disposeCallback != nullptr) { - _disposeCallback(); - _disposeCallback = nullptr; - } - - // Clear props - if (_propsContainer != nullptr) { - _propsContainer->dispose(); - } - - // Remove children - std::vector> tmp; - { - std::lock_guard lock(_childrenLock); - tmp.reserve(_children.size()); - for (auto &child : _children) { - tmp.push_back(child); - } - _children.clear(); - } - for (auto &child : tmp) { - child->dispose(); - } + invalidate(); } // Resolve children @@ -268,7 +269,37 @@ class JsiDomNode : public JsiHostObject, } } + /** + Empty implementation of the decorate context method + */ + virtual void decorateContext(DeclarationContext *context) { + // Empty implementation + } + + /** + Called when a node has been removed from the dom tree and needs to be cleaned + up. If the invalidate parameter is set, we will invalidate the node directly. + Calling dispose from the JS dispose function calls this with invalidate set + to false, while the dom render view calls this with true. + */ + virtual void dispose(bool immediate) { + if (_isDisposing) { + return; + } + _isDisposing = true; + if (immediate) { + invalidate(); + } + } + protected: + /** + Adds an operation that will be executed when the render cycle is finished. + */ + void enqueAsynOperation(std::function &&fp) { + std::lock_guard lock(_childrenLock); + _queuedNodeOps.push_back(std::move(fp)); + } /** Override to define properties in node implementations */ @@ -288,23 +319,17 @@ class JsiDomNode : public JsiHostObject, /** Native implementation of the set properties method. This is called from the - reconciler when properties are set due to changes in React. This method will - always call the onPropsSet method as a signal that things have changed. + reconciler when properties are set due to changes in React. */ - void setProps(jsi::Runtime &runtime, jsi::Object &&props) { + void setProps(jsi::Runtime &runtime, const jsi::Value &maybeProps) { #if SKIA_DOM_DEBUG printDebugInfo("JS:setProps(nodeId: " + std::to_string(_nodeId) + ")"); #endif - if (_propsContainer == nullptr) { - - // Initialize properties container - _propsContainer = std::make_shared(getType()); + // Initialize properties container + ensurePropertyContainer(); - // Ask sub classes to define their properties - defineProperties(_propsContainer.get()); - } // Update properties container - _propsContainer->setProps(runtime, std::move(props)); + _propsContainer->setProps(runtime, maybeProps); // Invalidate context invalidateContext(); @@ -317,14 +342,8 @@ class JsiDomNode : public JsiHostObject, #if SKIA_DOM_DEBUG printDebugInfo("JS:setEmptyProps(nodeId: " + std::to_string(_nodeId) + ")"); #endif - if (_propsContainer == nullptr) { - - // Initialize properties container - _propsContainer = std::make_shared(getType()); - - // Ask sub classes to define their properties - defineProperties(_propsContainer.get()); - } + // Initialize properties container + ensurePropertyContainer(); } /** @@ -335,6 +354,11 @@ class JsiDomNode : public JsiHostObject, return _children; } + /** + Override to be notified when a node property has changed + */ + virtual void onPropertyChanged(BaseNodeProp *prop) {} + /** Adds a child node to the array of children for this node */ @@ -343,10 +367,12 @@ class JsiDomNode : public JsiHostObject, printDebugInfo("JS:addChild(childId: " + std::to_string(child->_nodeId) + ")"); #endif - std::lock_guard lock(_childrenLock); - _queuedNodeOps.push_back([child, this]() { - _children.push_back(child); - child->setParent(this); + enqueAsynOperation([child, weakSelf = weak_from_this()]() { + auto self = weakSelf.lock(); + if (self) { + self->_children.push_back(child); + child->setParent(self.get()); + } }); } @@ -361,11 +387,14 @@ class JsiDomNode : public JsiHostObject, "JS:insertChildBefore(childId: " + std::to_string(child->_nodeId) + ", beforeId: " + std::to_string(before->_nodeId) + ")"); #endif - std::lock_guard lock(_childrenLock); - _queuedNodeOps.push_back([child, before, this]() { - auto position = std::find(_children.begin(), _children.end(), before); - _children.insert(position, child); - child->setParent(this); + enqueAsynOperation([child, before, weakSelf = weak_from_this()]() { + auto self = weakSelf.lock(); + if (self) { + auto position = + std::find(self->_children.begin(), self->_children.end(), before); + self->_children.insert(position, child); + child->setParent(self.get()); + } }); } @@ -378,28 +407,25 @@ class JsiDomNode : public JsiHostObject, printDebugInfo("JS:removeChild(childId: " + std::to_string(child->_nodeId) + ")"); #endif - std::lock_guard lock(_childrenLock); - _queuedNodeOps.push_back([child, this]() { - // Delete child itself - _children.erase( - std::remove_if(_children.begin(), _children.end(), - [child](const auto &node) { return node == child; }), - _children.end()); - - child->dispose(); - }); - } + auto removeChild = [child, + weakSelf = weak_from_this()](bool immediate = false) { + auto self = weakSelf.lock(); + if (self) { + // Delete child itself + self->_children.erase( + std::remove_if(self->_children.begin(), self->_children.end(), + [child](const auto &node) { return node == child; }), + self->_children.end()); + + child->dispose(immediate); + } + }; - /** - Called when a node has been removed from the dom tree and needs to be cleaned - up. - */ - virtual void dispose() { if (_isDisposing) { - return; + removeChild(false); + } else { + enqueAsynOperation(removeChild); } - - _isDisposing = true; } #if SKIA_DOM_DEBUG @@ -429,7 +455,82 @@ class JsiDomNode : public JsiHostObject, */ JsiDomNode *getParent() { return _parent; } + /** + Loops through all declaration nodes and gives each one of them the + opportunity to decorate the context. + */ + void decorateChildren(DeclarationContext *context) { + for (auto &child : getChildren()) { + // All JsiDomNodes has the decorateContext method - but only the + // JsiDomDeclarationNode is actually doing stuff inside this method. + child->decorateContext(context); + } + } + private: + /** + Invalidates the node - meaning removing and clearing children and properties + **/ + void invalidate() { + if (_isDisposing && !_isDisposed) { +#if SKIA_DOM_DEBUG + printDebugInfo("JsiDomNode::invalidate: nodeid: " + + std::to_string(_nodeId)); +#endif + + _isDisposed = true; + + // Clear parent + this->setParent(nullptr); + + // Clear any async operations + _queuedNodeOps.clear(); + + // Callback signaling that we're done + if (_disposeCallback != nullptr) { + _disposeCallback(); + _disposeCallback = nullptr; + } + + // Clear props + if (_propsContainer != nullptr) { + _propsContainer->dispose(); + } + + // Remove children + std::vector> tmp; + { + std::lock_guard lock(_childrenLock); + tmp.reserve(_children.size()); + for (auto &child : _children) { + tmp.push_back(child); + } + _children.clear(); + } + for (auto &child : tmp) { + child->dispose(true); + } + } + } + + /** + Creates and sets up the property container + */ + void ensurePropertyContainer() { + if (_propsContainer == nullptr) { + _propsContainer = std::make_shared( + getType(), [weakSelf = weak_from_this()](BaseNodeProp *p) { + auto self = weakSelf.lock(); + if (self) { + self->onPropertyChanged(p); + } + }); + + // Ask sub classes to define their properties + defineProperties(_propsContainer.get()); + } + } + const char *_type; std::shared_ptr _context; @@ -448,6 +549,8 @@ class JsiDomNode : public JsiHostObject, std::vector> _queuedNodeOps; JsiDomNode *_parent = nullptr; + + NodeClass _nodeClass; }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomRenderNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomRenderNode.h index e05274055b689..d811203a703be 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomRenderNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/JsiDomRenderNode.h @@ -15,6 +15,7 @@ #include #include +#include namespace RNSkia { @@ -22,17 +23,19 @@ class JsiDomRenderNode : public JsiDomNode { public: JsiDomRenderNode(std::shared_ptr context, const char *type) - : JsiDomNode(context, type) {} + : JsiDomNode(context, type, NodeClass::RenderNode) {} void render(DrawingContext *context) { #if SKIA_DOM_DEBUG printDebugInfo("Begin Render"); #endif - // Ensure we have a local drawing context inheriting from the parent context - if (_localContext == nullptr) { - _localContext = context->inheritContext(getType()); - } + auto parentPaint = context->getPaint(); + auto cache = + _paintCache.parent == parentPaint ? _paintCache.child : nullptr; + + auto shouldRestore = + context->saveAndConcat(_paintProps, getChildren(), cache); auto shouldTransform = _matrixProp->isSet() || _transformProp->isSet(); auto shouldSave = @@ -43,37 +46,36 @@ class JsiDomRenderNode : public JsiDomNode { // Save canvas state if (_layerProp->isSet()) { if (_layerProp->isBool()) { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->saveLayer()"); #endif - _localContext->getCanvas()->saveLayer( + context->getCanvas()->saveLayer( SkCanvas::SaveLayerRec(nullptr, nullptr, nullptr, 0)); } else { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->saveLayer(paint)"); #endif - _localContext->getCanvas()->saveLayer(SkCanvas::SaveLayerRec( + context->getCanvas()->saveLayer(SkCanvas::SaveLayerRec( nullptr, _layerProp->getDerivedValue().get(), nullptr, 0)); } } else { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->save()"); #endif - _localContext->getCanvas()->save(); + context->getCanvas()->save(); } if (_originProp->isSet()) { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->translate(origin)"); #endif // Handle origin - _localContext->getCanvas()->translate( - _originProp->getDerivedValue()->x(), - _originProp->getDerivedValue()->y()); + context->getCanvas()->translate(_originProp->getDerivedValue()->x(), + _originProp->getDerivedValue()->y()); } if (shouldTransform) { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo( "canvas->concat(" + std::string(_matrixProp->isSet() ? "matrix" : "transform") + @@ -83,43 +85,40 @@ class JsiDomRenderNode : public JsiDomNode { : _transformProp->getDerivedValue(); // Concat canvas' matrix with our matrix - _localContext->getCanvas()->concat(*matrix); + context->getCanvas()->concat(*matrix); } // Clipping if (_clipProp->isSet()) { auto invert = _invertClip->isSet() && _invertClip->value().getAsBool(); - clip(context, _localContext->getCanvas(), invert); + clip(context, context->getCanvas(), invert); } if (_originProp->isSet()) { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->translate(-origin)"); #endif // Handle origin - _localContext->getCanvas()->translate( - -_originProp->getDerivedValue()->x(), - -_originProp->getDerivedValue()->y()); + context->getCanvas()->translate(-_originProp->getDerivedValue()->x(), + -_originProp->getDerivedValue()->y()); } } - // Let any local paint props decorate the context - _paintProps->decorate(_localContext.get()); - - // Now let's make sure the local context is resolved correctly - ie. that - // all children of type declaration (except paint) is given the opportunity - // to decorate the context. - materializeDeclarations(); - // Render the node - renderNode(_localContext.get()); + renderNode(context); // Restore if needed if (shouldSave) { -#if SKIA_DOM_DEBUG +#if SKIA_DOM_DEBUG_VERBOSE printDebugInfo("canvas->restore()"); #endif - _localContext->getCanvas()->restore(); + context->getCanvas()->restore(); + } + + if (shouldRestore) { + _paintCache.parent = parentPaint; + _paintCache.child = context->getPaint(); + context->restore(); } #if SKIA_DOM_DEBUG @@ -131,26 +130,14 @@ class JsiDomRenderNode : public JsiDomNode { Override reset (last thing that happens in the render cycle) to also reset the changed flag on the local drawing context if necessary. */ - void resetPendingChanges() override { - JsiDomNode::resetPendingChanges(); - _localContext->resetChangedFlag(); - } + void resetPendingChanges() override { JsiDomNode::resetPendingChanges(); } /** - Signal from the JS side that the node is removed from the dom. + Overridden dispose to release resources */ - void dispose() override { - JsiDomNode::dispose(); - - // Clear local drawing context - if (_localContext != nullptr) { - _localContext->dispose(); - _localContext = nullptr; - } - } - - JsiDomNodeClass getNodeClass() override { - return JsiDomNodeClass::RenderNode; + void dispose(bool immediate) override { + JsiDomNode::dispose(immediate); + _paintCache.clear(); } protected: @@ -158,9 +145,15 @@ class JsiDomRenderNode : public JsiDomNode { Invalidates and marks then context as changed. */ void invalidateContext() override { - if (_localContext != nullptr) { - _localContext->markAsChanged(); - } + enqueAsynOperation([weakSelf = weak_from_this()]() { + auto self = weakSelf.lock(); + if (self) { + std::static_pointer_cast(self)->_paintCache.parent = + nullptr; + std::static_pointer_cast(self)->_paintCache.child = + nullptr; + } + }); } /** @@ -185,6 +178,43 @@ class JsiDomRenderNode : public JsiDomNode { _layerProp = container->defineProperty("layer"); } + /** + Validates that only declaration nodes can be children + */ + void addChild(std::shared_ptr child) override { + JsiDomNode::addChild(child); + _paintCache.parent = nullptr; + _paintCache.child = nullptr; + } + + /** + Validates that only declaration nodes can be children + */ + void insertChildBefore(std::shared_ptr child, + std::shared_ptr before) override { + JsiDomNode::insertChildBefore(child, before); + _paintCache.parent = nullptr; + _paintCache.child = nullptr; + } + + /** + A property changed + */ + void onPropertyChanged(BaseNodeProp *prop) override { + static std::vector paintProps = { + JsiPropId::get("color"), JsiPropId::get("strokeWidth"), + JsiPropId::get("blendMode"), JsiPropId::get("strokeCap"), + JsiPropId::get("strokeJoin"), JsiPropId::get("strokeMiter"), + JsiPropId::get("style"), JsiPropId::get("antiAlias"), + JsiPropId::get("opacity")}; + + // We'll invalidate paint if a prop change happened in a paint property + if (std::find(paintProps.begin(), paintProps.end(), prop->getName()) != + paintProps.end()) { + invalidateContext(); + } + } + private: /** Clips the canvas depending on the clip property @@ -209,18 +239,16 @@ class JsiDomRenderNode : public JsiDomNode { } } - /** - Loops through all declaration nodes and gives each one of them the - opportunity to decorate the context - */ - void materializeDeclarations() { - for (auto &child : getChildren()) { - if (child->getNodeClass() == JsiDomNodeClass::DeclarationNode) { - std::static_pointer_cast(child) - ->decorateContext(_localContext.get()); - } + struct PaintCache { + void clear() { + parent = nullptr; + child = nullptr; } - } + std::shared_ptr parent; + std::shared_ptr child; + }; + + PaintCache _paintCache; PointProp *_originProp; MatrixProp *_matrixProp; @@ -229,8 +257,6 @@ class JsiDomRenderNode : public JsiDomNode { ClipProp *_clipProp; LayerProp *_layerProp; PaintProps *_paintProps; - - std::shared_ptr _localContext; }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodeProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodeProp.h index 14a96b6f63966..e3df3bdd2f2cf 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodeProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodeProp.h @@ -5,6 +5,7 @@ #include #include +#include #include namespace RNSkia { @@ -19,8 +20,9 @@ class NodeProp : public BaseNodeProp, /** Constructs a new optional dom node properrty */ - explicit NodeProp(const std::string &name) - : _name(JsiPropId::get(name)), BaseNodeProp() {} + explicit NodeProp(const std::string &name, + const std::function &onChange) + : _name(JsiPropId::get(name)), _onChange(onChange), BaseNodeProp() {} /** Reads JS value and swaps out with a new value @@ -31,7 +33,7 @@ class NodeProp : public BaseNodeProp, // readValueFromJS Function (which comes from the reconciler // setting a new property value on the property if (_value == nullptr) { - _value = std::make_shared(runtime, read(runtime, _name, this)); + _value = std::make_unique(runtime, read(runtime, _name, this)); _isChanged = true; _hasNewValue = false; } else { @@ -39,11 +41,14 @@ class NodeProp : public BaseNodeProp, std::lock_guard lock(_swapMutex); if (_buffer == nullptr) { _buffer = - std::make_shared(runtime, read(runtime, _name, this)); + std::make_unique(runtime, read(runtime, _name, this)); } else { _buffer->setCurrent(runtime, read(runtime, _name, this)); } _hasNewValue = *_buffer.get() != *_value.get(); + if (_hasNewValue && _onChange != nullptr) { + _onChange(this); + } } } @@ -55,13 +60,16 @@ class NodeProp : public BaseNodeProp, // and we don't want to rip out the underlying value object. std::lock_guard lock(_swapMutex); if (_buffer == nullptr) { - _buffer = std::make_shared(runtime, value); + _buffer = std::make_unique(runtime, value); } else { _buffer->setCurrent(runtime, value); } // This is almost always a change - meaning a swap is // cheaper than comparing for equality. _hasNewValue = true; + if (_onChange != nullptr) { + _onChange(this); + } } /** @@ -119,8 +127,10 @@ class NodeProp : public BaseNodeProp, private: PropId _name; - std::shared_ptr _value; - std::shared_ptr _buffer; + std::function _onChange; + + std::unique_ptr _value; + std::unique_ptr _buffer; std::atomic _isChanged = {false}; std::atomic _hasNewValue = {false}; std::mutex _swapMutex; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodePropsContainer.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodePropsContainer.h index fbed8060c7b50..7348276ea40b2 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodePropsContainer.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/base/NodePropsContainer.h @@ -20,11 +20,12 @@ namespace RNSkia { class NodePropsContainer { public: /** - Constructor. Pass the runtime and the JS object representing the properties, - and a function that will be called when any property was changed from within - this class as a result of a Skia value change. + Constructor for the node prop container */ - explicit NodePropsContainer(PropId componentType) : _type(componentType) {} + explicit NodePropsContainer( + PropId componentType, + const std::function &onPropChanged) + : _onPropChanged(onPropChanged), _type(componentType) {} /** Returns true if there are any changes in the props container in the current @@ -40,10 +41,30 @@ class NodePropsContainer { } /** - Returns a list of mappings betwen property names and property objects + Enumerate all mapped properties */ - const std::map> &getMappedProperties() { - return _mappedProperties; + void enumerateMappedProps( + const std::function)> &callback) { + std::lock_guard lock(_mappedPropsLock); + for (auto &props : _mappedProperties) { + callback(props.first, props.second); + } + } + + /** + Enumerates a named property instances from the mapped properties list + */ + void + enumerateMappedPropsByName(const std::string &name, + const std::function &callback) { + std::lock_guard lock(_mappedPropsLock); + auto propMapIt = _mappedProperties.find(JsiPropId::get(name)); + if (propMapIt != _mappedProperties.end()) { + for (auto &prop : propMapIt->second) { + callback(prop); + } + } } /** @@ -53,7 +74,7 @@ class NodePropsContainer { void updatePendingValues() { for (auto &prop : _properties) { prop->updatePendingChanges(); - if (!prop->isSet() && prop->isRequired()) { + if (prop->isRequired() && !prop->isSet()) { throw std::runtime_error("Missing one or more required properties " + std::string(prop->getName()) + " in the " + _type + " component."); @@ -74,6 +95,7 @@ class NodePropsContainer { Clears all props and data from the container */ void dispose() { + std::lock_guard lock(_mappedPropsLock); _properties.clear(); _mappedProperties.clear(); } @@ -81,10 +103,18 @@ class NodePropsContainer { /** Called when the React / JS side sets properties on a node */ - void setProps(jsi::Runtime &runtime, jsi::Object &&props) { + void setProps(jsi::Runtime &runtime, const jsi::Value &maybePropsObject) { + std::lock_guard lock(_mappedPropsLock); + // Clear property mapping _mappedProperties.clear(); + if (!maybePropsObject.isObject()) { + throw jsi::JSError(runtime, "Expected property object."); + } + + auto props = maybePropsObject.asObject(runtime); + // Use specialized reader function to be able to intercept calls that // reads specific named values from the js property object. auto read = [&](jsi::Runtime &runtime, PropId name, NodeProp *prop) { @@ -102,28 +132,27 @@ class NodePropsContainer { } /** - Defines a property that will be updated with the container changes. - */ - template - T *defineProperty(std::shared_ptr prop) { - _properties.push_back(prop); - return prop.get(); - } - - /** - Defines a property that will be updated with the container changes. + Defines a property that will be added to the container */ template ::value>> + class = std::enable_if_t::value>> _Tp *defineProperty(_Args &&...__args) { - return defineProperty( - std::make_shared<_Tp>(std::forward<_Args>(__args)...)); + // Create property and set onChange callback + auto prop = + std::make_shared<_Tp>(std::forward<_Args>(__args)..., _onPropChanged); + + // Add to props list + _properties.push_back(prop); + + return prop.get(); } private: + std::function _onPropChanged; std::vector> _properties; std::map> _mappedProperties; PropId _type; + std::mutex _mappedPropsLock; }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h index 119819530d59d..b176bc10f440a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h @@ -15,22 +15,33 @@ class JsiBackdropFilterNode : public JsiDomDrawingNode, protected: void draw(DrawingContext *context) override { - if (getChildren().size() == 0) { - throw std::runtime_error( - "Expected at least one child in the BackdropFilter node."); + auto children = getChildren(); + + if (children.size() == 0) { + return; } - auto child = getChildren()[0]; - auto colorFilter = std::dynamic_pointer_cast(child); - auto imageFilter = std::dynamic_pointer_cast(child); auto canvas = context->getCanvas(); - auto filter = - colorFilter != nullptr - ? SkImageFilters::ColorFilter(colorFilter->getCurrent(), nullptr) - : imageFilter->getCurrent(); + auto firstChild = children[0]; + sk_sp imageFilter; + + if (firstChild->getNodeClass() == NodeClass::DeclarationNode) { + context->getDeclarationContext()->save(); + firstChild->decorateContext(context->getDeclarationContext()); + auto imgF = context->getDeclarationContext()->getImageFilters()->pop(); + if (imgF) { + imageFilter = imgF; + } else { + auto cf = context->getDeclarationContext()->getColorFilters()->pop(); + if (cf) { + imageFilter = SkImageFilters::ColorFilter(cf, nullptr); + } + } + context->getDeclarationContext()->restore(); + } canvas->saveLayer( - SkCanvas::SaveLayerRec(nullptr, nullptr, filter.get(), 0)); + SkCanvas::SaveLayerRec(nullptr, nullptr, imageFilter.get(), 0)); canvas->restore(); } }; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlendNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlendNode.h index 970e02d433134..4dd6d8f6f5bd5 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlendNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlendNode.h @@ -2,74 +2,55 @@ #include "JsiDomDeclarationNode.h" +#include #include #include namespace RNSkia { -class JsiBlendNode : public JsiBaseDomDeclarationNode, +class JsiBlendNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiBlendNode(std::shared_ptr context) - : JsiBaseDomDeclarationNode(context, "skBlend") {} + : JsiDomDeclarationNode(context, "skBlend", + DeclarationType::ImageFilter) {} -protected: - void decorate(DrawingContext *context) override { - if (context->isChanged() || getPropsContainer()->isChanged()) { - auto children = getChildren(); - auto childSize = children.size(); - - // No need to do anything if there are no children here - if (childSize == 0) { - return; - } - - // Blend mode - auto blendMode = *_blendProp->getDerivedValue(); - - // Find the latest child and check if it is a shader or image filter - bool asShader = std::dynamic_pointer_cast( - children.at(childSize - 1)) != nullptr; - - // Traverse children in reverse - sk_sp innerShader; - sk_sp innerImageFilter; - - for (size_t i = childSize - 1; i != (std::size_t)-1; i--) { - auto child = children.at(i); - auto maybeShader = std::dynamic_pointer_cast(child); - auto maybeImageFilter = - std::dynamic_pointer_cast(child); - - if (maybeShader) { - sk_sp outer = maybeShader->getCurrent(); - if (innerShader != nullptr) { - innerShader = SkShaders::Blend(blendMode, outer, innerShader); - } else { - innerShader = outer; - } - } else if (maybeImageFilter) { - sk_sp outer = maybeImageFilter->getCurrent(); - if (outer != nullptr) { - innerImageFilter = SkImageFilters::Blend(blendMode, outer, - innerImageFilter, nullptr); - } else { - innerImageFilter = outer; - } - } - } - - // Materialize - if (asShader) { - context->getMutablePaint()->setShader(innerShader); - } else { - context->getMutablePaint()->setImageFilter(innerImageFilter); - } + void decorate(DeclarationContext *context) override { + + // No need to do anything if there are no children here + if (getChildren().size() == 0) { + return; + } + + decorateChildren(context); + + // Blend mode + auto blendMode = *_blendProp->getDerivedValue(); + + // Shader + auto shader = context->getShaders()->popAsOne( + [blendMode](sk_sp inner, sk_sp outer) { + return SkShaders::Blend(blendMode, outer, inner); + }); + + if (shader != nullptr) { + context->getShaders()->push(shader); + } + + auto imageFilter = + context->getImageFilters()->Declaration>::popAsOne( + [blendMode](sk_sp inner, + sk_sp outer) { + return SkImageFilters::Blend(blendMode, outer, inner); + }); + if (imageFilter != nullptr) { + context->getImageFilters()->push(imageFilter); } } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _blendProp = container->defineProperty("mode"); _blendProp->require(); } @@ -78,7 +59,7 @@ class JsiBlendNode : public JsiBaseDomDeclarationNode, Validates that only declaration nodes can be children */ void addChild(std::shared_ptr child) override { - JsiBaseDomDeclarationNode::addChild(child); + JsiDomDeclarationNode::addChild(child); // Verify declaration of either shader or image filter verifyChild(child); } @@ -88,15 +69,18 @@ class JsiBlendNode : public JsiBaseDomDeclarationNode, */ void insertChildBefore(std::shared_ptr child, std::shared_ptr before) override { - JsiBaseDomDeclarationNode::insertChildBefore(child, before); + JsiDomDeclarationNode::insertChildBefore(child, before); // Verify declaration of either shader or image filter verifyChild(child); } private: void verifyChild(std::shared_ptr child) { - if (std::dynamic_pointer_cast(child) == nullptr && - std::dynamic_pointer_cast(child) == nullptr) { + if (child->getNodeClass() != NodeClass::DeclarationNode || + (std::static_pointer_cast(child) + ->getDeclarationType() != DeclarationType::Shader && + std::static_pointer_cast(child) + ->getDeclarationType() != DeclarationType::ImageFilter)) { // We'll raise an error when other children are added. std::runtime_error("Blend nodes only supports either shaders or image " "filters as children, got " + diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h index c6500f09dbc77..e98b29e4c60ce 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h @@ -10,39 +10,39 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkBlurTypes.h" +#include "SkMaskFilter.h" #pragma clang diagnostic pop namespace RNSkia { -class JsiBlurMaskNode : public JsiBaseDomDeclarationNode, +class JsiBlurMaskNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiBlurMaskNode(std::shared_ptr context) - : JsiBaseDomDeclarationNode(context, "skBlurMaskFilter") {} + : JsiDomDeclarationNode(context, "skBlurMaskFilter", + DeclarationType::MaskFilter) {} -protected: - void decorate(DrawingContext *context) override { - if (context->isChanged() || getPropsContainer()->isChanged()) { + void decorate(DeclarationContext *context) override { - bool respectCTM = - _respectCTM->isSet() ? _respectCTM->value().getAsBool() : true; - SkBlurStyle style = SkBlurStyle::kNormal_SkBlurStyle; - if (_style->isSet()) { - style = getBlurStyleFromString(_style->value().getAsString()); - } + bool respectCTM = + _respectCTM->isSet() ? _respectCTM->value().getAsBool() : true; + SkBlurStyle style = SkBlurStyle::kNormal_SkBlurStyle; + if (_style->isSet()) { + style = getBlurStyleFromString(_style->value().getAsString()); + } - auto filter = SkMaskFilter::MakeBlur(style, _blur->value().getAsNumber(), - respectCTM); + auto filter = + SkMaskFilter::MakeBlur(style, _blur->value().getAsNumber(), respectCTM); - // Set the mask filter - context->getMutablePaint()->setMaskFilter(filter); - } + // Set the mask filter + context->getMaskFilters()->push(filter); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _style = container->defineProperty("style"); _respectCTM = container->defineProperty("respectCTM"); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h index cfbb0bf687096..b3d97160963dc 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h @@ -7,21 +7,22 @@ namespace RNSkia { -class JsiBoxShadowNode : public JsiBaseDomDeclarationNode, +class JsiBoxShadowNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiBoxShadowNode(std::shared_ptr context) - : JsiBaseDomDeclarationNode(context, "skBoxShadow") {} + : JsiDomDeclarationNode(context, "skBoxShadow", + DeclarationType::Unknown) {} BoxShadowProps *getBoxShadowProps() { return _boxShadowProps; } -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { // Do nothing, we are just a container for properties } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _boxShadowProps = container->defineProperty(); } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h index 61cae14ce2178..bef1c97472bc9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h @@ -11,45 +11,26 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkColorFilter.h" #pragma clang diagnostic pop namespace RNSkia { -class JsiBaseColorFilterNode - : public JsiDomDeclarationNode> { +class JsiBaseColorFilterNode : public JsiDomDeclarationNode { public: JsiBaseColorFilterNode(std::shared_ptr context, const char *type) - : JsiDomDeclarationNode>( - context, type) {} + : JsiDomDeclarationNode(context, type, DeclarationType::ColorFilter) {} protected: - sk_sp resolve(std::shared_ptr child) override { - auto ptr = std::dynamic_pointer_cast(child); - if (ptr) { - return ptr->getCurrent(); - } - return nullptr; - } - - void setColorFilter(DrawingContext *context, sk_sp f) { - set(context, f); - } - - void set(DrawingContext *context, sk_sp ColorFilter) override { - auto paint = context->getMutablePaint(); - if (paint->getColorFilter() != nullptr && - paint->getColorFilter() != getCurrent().get()) { - paint->setColorFilter( - SkColorFilters::Compose(ColorFilter, paint->refColorFilter())); - } else { - paint->setColorFilter(ColorFilter); - } - - setCurrent(ColorFilter); + void composeAndPush(DeclarationContext *context, sk_sp cf1) { + context->save(); + decorateChildren(context); + auto cf2 = context->getColorFilters()->popAsOne(); + context->restore(); + auto cf = cf2 ? SkColorFilters::Compose(cf1, cf2) : cf1; + context->getColorFilters()->push(cf); } }; @@ -61,22 +42,20 @@ class JsiMatrixColorFilterNode std::shared_ptr context) : JsiBaseColorFilterNode(context, "skMatrixColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto array = _matrixProp->value().getAsArray(); - float matrix[20]; - for (int i = 0; i < 20; i++) { - if (array.size() > i) { - matrix[i] = array[i].getAsNumber(); - } + void decorate(DeclarationContext *context) override { + auto array = _matrixProp->value().getAsArray(); + float matrix[20]; + for (int i = 0; i < 20; i++) { + if (array.size() > i) { + matrix[i] = array[i].getAsNumber(); } - setColorFilter(context, SkColorFilters::Matrix(matrix)); } + composeAndPush(context, SkColorFilters::Matrix(matrix)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _matrixProp = container->defineProperty("matrix"); _matrixProp->require(); } @@ -91,17 +70,15 @@ class JsiBlendColorFilterNode : public JsiBaseColorFilterNode, explicit JsiBlendColorFilterNode(std::shared_ptr context) : JsiBaseColorFilterNode(context, "skBlendColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - setColorFilter(context, - SkColorFilters::Blend(*_colorProp->getDerivedValue(), - *_blendModeProp->getDerivedValue())); - } + void decorate(DeclarationContext *context) override { + auto color = _colorProp->getDerivedValue(); + auto mode = _blendModeProp->getDerivedValue(); + composeAndPush(context, SkColorFilters::Blend(*color, *mode)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _blendModeProp = container->defineProperty("mode"); _colorProp = container->defineProperty("color"); @@ -122,11 +99,8 @@ class JsiLinearToSRGBGammaColorFilterNode std::shared_ptr context) : JsiBaseColorFilterNode(context, "skLinearToSRGBGammaColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - setColorFilter(context, SkColorFilters::LinearToSRGBGamma()); - } + void decorate(DeclarationContext *context) override { + composeAndPush(context, SkColorFilters::LinearToSRGBGamma()); } }; @@ -138,11 +112,8 @@ class JsiSRGBToLinearGammaColorFilterNode std::shared_ptr context) : JsiBaseColorFilterNode(context, "skSRGBToLinearGammaColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - setColorFilter(context, SkColorFilters::SRGBToLinearGamma()); - } + void decorate(DeclarationContext *context) override { + composeAndPush(context, SkColorFilters::SRGBToLinearGamma()); } }; @@ -152,11 +123,8 @@ class JsiLumaColorFilterNode : public JsiBaseColorFilterNode, explicit JsiLumaColorFilterNode(std::shared_ptr context) : JsiBaseColorFilterNode(context, "skLumaColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - setColorFilter(context, SkLumaColorFilter::Make()); - } + void decorate(DeclarationContext *context) override { + composeAndPush(context, SkLumaColorFilter::Make()); } }; @@ -166,17 +134,25 @@ class JsiLerpColorFilterNode : public JsiBaseColorFilterNode, explicit JsiLerpColorFilterNode(std::shared_ptr context) : JsiBaseColorFilterNode(context, "skLerpColorFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - setColorFilter(context, - SkColorFilters::Lerp(_tProp->value().getAsNumber(), - requireChild(0), requireChild(1))); + void decorate(DeclarationContext *context) override { + context->save(); + decorateChildren(context); + auto second = context->getColorFilters()->pop(); + auto first = context->getColorFilters()->pop(); + context->restore(); + + if (first == nullptr || second == nullptr) { + throw std::runtime_error( + "LerpColorFilterNode: missing two color filters as children"); } + + auto t = _tProp->value().getAsNumber(); + context->getColorFilters()->push(SkColorFilters::Lerp(t, first, second)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _tProp = container->defineProperty("t"); _tProp->require(); } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGlyphsNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGlyphsNode.h index 5397d6b4048b9..a54a6e3840789 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGlyphsNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGlyphsNode.h @@ -20,12 +20,14 @@ class JsiGlyphsNode : public JsiDomDrawingNode, auto x = _xProp->value().getAsNumber(); auto y = _yProp->value().getAsNumber(); auto font = _fontProp->getDerivedValue(); - auto glyphInfo = _glyphsProp->getDerivedValue(); - - context->getCanvas()->drawGlyphs( - static_cast(glyphInfo->glyphIds.size()), - glyphInfo->glyphIds.data(), glyphInfo->positions.data(), - SkPoint::Make(x, y), *font, *context->getPaint()); + if (font != nullptr) { + auto glyphInfo = _glyphsProp->getDerivedValue(); + + context->getCanvas()->drawGlyphs( + static_cast(glyphInfo->glyphIds.size()), + glyphInfo->glyphIds.data(), glyphInfo->positions.data(), + SkPoint::Make(x, y), *font, *context->getPaint()); + } } void defineProperties(NodePropsContainer *container) override { @@ -36,7 +38,6 @@ class JsiGlyphsNode : public JsiDomDrawingNode, _xProp = container->defineProperty("x"); _yProp = container->defineProperty("y"); - _fontProp->require(); _glyphsProp->require(); _xProp->require(); _yProp->require(); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGroupNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGroupNode.h index 55e4249c60ccf..0d42adb0a7e11 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGroupNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiGroupNode.h @@ -15,7 +15,7 @@ class JsiGroupNode : public JsiDomRenderNode, void renderNode(DrawingContext *context) override { for (auto &child : getChildren()) { - if (child->getNodeClass() == JsiDomNodeClass::RenderNode) { + if (child->getNodeClass() == NodeClass::RenderNode) { std::static_pointer_cast(child)->render(context); } } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h index 8a29549617878..7273a5b7987da 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h @@ -16,55 +16,33 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkImageFilter.h" #pragma clang diagnostic pop namespace RNSkia { -class JsiBaseImageFilterNode - : public JsiDomDeclarationNode> { +class JsiBaseImageFilterNode : public JsiDomDeclarationNode { public: JsiBaseImageFilterNode(std::shared_ptr context, const char *type) - : JsiDomDeclarationNode>( - context, type) {} + : JsiDomDeclarationNode(context, type, DeclarationType::ImageFilter) {} protected: - sk_sp resolve(std::shared_ptr child) override { - auto imageFilterPtr = - std::dynamic_pointer_cast(child); - if (imageFilterPtr) { - return imageFilterPtr->getCurrent(); + void composeAndPush(DeclarationContext *context, sk_sp imgf1) { + context->save(); + decorateChildren(context); + auto imgf2 = context->getImageFilters()->popAsOne(); + auto cf = context->getColorFilters()->popAsOne(); + context->restore(); + if (cf != nullptr) { + imgf2 = SkImageFilters::Compose(imgf2, + SkImageFilters::ColorFilter(cf, nullptr)); } - auto shaderPtr = std::dynamic_pointer_cast(child); - if (shaderPtr) { - return SkImageFilters::Shader(shaderPtr->getCurrent()); - } - auto colorFilterPtr = - std::dynamic_pointer_cast(child); - if (colorFilterPtr) { - return SkImageFilters::ColorFilter(colorFilterPtr->getCurrent(), nullptr); - } - return nullptr; - } + auto imgf = + imgf2 != nullptr ? SkImageFilters::Compose(imgf1, imgf2) : imgf1; - void setImageFilter(DrawingContext *context, sk_sp f) { - set(context, f); - } - - void set(DrawingContext *context, sk_sp imageFilter) override { - auto paint = context->getMutablePaint(); - if (paint->getImageFilter() != nullptr && - paint->getImageFilter() != getCurrent().get()) { - paint->setImageFilter( - SkImageFilters::Compose(paint->refImageFilter(), imageFilter)); - } else { - paint->setImageFilter(imageFilter); - } - - setCurrent(imageFilter); + context->getImageFilters()->push(imgf); } }; @@ -74,26 +52,23 @@ class JsiBlendImageFilterNode : public JsiBaseImageFilterNode, explicit JsiBlendImageFilterNode(std::shared_ptr context) : JsiBaseImageFilterNode(context, "skBlendImageFilter") {} -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { - if (isChanged(context)) { - - if (getChildren().size() != 2) { - throw std::runtime_error("Blend image filter needs two child nodes."); - } + if (getChildren().size() != 2) { + throw std::runtime_error("Blend image filter needs two child nodes."); + } - auto background = requireChild(0); - auto foreground = requireChild(1); + auto background = context->getImageFilters()->pop(); + auto foreground = context->getImageFilters()->pop(); - SkBlendMode blendMode = *_blendModeProp->getDerivedValue(); - setImageFilter(context, - SkImageFilters::Blend(blendMode, background, foreground)); - } + SkBlendMode blendMode = *_blendModeProp->getDerivedValue(); + composeAndPush(context, + SkImageFilters::Blend(blendMode, background, foreground)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _blendModeProp = container->defineProperty("mode"); _blendModeProp->require(); } @@ -110,49 +85,50 @@ class JsiDropShadowImageFilterNode std::shared_ptr context) : JsiBaseImageFilterNode(context, "skDropShadowImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto color = _colorProp->getDerivedValue(); - auto dx = _dxProp->value().getAsNumber(); - auto dy = _dxProp->value().getAsNumber(); - auto blur = _blurProp->value().getAsNumber(); - auto input = optionalChild(0); - - auto inner = _innerProp->isSet() && _innerProp->value().getAsBool(); - auto shadowOnly = - _shadowOnlyProp->isSet() && _shadowOnlyProp->value().getAsBool(); - - if (inner) { - auto srcGraphic = SkImageFilters::ColorFilter( - SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kDst), nullptr); - auto srcAlpha = SkImageFilters::ColorFilter( - SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kSrcIn), nullptr); - auto f1 = SkImageFilters::ColorFilter( - SkColorFilters::Blend(*color, SkBlendMode::kSrcOut), nullptr); - auto f2 = SkImageFilters::Offset(dx, dy, f1); - auto f3 = SkImageFilters::Blur(blur, blur, SkTileMode::kDecal, f2); - auto f4 = SkImageFilters::Blend(SkBlendMode::kSrcIn, srcAlpha, f3); - - setImageFilter(context, SkImageFilters::Compose( + void decorate(DeclarationContext *context) override { + + auto color = _colorProp->getDerivedValue(); + auto dx = _dxProp->value().getAsNumber(); + auto dy = _dyProp->value().getAsNumber(); + auto blur = _blurProp->value().getAsNumber(); + auto input = context->getImageFilters()->pop(); + + auto inner = _innerProp->isSet() && _innerProp->value().getAsBool(); + auto shadowOnly = + _shadowOnlyProp->isSet() && _shadowOnlyProp->value().getAsBool(); + + if (inner) { + auto srcGraphic = SkImageFilters::ColorFilter( + SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kDst), nullptr); + auto srcAlpha = SkImageFilters::ColorFilter( + SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kSrcIn), nullptr); + auto f1 = SkImageFilters::ColorFilter( + SkColorFilters::Blend(*color, SkBlendMode::kSrcOut), nullptr); + auto f2 = SkImageFilters::Offset(dx, dy, f1); + auto f3 = SkImageFilters::Blur(blur, blur, SkTileMode::kDecal, f2); + auto f4 = SkImageFilters::Blend(SkBlendMode::kSrcIn, srcAlpha, f3); + if (shadowOnly) { + composeAndPush(context, f4); + } else { + composeAndPush(context, SkImageFilters::Compose( input ? input : nullptr, SkImageFilters::Blend(SkBlendMode::kSrcOver, srcGraphic, f4))); - - } else { - setImageFilter( - context, - shadowOnly - ? SkImageFilters::DropShadowOnly(dx, dy, blur, blur, *color, - input ? input : nullptr) - : SkImageFilters::DropShadow(dx, dy, blur, blur, *color, - input ? input : nullptr)); } + + } else { + composeAndPush( + context, + shadowOnly ? SkImageFilters::DropShadowOnly( + dx, dy, blur, blur, *color, input ? input : nullptr) + : SkImageFilters::DropShadow(dx, dy, blur, blur, *color, + input ? input : nullptr)); } } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _dxProp = container->defineProperty("dx"); _dyProp = container->defineProperty("dy"); _blurProp = container->defineProperty("blur"); @@ -184,27 +160,27 @@ class JsiDisplacementMapImageFilterNode std::shared_ptr context) : JsiBaseImageFilterNode(context, "skDisplacementMapImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - - auto channelX = - getColorChannelFromStringValue(_channelXProp->value().getAsString()); - auto channelY = - getColorChannelFromStringValue(_channelYProp->value().getAsString()); - auto scale = _scaleProp->value().getAsNumber(); - - auto displacement = requireChild(0); - auto color = optionalChild(1); - - setImageFilter(context, SkImageFilters::DisplacementMap( - channelX, channelY, scale, displacement, - color ? color : nullptr)); + void decorate(DeclarationContext *context) override { + decorateChildren(context); + auto channelX = + getColorChannelFromStringValue(_channelXProp->value().getAsString()); + auto channelY = + getColorChannelFromStringValue(_channelYProp->value().getAsString()); + auto scale = _scaleProp->value().getAsNumber(); + auto shader = context->getShaders()->pop(); + if (!shader) { + throw std::runtime_error("DisplacementMap expects a shader as child"); } + auto map = SkImageFilters::Shader(shader); + auto input = context->getImageFilters()->pop(); + auto imgf = SkImageFilters::DisplacementMap(channelX, channelY, scale, map, + input ? input : nullptr); + context->getImageFilters()->push(imgf); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _channelXProp = container->defineProperty("channelX"); _channelYProp = container->defineProperty("channelY"); _scaleProp = container->defineProperty("scale"); @@ -240,22 +216,19 @@ class JsiBlurImageFilterNode : public JsiBaseImageFilterNode, explicit JsiBlurImageFilterNode(std::shared_ptr context) : JsiBaseImageFilterNode(context, "skBlurImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto input = optionalChild(0); - setImageFilter( - context, SkImageFilters::Blur(_blurProp->getDerivedValue()->x(), - _blurProp->getDerivedValue()->y(), - _tileModeProp->isSet() - ? *_tileModeProp->getDerivedValue() - : SkTileMode::kDecal, - input ? input : nullptr)); - } + void decorate(DeclarationContext *context) override { + auto input = context->getImageFilters()->pop(); + auto imageFilter = SkImageFilters::Blur( + _blurProp->getDerivedValue()->x(), _blurProp->getDerivedValue()->y(), + _tileModeProp->isSet() ? *_tileModeProp->getDerivedValue() + : SkTileMode::kDecal, + input); + composeAndPush(context, imageFilter); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _blurProp = container->defineProperty("blur"); _tileModeProp = container->defineProperty("mode"); @@ -275,21 +248,18 @@ class JsiOffsetImageFilterNode std::shared_ptr context) : JsiBaseImageFilterNode(context, "skOffsetImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto input = optionalChild(0); - if (getPropsContainer()->isChanged()) { - setImageFilter(context, - SkImageFilters::Offset(_xProp->value().getAsNumber(), - _yProp->value().getAsNumber(), - input ? input : nullptr)); - } - } + void decorate(DeclarationContext *context) override { + decorateChildren(context); + auto input = context->getImageFilters()->pop(); + composeAndPush(context, + SkImageFilters::Offset(_xProp->value().getAsNumber(), + _yProp->value().getAsNumber(), + input ? input : nullptr)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _xProp = container->defineProperty("x"); _yProp = container->defineProperty("y"); @@ -312,26 +282,23 @@ class JsiMorphologyImageFilterNode std::shared_ptr context) : JsiBaseImageFilterNode(context, "skMorphologyImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto op = getTypeFromStringValue(_operatorProp->value().getAsString()); - auto radius = _radiusProp->getDerivedValue(); - auto input = optionalChild(0); - - if (op == Type::Dilate) { - setImageFilter(context, - SkImageFilters::Dilate(radius->x(), radius->y(), - input ? input : nullptr)); - } else { - setImageFilter(context, SkImageFilters::Erode(radius->x(), radius->y(), - input ? input : nullptr)); - } + void decorate(DeclarationContext *context) override { + auto op = getTypeFromStringValue(_operatorProp->value().getAsString()); + auto radius = _radiusProp->getDerivedValue(); + auto input = context->getImageFilters()->pop(); + + if (op == Type::Dilate) { + composeAndPush(context, SkImageFilters::Dilate(radius->x(), radius->y(), + input ? input : nullptr)); + } else { + composeAndPush(context, SkImageFilters::Erode(radius->x(), radius->y(), + input ? input : nullptr)); } } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _operatorProp = container->defineProperty("operator"); _radiusProp = container->defineProperty("radius"); @@ -362,26 +329,23 @@ class JsiRuntimeShaderImageFilterNode std::shared_ptr context) : JsiBaseImageFilterNode(context, "skRuntimeShaderImageFilter") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto source = _sourceProp->value().getAs(); - if (source == nullptr) { - throw std::runtime_error("Expected runtime effect when reading source " - "property of RuntimeEffectImageFilter."); - } + void decorate(DeclarationContext *context) override { + auto source = _sourceProp->value().getAs(); + if (source == nullptr) { + throw std::runtime_error("Expected runtime effect when reading source " + "property of RuntimeEffectImageFilter."); + } - auto builder = SkRuntimeShaderBuilder(source->getObject()); - auto input = optionalChild(0); - _uniformsProp->processUniforms(builder); + auto builder = SkRuntimeShaderBuilder(source->getObject()); + auto input = context->getImageFilters()->pop(); + _uniformsProp->processUniforms(builder); - setImageFilter(context, - SkImageFilters::RuntimeShader(builder, "", input)); - } + composeAndPush(context, SkImageFilters::RuntimeShader(builder, "", input)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _sourceProp = container->defineProperty("source"); _uniformsProp = container->defineProperty("uniforms", _sourceProp); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageNode.h index cf18ce1fc93a0..46d6a2943fd1d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageNode.h @@ -16,15 +16,19 @@ class JsiImageNode : public JsiDomDrawingNode, protected: void draw(DrawingContext *context) override { auto rects = _imageProps->getDerivedValue(); + auto image = _imageProps->getImage(); + if (image == nullptr) { + return; + } + context->getCanvas()->drawImageRect( - _imageProps->getImage(), rects->src, rects->dst, SkSamplingOptions(), + image, rects->src, rects->dst, SkSamplingOptions(), context->getPaint().get(), SkCanvas::kStrict_SrcRectConstraint); } void defineProperties(NodePropsContainer *container) override { JsiDomDrawingNode::defineProperties(container); _imageProps = container->defineProperty(); - _imageProps->require(); } private: diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageSvgNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageSvgNode.h index 4589c63457fbb..1b207807263ff 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageSvgNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiImageSvgNode.h @@ -17,26 +17,47 @@ class JsiImageSvgNode : public JsiDomDrawingNode, protected: void draw(DrawingContext *context) override { auto svgDom = _svgDomProp->getDerivedValue(); - auto rect = _rectProp->getDerivedValue(); - - context->getCanvas()->save(); - context->getCanvas()->translate(rect->x(), rect->y()); - svgDom->setContainerSize(SkSize::Make(rect->width(), rect->height())); - svgDom->render(context->getCanvas()); - context->getCanvas()->restore(); + if (svgDom != nullptr) { + auto rect = _rectProp->getDerivedValue(); + auto x = _xProp->isSet() ? _xProp->value().getAsNumber() : -1; + auto y = _yProp->isSet() ? _yProp->value().getAsNumber() : -1; + auto width = _widthProp->isSet() ? _widthProp->value().getAsNumber() : -1; + auto height = + _widthProp->isSet() ? _heightProp->value().getAsNumber() : -1; + context->getCanvas()->save(); + if (rect != nullptr) { + context->getCanvas()->translate(rect->x(), rect->y()); + svgDom->setContainerSize(SkSize::Make(rect->width(), rect->height())); + } else { + if (x != -1 && y != -1) { + context->getCanvas()->translate(x, y); + } + if (width != -1 && height != -1) { + svgDom->setContainerSize(SkSize::Make(width, height)); + } + } + svgDom->render(context->getCanvas()); + context->getCanvas()->restore(); + } } void defineProperties(NodePropsContainer *container) override { JsiDomDrawingNode::defineProperties(container); _svgDomProp = container->defineProperty("svg"); _rectProp = container->defineProperty("rect"); - - _svgDomProp->require(); + _xProp = container->defineProperty("x"); + _yProp = container->defineProperty("y"); + _widthProp = container->defineProperty("width"); + _heightProp = container->defineProperty("height"); } private: SvgProp *_svgDomProp; RectProps *_rectProp; + NodeProp *_xProp; + NodeProp *_yProp; + NodeProp *_widthProp; + NodeProp *_heightProp; }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiLayerNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiLayerNode.h index 3405062e7c717..adc44060743ce 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiLayerNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiLayerNode.h @@ -18,38 +18,48 @@ class JsiLayerNode : public JsiDomRenderNode, protected: void renderNode(DrawingContext *context) override { - bool isLayer = false; + auto hasLayer = false; auto children = getChildren(); - auto size = children.size(); // Is the first children a layer? - for (size_t i = 0; i < size; ++i) { + for (size_t i = 0; i < children.size(); ++i) { if (i == 0) { // Check for paint node as layer - auto paintNode = - std::dynamic_pointer_cast(children.at(i)); + if (children.at(i)->getNodeClass() == NodeClass::DeclarationNode) { + auto declarationNode = + std::static_pointer_cast(children.at(i)); - if (paintNode != nullptr) { - // Yes, it is a paint node - which we can use as a layer. - isLayer = true; - // Save canvas with the paint node's paint! - context->getCanvas()->saveLayer(SkCanvas::SaveLayerRec( - nullptr, paintNode->getPaint().get(), nullptr, 0)); + if (declarationNode->getDeclarationType() == DeclarationType::Paint) { + // Yes, it is a paint node - which we can use as a layer. + auto declarationContext = context->getDeclarationContext(); + auto layerNode = + std::static_pointer_cast(children.at(i)); - continue; + // Save canvas with the paint node's paint! + declarationContext->save(); + layerNode->decorate(declarationContext); + auto paint = declarationContext->getPaints()->pop(); + declarationContext->restore(); + + if (paint) { + hasLayer = true; + context->getCanvas()->saveLayer( + SkCanvas::SaveLayerRec(nullptr, paint.get(), nullptr, 0)); + } + + continue; + } } } // Render rest of the children - auto renderNode = - std::dynamic_pointer_cast(children.at(i)); - - if (renderNode != nullptr) { - renderNode->render(context); + if (children.at(i)->getNodeClass() == NodeClass::RenderNode) { + std::static_pointer_cast(children.at(i)) + ->render(context); } } - if (isLayer) { + if (hasLayer) { context->getCanvas()->restore(); } } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPaintNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPaintNode.h index c40bbcdd9f40a..d967b7515c8b2 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPaintNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPaintNode.h @@ -7,72 +7,109 @@ namespace RNSkia { -// TODO: implement feature: A paint node has its own paint not inherited, -// and when found the drawing node should render an extra time for -// each paint node in its children. - -class JsiPaintNode : public JsiBaseDomDeclarationNode, +class JsiPaintNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiPaintNode(std::shared_ptr context) - : JsiBaseDomDeclarationNode(context, "skPaint") {} - - /** - Returns a pointer to the local paint context in the paint node. This is a - special case for declaration nodes since the Paint node has a bit different - semantic than other declaration nodes. - */ - DrawingContext *getDrawingContext() { return _localContext.get(); } - - /** - We need to override the decorate node call to avoid letting children - decorate before we have created our child context. - */ - void decorateContext(DrawingContext *context) override { - // A paint node should have its own local paint - if (_localContext == nullptr) { - _localContext = context->inheritContext("PaintNode"); + : JsiDomDeclarationNode(context, "skPaint", DeclarationType::Paint) {} + + void decorate(DeclarationContext *context) override { + auto paint = std::make_shared(); + paint->setAntiAlias(true); + + if (_paintProps->getOpacity()->isSet()) { + paint->setAlphaf(paint->getAlphaf() * + _paintProps->getOpacity()->value().getAsNumber()); + } + + if (_paintProps->getColor()->isSet()) { + auto currentOpacity = paint->getAlphaf(); + paint->setShader(nullptr); + paint->setColor(*_paintProps->getColor()->getDerivedValue()); + paint->setAlphaf(paint->getAlphaf() * currentOpacity); } - // ...and it should be a totally new paint, not inheriting from parent - // paint. - if (_localContext->isChanged()) { - auto paint = std::make_shared(); - paint->setAntiAlias(true); - _localContext->setMutablePaint(paint); + if (_paintProps->getStrokeWidth()->isSet()) { + paint->setStrokeWidth( + _paintProps->getStrokeWidth()->value().getAsNumber()); } - // Let's decorate paint props - _paintProps->decorate(_localContext.get()); + if (_paintProps->getBlendMode()->isSet()) { + paint->setBlendMode(*_paintProps->getBlendMode()->getDerivedValue()); + } - // Materialize children who will now only change the paint node's paint - for (auto &child : getChildren()) { - auto decl = std::dynamic_pointer_cast(child); - if (decl != nullptr) { - decl->decorateContext(_localContext.get()); + if (_paintProps->getStyle()->isSet()) { + auto styleValue = _paintProps->getStyle()->value().getAsString(); + if (styleValue == "stroke") { + paint->setStyle(SkPaint::Style::kStroke_Style); + } else if (styleValue == "fill") { + paint->setStyle(SkPaint::Style::kFill_Style); + } else { + throw std::runtime_error( + styleValue + " is not a valud value for the style property."); } } - } - std::shared_ptr getPaint() { - return _localContext->getPaint(); + if (_paintProps->getStrokeJoin()->isSet()) { + paint->setStrokeJoin(*_paintProps->getStrokeJoin()->getDerivedValue()); + } + + if (_paintProps->getStrokeCap()->isSet()) { + paint->setStrokeCap(*_paintProps->getStrokeCap()->getDerivedValue()); + } + + if (_paintProps->getStrokeMiter()->isSet()) { + paint->setStrokeMiter( + _paintProps->getStrokeMiter()->value().getAsNumber()); + } + + if (_paintProps->getAntiAlias()->isSet()) { + paint->setAntiAlias(_paintProps->getAntiAlias()->value().getAsBool()); + } + + context->save(); + decorateChildren(context); + + auto imageFilter = context->getImageFilters()->popAsOne(); + auto colorFilter = context->getColorFilters()->popAsOne(); + auto shader = context->getShaders()->pop(); + auto maskFilter = context->getMaskFilters()->pop(); + auto pathEffect = context->getPathEffects()->popAsOne(); + + context->restore(); + + if (imageFilter) { + paint->setImageFilter(imageFilter); + } + + if (colorFilter) { + paint->setColorFilter(colorFilter); + } + + if (shader) { + paint->setShader(shader); + } + + if (maskFilter) { + paint->setMaskFilter(maskFilter); + } + + if (pathEffect) { + paint->setPathEffect(pathEffect); + } + + context->getPaints()->push(paint); } protected: - void decorate(DrawingContext *context) override {} - void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _paintProps = container->defineProperty(); - _opacityProp = container->defineProperty("opacity"); } private: - NodeProp *_opacityProp; PaintProps *_paintProps; - - std::shared_ptr _localContext; }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h index 2de7d2b6c6ae1..d9d8b249c8a03 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h @@ -11,46 +11,26 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPathEffect.h" #pragma clang diagnostic pop namespace RNSkia { -class JsiBasePathEffectNode - : public JsiDomDeclarationNode> { +class JsiBasePathEffectNode : public JsiDomDeclarationNode { public: JsiBasePathEffectNode(std::shared_ptr context, const char *type) - : JsiDomDeclarationNode>( - context, type) {} + : JsiDomDeclarationNode(context, type, DeclarationType::PathEffect) {} protected: - void setPathEffect(DrawingContext *context, sk_sp f) { - set(context, f); - } - - sk_sp resolve(std::shared_ptr child) override { - auto ptr = std::dynamic_pointer_cast(child); - if (ptr) { - return ptr->getCurrent(); - } - return nullptr; - } - - /** - Sets or composes the path effect - */ - void set(DrawingContext *context, sk_sp pathEffect) override { - auto paint = context->getMutablePaint(); - if (paint->getPathEffect() != nullptr && - paint->getPathEffect() != getCurrent().get()) { - paint->setPathEffect( - SkPathEffect::MakeCompose(paint->refPathEffect(), pathEffect)); - } else { - paint->setPathEffect(pathEffect); - } - setCurrent(pathEffect); + void composeAndPush(DeclarationContext *context, sk_sp pe1) { + context->save(); + decorateChildren(context); + auto pe2 = context->getPathEffects()->popAsOne(); + context->restore(); + auto pe = pe2 ? SkPathEffect::MakeCompose(pe1, pe2) : pe1; + context->getPathEffects()->push(pe); } }; @@ -60,30 +40,28 @@ class JsiDashPathEffectNode : public JsiBasePathEffectNode, explicit JsiDashPathEffectNode(std::shared_ptr context) : JsiBasePathEffectNode(context, "skDashPathEffect") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { + void decorate(DeclarationContext *context) override { - // Phase - auto phase = _phase->isSet() ? _phase->value().getAsNumber() : 0; + // Phase + auto phase = _phase->isSet() ? _phase->value().getAsNumber() : 0; - // Copy intervals - std::vector intervals; - auto intervalsArray = _intervals->value().getAsArray(); - for (size_t i = 0; i < intervalsArray.size(); ++i) { - intervals.push_back(intervalsArray[i].getAsNumber()); - } + // Copy intervals + std::vector intervals; + auto intervalsArray = _intervals->value().getAsArray(); + for (size_t i = 0; i < intervalsArray.size(); ++i) { + intervals.push_back(intervalsArray[i].getAsNumber()); + } - // Create effect - auto pathEffect = SkDashPathEffect::Make( - intervals.data(), static_cast(intervals.size()), phase); + // Create effect + auto pathEffect = SkDashPathEffect::Make( + intervals.data(), static_cast(intervals.size()), phase); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _intervals = container->defineProperty("intervals"); _phase = container->defineProperty("phase"); @@ -104,22 +82,19 @@ class JsiDiscretePathEffectNode std::shared_ptr context) : JsiBasePathEffectNode(context, "skDiscretePathEffect") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - - // Create effect - auto pathEffect = - SkDiscretePathEffect::Make(_lengthProp->value().getAsNumber(), - _deviationProp->value().getAsNumber(), - _seedProp->value().getAsNumber()); + void decorate(DeclarationContext *context) override { + // Create effect + auto pathEffect = + SkDiscretePathEffect::Make(_lengthProp->value().getAsNumber(), + _deviationProp->value().getAsNumber(), + _seedProp->value().getAsNumber()); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _lengthProp = container->defineProperty("length"); _deviationProp = container->defineProperty("deviation"); @@ -142,19 +117,16 @@ class JsiCornerPathEffectNode : public JsiBasePathEffectNode, explicit JsiCornerPathEffectNode(std::shared_ptr context) : JsiBasePathEffectNode(context, "skCornerPathEffect") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - - // Create effect - auto pathEffect = SkCornerPathEffect::Make(_rProp->value().getAsNumber()); + void decorate(DeclarationContext *context) override { + // Create effect + auto pathEffect = SkCornerPathEffect::Make(_rProp->value().getAsNumber()); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _rProp = container->defineProperty("r"); _rProp->require(); @@ -170,22 +142,19 @@ class JsiPath1DPathEffectNode : public JsiBasePathEffectNode, explicit JsiPath1DPathEffectNode(std::shared_ptr context) : JsiBasePathEffectNode(context, "skPath1DPathEffect") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - - // Create effect - auto pathEffect = SkPath1DPathEffect::Make( - *_pathProp->getDerivedValue(), _advanceProp->value().getAsNumber(), - _phaseProp->value().getAsNumber(), - getStyleFromStringValue(_styleProp->value().getAsString())); + void decorate(DeclarationContext *context) override { + // Create effect + auto pathEffect = SkPath1DPathEffect::Make( + *_pathProp->getDerivedValue(), _advanceProp->value().getAsNumber(), + _phaseProp->value().getAsNumber(), + getStyleFromStringValue(_styleProp->value().getAsString())); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _phaseProp = container->defineProperty("phase"); _advanceProp = container->defineProperty("advance"); @@ -224,19 +193,17 @@ class JsiPath2DPathEffectNode : public JsiBasePathEffectNode, : JsiBasePathEffectNode(context, "skPath2DPathEffect") {} protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { + void decorate(DeclarationContext *context) override { - // Create effect - auto pathEffect = SkPath2DPathEffect::Make( - *_matrixProp->getDerivedValue(), *_pathProp->getDerivedValue()); + // Create effect + auto pathEffect = SkPath2DPathEffect::Make(*_matrixProp->getDerivedValue(), + *_pathProp->getDerivedValue()); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _matrixProp = container->defineProperty("matrix"); _pathProp = container->defineProperty("path"); @@ -257,19 +224,17 @@ class JsiLine2DPathEffectNode : public JsiBasePathEffectNode, : JsiBasePathEffectNode(context, "skLine2DPathEffect") {} protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { + void decorate(DeclarationContext *context) override { - // Create effect - auto pathEffect = SkLine2DPathEffect::Make( - _widthProp->value().getAsNumber(), *_matrixProp->getDerivedValue()); + // Create effect + auto pathEffect = SkLine2DPathEffect::Make( + _widthProp->value().getAsNumber(), *_matrixProp->getDerivedValue()); - setPathEffect(context, pathEffect); - } + composeAndPush(context, pathEffect); } void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _matrixProp = container->defineProperty("matrix"); _widthProp = container->defineProperty("width"); @@ -290,12 +255,14 @@ class JsiSumPathEffectNode : public JsiBasePathEffectNode, : JsiBasePathEffectNode(context, "skSumPathEffect") {} protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto inner = requireChild(0); - auto outer = requireChild(1); - setPathEffect(context, SkPathEffect::MakeSum(inner, outer)); - } + void decorate(DeclarationContext *context) override { + decorateChildren(context); + auto pe = + context->getPathEffects()->Declaration>::popAsOne( + [=](sk_sp inner, sk_sp outer) { + return SkPathEffect::MakeSum(inner, outer); + }); + context->getPathEffects()->push(pe); } }; } // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h index aa185aa48b4f4..e98ec8f13bcd9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPathNode.h @@ -3,13 +3,14 @@ #include "JsiDomDrawingNode.h" #include "PathProp.h" +#include #include #include #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkTrimPathEffect.h" #pragma clang diagnostic pop @@ -27,12 +28,14 @@ class JsiPathNode : public JsiDomDrawingNode, protected: void draw(DrawingContext *context) override { if (getPropsContainer()->isChanged()) { + auto start = saturate( + _startProp->isSet() ? _startProp->value().getAsNumber() : 0.0); + auto end = + saturate(_endProp->isSet() ? _endProp->value().getAsNumber() : 1.0); // Can we use the path directly, or do we need to copy to // mutate / modify the path? - auto hasStartOffset = - _startProp->isSet() && _startProp->value().getAsNumber() != 0.0; - auto hasEndOffset = - _endProp->isSet() && _endProp->value().getAsNumber() != 1.0; + auto hasStartOffset = start != 0.0; + auto hasEndOffset = end != 1.0; auto hasFillStyle = _fillTypeProp->isSet(); auto hasStrokeOptions = _strokeOptsProp->isSet() && @@ -44,9 +47,6 @@ class JsiPathNode : public JsiDomDrawingNode, if (willMutatePath) { // We'll trim the path SkPath filteredPath(*_pathProp->getDerivedValue()); - auto start = - _startProp->isSet() ? _startProp->value().getAsNumber() : 0.0; - auto end = _endProp->isSet() ? _endProp->value().getAsNumber() : 1.0; auto pe = SkTrimPathEffect::Make(start, end, SkTrimPathEffect::Mode::kNormal); @@ -55,16 +55,14 @@ class JsiPathNode : public JsiDomDrawingNode, if (!pe->filterPath(&filteredPath, filteredPath, &rec, nullptr)) { throw std::runtime_error( "Failed trimming path with parameters start: " + - std::to_string(_startProp->value().getAsNumber()) + - ", end: " + std::to_string(_endProp->value().getAsNumber())); + std::to_string(start) + ", end: " + std::to_string(end)); } filteredPath.swap(filteredPath); _path = std::make_shared(filteredPath); } else if (hasStartOffset || hasEndOffset) { throw std::runtime_error( "Failed trimming path with parameters start: " + - std::to_string(_startProp->value().getAsNumber()) + - ", end: " + std::to_string(_endProp->value().getAsNumber())); + std::to_string(start) + ", end: " + std::to_string(end)); } else { _path = std::make_shared(filteredPath); } @@ -110,8 +108,8 @@ class JsiPathNode : public JsiDomDrawingNode, // _path is const so we can't mutate it directly, let's replace the // path like this: auto p = std::make_shared(*_path.get()); - if (!strokePaint.getFillPath(*_path.get(), p.get(), nullptr, - precision)) { + if (!skpathutils::FillPathWithPaint(*_path.get(), strokePaint, + p.get(), nullptr, precision)) { _path = nullptr; } else { _path = std::const_pointer_cast(p); @@ -144,6 +142,8 @@ class JsiPathNode : public JsiDomDrawingNode, } private: + float saturate(float x) { return std::max(0.0f, std::min(1.0f, x)); } + SkPathFillType getFillTypeFromStringValue(const std::string &value) { if (value == "winding") { return SkPathFillType::kWinding; @@ -169,8 +169,9 @@ class JsiPathNode : public JsiDomDrawingNode, class StrokeOptsProps : public BaseDerivedProp { public: - StrokeOptsProps() : BaseDerivedProp() { - _strokeProp = addProperty(std::make_shared("stroke")); + explicit StrokeOptsProps(const std::function &onChange) + : BaseDerivedProp(onChange) { + _strokeProp = defineProperty("stroke"); } private: diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPointsNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPointsNode.h index 90dc4c2947ac4..25eb21c23da86 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPointsNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiPointsNode.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkCanvas.h" #pragma clang diagnostic pop diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiShaderNodes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiShaderNodes.h index 97361d5da7355..6a4e3069d522e 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiShaderNodes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiShaderNodes.h @@ -17,90 +17,54 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkShader.h" #pragma clang diagnostic pop namespace RNSkia { -class JsiBaseShaderNode - : public JsiDomDeclarationNode> { -public: - JsiBaseShaderNode(std::shared_ptr context, - const char *type) - : JsiDomDeclarationNode>(context, - type) {} - -protected: - sk_sp resolve(std::shared_ptr child) override { - auto ptr = std::dynamic_pointer_cast(child); - if (ptr) { - return ptr->getCurrent(); - } - return nullptr; - } - - void setShader(DrawingContext *context, sk_sp f) { - set(context, f); - } - - void set(DrawingContext *context, sk_sp shader) override { - auto paint = context->getMutablePaint(); - paint->setShader(shader); - setCurrent(shader); - } -}; - -class JsiShaderNode : public JsiBaseShaderNode, +class JsiShaderNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiShaderNode(std::shared_ptr context) - : JsiBaseShaderNode(context, "skShader") {} - -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto source = _sourceProp->value().getAs(); - if (source == nullptr) { - throw std::runtime_error("Expected runtime effect when reading source " - "property of RuntimeEffectImageFilter."); - } - auto uniforms = - _uniformsProp->isSet() ? _uniformsProp->getDerivedValue() : nullptr; - - SkMatrix lm; - auto tm = - _transformProp->isSet() ? _transformProp->getDerivedValue() : nullptr; - - if (tm != nullptr) { - if (_originProp->isSet()) { - auto tr = _originProp->getDerivedValue(); - lm.preTranslate(tr->x(), tr->y()); - lm.preConcat(*tm); - lm.preTranslate(-tr->x(), -tr->y()); - } else { - lm.preConcat(*tm); - } + : JsiDomDeclarationNode(context, "skShader", DeclarationType::Shader) {} + + void decorate(DeclarationContext *context) override { + decorateChildren(context); + auto source = _sourceProp->value().getAs(); + if (source == nullptr) { + throw std::runtime_error("Expected runtime effect when reading source " + "property of RuntimeEffectImageFilter."); + } + auto uniforms = + _uniformsProp->isSet() ? _uniformsProp->getDerivedValue() : nullptr; + + SkMatrix lm; + auto tm = + _transformProp->isSet() ? _transformProp->getDerivedValue() : nullptr; + + if (tm != nullptr) { + if (_originProp->isSet()) { + auto tr = _originProp->getDerivedValue(); + lm.preTranslate(tr->x(), tr->y()); + lm.preConcat(*tm); + lm.preTranslate(-tr->x(), -tr->y()); + } else { + lm.preConcat(*tm); } + } - // get all children that are shader nodes - std::vector> children; - children.reserve(getChildren().size()); - for (auto &child : getChildren()) { - auto ptr = std::dynamic_pointer_cast(child); - if (ptr != nullptr) { - children.push_back(ptr->getCurrent()); - } - } + // get all children that are shader nodes + auto children = context->getShaders()->popAll(); - // Update shader - setShader(context, source->getObject()->makeShader( - uniforms, children.data(), children.size(), &lm)); - } + // Update shader + context->getShaders()->push(source->getObject()->makeShader( + uniforms, children.data(), children.size(), &lm)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _sourceProp = container->defineProperty("source"); _uniformsProp = container->defineProperty("uniforms", _sourceProp); @@ -117,55 +81,56 @@ class JsiShaderNode : public JsiBaseShaderNode, PointProp *_originProp; }; -class JsiImageShaderNode : public JsiBaseShaderNode, +class JsiImageShaderNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiImageShaderNode(std::shared_ptr context) - : JsiBaseShaderNode(context, "skImageShader") {} + : JsiDomDeclarationNode(context, "skImageShader", + DeclarationType::Shader) {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - auto image = _imageProps->getImage(); - auto rect = _imageProps->getRect(); - auto lm = - _transformProp->isSet() ? _transformProp->getDerivedValue() : nullptr; - - if (rect != nullptr && lm != nullptr) { - auto rc = _imageProps->getDerivedValue(); - auto m3 = _imageProps->rect2rect(rc->src, rc->dst); - if (_transformProp->isChanged()) { - // To modify the matrix we need to copy it since we're not allowed to - // modify values contained in properties - this would have caused the - // matrix to be translated and scaled more and more for each render - // even thought the matrix prop did not change. - _matrix.reset(); - _matrix.preConcat(m3); - if (_originProp->isSet()) { - auto tr = _originProp->getDerivedValue(); - _matrix.preTranslate(tr->x(), tr->y()); - _matrix.preConcat(*lm); - _matrix.preTranslate(-tr->x(), -tr->y()); - } else { - _matrix.preConcat(*lm); - } + void decorate(DeclarationContext *context) override { + + auto image = _imageProps->getImage(); + if (image == nullptr) { + return; + } + + auto rect = _imageProps->getRect(); + auto lm = + _transformProp->isSet() ? _transformProp->getDerivedValue() : nullptr; + + if (rect != nullptr && lm != nullptr) { + auto rc = _imageProps->getDerivedValue(); + auto m3 = _imageProps->rect2rect(rc->src, rc->dst); + if (_transformProp->isChanged() || _imageProps->isChanged()) { + // To modify the matrix we need to copy it since we're not allowed to + // modify values contained in properties - this would have caused the + // matrix to be translated and scaled more and more for each render + // even thought the matrix prop did not change. + _matrix.reset(); + _matrix.preConcat(m3); + if (_originProp->isSet()) { + auto tr = _originProp->getDerivedValue(); + _matrix.preTranslate(tr->x(), tr->y()); + _matrix.preConcat(*lm); + _matrix.preTranslate(-tr->x(), -tr->y()); + } else { + _matrix.preConcat(*lm); } } - - setShader( - context, - image->makeShader( - *_txProp->getDerivedValue(), *_tyProp->getDerivedValue(), - SkSamplingOptions(getFilterModeFromString( - _filterModeProp->value().getAsString()), - getMipmapModeFromString( - _mipmapModeProp->value().getAsString())), - &_matrix)); } + + context->getShaders()->push(image->makeShader( + *_txProp->getDerivedValue(), *_tyProp->getDerivedValue(), + SkSamplingOptions( + getFilterModeFromString(_filterModeProp->value().getAsString()), + getMipmapModeFromString(_mipmapModeProp->value().getAsString())), + &_matrix)); } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _txProp = container->defineProperty("tx"); _tyProp = container->defineProperty("ty"); _filterModeProp = container->defineProperty("fm"); @@ -183,7 +148,7 @@ class JsiImageShaderNode : public JsiBaseShaderNode, _transformProp->require(); // Add and require the image - container->defineProperty("image")->require(); + container->defineProperty("image"); } private: @@ -224,25 +189,23 @@ class JsiImageShaderNode : public JsiBaseShaderNode, PointProp *_originProp; }; -class JsiColorShaderNode : public JsiBaseShaderNode, +class JsiColorShaderNode : public JsiDomDeclarationNode, public JsiDomNodeCtor { public: explicit JsiColorShaderNode(std::shared_ptr context) - : JsiBaseShaderNode(context, "skColorShader") {} + : JsiDomDeclarationNode(context, "skColorShader", + DeclarationType::Shader) {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - if (_colorProp->isSet()) { - setShader(context, SkShaders::Color(*_colorProp->getDerivedValue())); - } else { - setShader(context, nullptr); - } + void decorate(DeclarationContext *context) override { + if (_colorProp->isSet()) { + context->getShaders()->push( + SkShaders::Color(*_colorProp->getDerivedValue())); } } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _colorProp = container->defineProperty("color"); _colorProp->require(); } @@ -251,15 +214,14 @@ class JsiColorShaderNode : public JsiBaseShaderNode, ColorProp *_colorProp; }; -class JsiBasePerlinNoiseNode : public JsiBaseShaderNode { +class JsiBasePerlinNoiseNode : public JsiDomDeclarationNode { public: JsiBasePerlinNoiseNode(std::shared_ptr context, PropId type) - : JsiBaseShaderNode(context, type) {} + : JsiDomDeclarationNode(context, type, DeclarationType::Shader) {} -protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _freqXProp = container->defineProperty("freqX"); _freqYProp = container->defineProperty("freqY"); _octavesProp = container->defineProperty("octaves"); @@ -289,18 +251,15 @@ class JsiTurbulenceNode : public JsiBasePerlinNoiseNode, explicit JsiTurbulenceNode(std::shared_ptr context) : JsiBasePerlinNoiseNode(context, "skTurbulence") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - SkISize size = SkISize::Make(_tileWidthProp->value().getAsNumber(), - _tileHeightProp->value().getAsNumber()); - - setShader(context, SkPerlinNoiseShader::MakeTurbulence( - _freqXProp->value().getAsNumber(), - _freqYProp->value().getAsNumber(), - _octavesProp->value().getAsNumber(), - _seedProp->value().getAsNumber(), &size)); - } + void decorate(DeclarationContext *context) override { + + SkISize size = SkISize::Make(_tileWidthProp->value().getAsNumber(), + _tileHeightProp->value().getAsNumber()); + + context->getShaders()->push(SkPerlinNoiseShader::MakeTurbulence( + _freqXProp->value().getAsNumber(), _freqYProp->value().getAsNumber(), + _octavesProp->value().getAsNumber(), _seedProp->value().getAsNumber(), + &size)); } }; @@ -310,28 +269,41 @@ class JsiFractalNoiseNode : public JsiBasePerlinNoiseNode, explicit JsiFractalNoiseNode(std::shared_ptr context) : JsiBasePerlinNoiseNode(context, "skFractalNoise") {} -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - SkISize size = SkISize::Make(_tileWidthProp->value().getAsNumber(), - _tileHeightProp->value().getAsNumber()); - - setShader(context, SkPerlinNoiseShader::MakeFractalNoise( - _freqXProp->value().getAsNumber(), - _freqYProp->value().getAsNumber(), - _octavesProp->value().getAsNumber(), - _seedProp->value().getAsNumber(), &size)); - } + void decorate(DeclarationContext *context) override { + + SkISize size = SkISize::Make(_tileWidthProp->value().getAsNumber(), + _tileHeightProp->value().getAsNumber()); + + context->getShaders()->push(SkPerlinNoiseShader::MakeFractalNoise( + _freqXProp->value().getAsNumber(), _freqYProp->value().getAsNumber(), + _octavesProp->value().getAsNumber(), _seedProp->value().getAsNumber(), + &size)); } }; -class JsiBaseGradientNode : public JsiBaseShaderNode { +class JsiBaseGradientNode : public JsiDomDeclarationNode { public: JsiBaseGradientNode(std::shared_ptr context, PropId type) - : JsiBaseShaderNode(context, type) {} + : JsiDomDeclarationNode(context, type, DeclarationType::Shader) {} + + void decorate(DeclarationContext *context) override { + + _colors = _colorsProp->getDerivedValue()->data(); + _colorCount = static_cast(_colorsProp->getDerivedValue()->size()); + _flags = _flagsProp->isSet() ? _flagsProp->value().getAsNumber() : 0; + _mode = + _modeProp->isSet() ? *_modeProp->getDerivedValue() : SkTileMode::kClamp; + _positions = _positionsProp->isSet() + ? _positionsProp->getDerivedValue()->data() + : nullptr; + _matrix = _transformsProps->isSet() + ? _transformsProps->getDerivedValue().get() + : nullptr; + } +protected: void defineProperties(NodePropsContainer *container) override { - JsiBaseDomDeclarationNode::defineProperties(container); + JsiDomDeclarationNode::defineProperties(container); _transformsProps = container->defineProperty(); _colorsProp = container->defineProperty("colors"); @@ -342,23 +314,6 @@ class JsiBaseGradientNode : public JsiBaseShaderNode { _colorsProp->require(); } -protected: - void decorate(DrawingContext *context) override { - if (isChanged(context)) { - _colors = _colorsProp->getDerivedValue()->data(); - _colorCount = static_cast(_colorsProp->getDerivedValue()->size()); - _flags = _flagsProp->isSet() ? _flagsProp->value().getAsNumber() : 0; - _mode = _modeProp->isSet() ? *_modeProp->getDerivedValue() - : SkTileMode::kClamp; - _positions = _positionsProp->isSet() - ? _positionsProp->getDerivedValue()->data() - : nullptr; - _matrix = _transformsProps->isSet() - ? _transformsProps->getDerivedValue().get() - : nullptr; - } - } - const SkColor *_colors; double _flags; int _colorCount; @@ -380,19 +335,17 @@ class JsiLinearGradientNode : public JsiBaseGradientNode, explicit JsiLinearGradientNode(std::shared_ptr context) : JsiBaseGradientNode(context, "skLinearGradient") {} -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { JsiBaseGradientNode::decorate(context); - if (isChanged(context)) { - SkPoint pts[] = {*_startProp->getDerivedValue(), - *_endProp->getDerivedValue()}; - setShader(context, SkGradientShader::MakeLinear(pts, _colors, _positions, - _colorCount, _mode, - _flags, _matrix)); - } + SkPoint pts[] = {*_startProp->getDerivedValue(), + *_endProp->getDerivedValue()}; + auto shader = SkGradientShader::MakeLinear( + pts, _colors, _positions, _colorCount, _mode, _flags, _matrix); + context->getShaders()->push(shader); } +protected: void defineProperties(NodePropsContainer *container) override { JsiBaseGradientNode::defineProperties(container); _startProp = container->defineProperty("start"); @@ -413,19 +366,17 @@ class JsiRadialGradientNode : public JsiBaseGradientNode, explicit JsiRadialGradientNode(std::shared_ptr context) : JsiBaseGradientNode(context, "skRadialGradient") {} -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { JsiBaseGradientNode::decorate(context); - if (isChanged(context)) { - auto c = _centerProp->getDerivedValue(); - auto r = _radiusProp->value().getAsNumber(); - setShader(context, SkGradientShader::MakeRadial(*c, r, _colors, - _positions, _colorCount, - _mode, _flags, _matrix)); - } + auto c = _centerProp->getDerivedValue(); + auto r = _radiusProp->value().getAsNumber(); + auto shader = SkGradientShader::MakeRadial( + *c, r, _colors, _positions, _colorCount, _mode, _flags, _matrix); + context->getShaders()->push(shader); } +protected: void defineProperties(NodePropsContainer *container) override { JsiBaseGradientNode::defineProperties(container); _centerProp = container->defineProperty("c"); @@ -446,21 +397,19 @@ class JsiSweepGradientNode : public JsiBaseGradientNode, explicit JsiSweepGradientNode(std::shared_ptr context) : JsiBaseGradientNode(context, "skSweepGradient") {} -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { JsiBaseGradientNode::decorate(context); - if (isChanged(context)) { - auto start = _startProp->isSet() ? _startProp->value().getAsNumber() : 0; - auto end = _endProp->isSet() ? _endProp->value().getAsNumber() : 360; - auto c = _centerProp->getDerivedValue(); + auto start = _startProp->isSet() ? _startProp->value().getAsNumber() : 0; + auto end = _endProp->isSet() ? _endProp->value().getAsNumber() : 360; + auto c = _centerProp->getDerivedValue(); - setShader(context, SkGradientShader::MakeSweep( - c->x(), c->y(), _colors, _positions, _colorCount, - _mode, start, end, _flags, _matrix)); - } + context->getShaders()->push(SkGradientShader::MakeSweep( + c->x(), c->y(), _colors, _positions, _colorCount, _mode, start, end, + _flags, _matrix)); } +protected: void defineProperties(NodePropsContainer *container) override { JsiBaseGradientNode::defineProperties(container); _startProp = container->defineProperty("start"); @@ -482,22 +431,20 @@ class JsiTwoPointConicalGradientNode std::shared_ptr context) : JsiBaseGradientNode(context, "skTwoPointConicalGradient") {} -protected: - void decorate(DrawingContext *context) override { + void decorate(DeclarationContext *context) override { JsiBaseGradientNode::decorate(context); - if (isChanged(context)) { - auto start = _startProp->getDerivedValue(); - auto end = _endProp->getDerivedValue(); - auto startR = _startRProp->value().getAsNumber(); - auto endR = _endRProp->value().getAsNumber(); + auto start = _startProp->getDerivedValue(); + auto end = _endProp->getDerivedValue(); + auto startR = _startRProp->value().getAsNumber(); + auto endR = _endRProp->value().getAsNumber(); - setShader(context, SkGradientShader::MakeTwoPointConical( - *start, startR, *end, endR, _colors, _positions, - _colorCount, _mode, _flags, _matrix)); - } + context->getShaders()->push(SkGradientShader::MakeTwoPointConical( + *start, startR, *end, endR, _colors, _positions, _colorCount, _mode, + _flags, _matrix)); } +protected: void defineProperties(NodePropsContainer *container) override { JsiBaseGradientNode::defineProperties(container); _startProp = container->defineProperty("start"); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextNode.h index 6c78e83941d56..71a26b8179400 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextNode.h @@ -21,9 +21,11 @@ class JsiTextNode : public JsiDomDrawingNode, auto y = _yProp->value().getAsNumber(); auto font = _fontProp->getDerivedValue(); - context->getCanvas()->drawSimpleText(text, strlen(text), - SkTextEncoding::kUTF8, x, y, *font, - *context->getPaint()); + if (font != nullptr) { + context->getCanvas()->drawSimpleText(text, strlen(text), + SkTextEncoding::kUTF8, x, y, *font, + *context->getPaint()); + } } void defineProperties(NodePropsContainer *container) override { @@ -34,7 +36,6 @@ class JsiTextNode : public JsiDomDrawingNode, _xProp = container->defineProperty("x"); _yProp = container->defineProperty("y"); - _fontProp->require(); _textProp->require(); _xProp->require(); _yProp->require(); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextPathNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextPathNode.h index 90d11b960de8a..ec08389fbb934 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextPathNode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/nodes/JsiTextPathNode.h @@ -16,7 +16,9 @@ class JsiTextPathNode : public JsiDomDrawingNode, protected: void draw(DrawingContext *context) override { auto blob = _textBlobProp->getDerivedValue(); - context->getCanvas()->drawTextBlob(blob, 0, 0, *context->getPaint()); + if (blob != nullptr) { + context->getCanvas()->drawTextBlob(blob, 0, 0, *context->getPaint()); + } } void defineProperties(NodePropsContainer *container) override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BezierProps.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BezierProps.h index c230905bcf5ea..4829ebe489917 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BezierProps.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BezierProps.h @@ -12,8 +12,10 @@ namespace RNSkia { class BezierProp : public DerivedProp> { public: - explicit BezierProp(PropId name) : DerivedProp>() { - _bezierProp = addProperty(std::make_shared(name)); + explicit BezierProp(PropId name, + const std::function &onChange) + : DerivedProp>(onChange) { + _bezierProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BlendModeProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BlendModeProp.h index 654d8eeea713d..6b95b5e72ce7b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BlendModeProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BlendModeProp.h @@ -10,7 +10,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkBlendMode.h" #pragma clang diagnostic pop @@ -18,8 +18,10 @@ namespace RNSkia { class BlendModeProp : public DerivedProp { public: - explicit BlendModeProp(PropId name) : DerivedProp() { - _blendMode = addProperty(std::make_shared(name)); + explicit BlendModeProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _blendMode = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h index 6c438604d6f0b..fa43c8613df08 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/BoxShadowProps.h @@ -5,20 +5,20 @@ #include #include +#include "SkBlurTypes.h" + namespace RNSkia { class BoxShadowProps : public DerivedProp { public: - BoxShadowProps() : DerivedProp() { - _dxProp = addProperty(std::make_shared(JsiPropId::get("dx"))); - _dyProp = addProperty(std::make_shared(JsiPropId::get("dy"))); - _spreadProp = - addProperty(std::make_shared(JsiPropId::get("spread"))); - _blurProp = addProperty(std::make_shared(JsiPropId::get("blur"))); - _colorProp = - addProperty(std::make_shared(JsiPropId::get("color"))); - _innerProp = - addProperty(std::make_shared(JsiPropId::get("inner"))); + explicit BoxShadowProps(const std::function &onChange) + : DerivedProp(onChange) { + _dxProp = defineProperty("dx"); + _dyProp = defineProperty("dy"); + _spreadProp = defineProperty("spread"); + _blurProp = defineProperty("blur"); + _colorProp = defineProperty("color"); + _innerProp = defineProperty("inner"); _blurProp->require(); } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/CircleProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/CircleProp.h index cc40267c9ec07..bdbdf59607881 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/CircleProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/CircleProp.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPoint.h" #pragma clang diagnostic pop @@ -20,10 +20,11 @@ static PropId PropNameC = JsiPropId::get("c"); class CircleProp : public DerivedProp { public: - CircleProp() : DerivedProp() { - _c = addProperty(std::make_shared(PropNameC)); - _cx = addProperty(std::make_shared(PropNameCx)); - _cy = addProperty(std::make_shared(PropNameCy)); + explicit CircleProp(const std::function &onChange) + : DerivedProp(onChange) { + _c = defineProperty("c"); + _cx = defineProperty("cx"); + _cy = defineProperty("cy"); } void updateDerivedValue() override { @@ -33,7 +34,7 @@ class CircleProp : public DerivedProp { setDerivedValue(SkPoint::Make(_cx->value().getAsNumber(), _cy->value().getAsNumber())); } else if (_c->isSet()) { - setDerivedValue(_c->getDerivedValue()); + setDerivedValue(_c->getUnsafeDerivedValue()); } else { setDerivedValue(SkPoint::Make(0.0, 0.0)); } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ClipProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ClipProp.h index cab59cdbdb469..d7e8806102942 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ClipProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ClipProp.h @@ -11,7 +11,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPath.h" #pragma clang diagnostic pop @@ -19,44 +19,39 @@ namespace RNSkia { class ClipProp : public BaseDerivedProp { public: - explicit ClipProp(PropId name) : BaseDerivedProp() { - _pathProp = addProperty(std::make_shared(name)); - _rectProp = addProperty(std::make_shared(name)); - _rrectProp = addProperty(std::make_shared(name)); + explicit ClipProp(PropId name, + const std::function &onChange) + : BaseDerivedProp(onChange) { + _clipProp = defineProperty(name); } void updateDerivedValue() override { - if (_pathProp->isSet()) { - _rect = nullptr; - _rrect = nullptr; - _path = _pathProp->getDerivedValue(); - } else if (_rrectProp->isSet()) { - _rect = nullptr; - _rrect = _rrectProp->getDerivedValue(); - _path = nullptr; - } else if (_rectProp->isSet()) { - _rect = _rectProp->getDerivedValue(); + if (_clipProp->isSet()) { + auto value = _clipProp->value(); + _rect = RectProp::processRect(value); _rrect = nullptr; _path = nullptr; + if (!_rect) { + _path = PathProp::processPath(value); + if (!_path) { + _rrect = RRectProp::processRRect(value); + } + } } } - bool isSet() override { - return _pathProp->isSet() || _rectProp->isSet() || _rrectProp->isSet(); - } + bool isSet() override { return _clipProp->isSet(); } const SkPath *getPath() { return _path.get(); } const SkRect *getRect() { return _rect.get(); } const SkRRect *getRRect() { return _rrect.get(); } private: - PathProp *_pathProp; - RectProp *_rectProp; - RRectProp *_rrectProp; + NodeProp *_clipProp; std::shared_ptr _path; std::shared_ptr _rect; std::shared_ptr _rrect; }; -} // namespace RNSkia +} // namespace RNSkia \ No newline at end of file diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ColorProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ColorProp.h index 50f45b9530823..4a391fad65426 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ColorProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ColorProp.h @@ -16,8 +16,10 @@ static PropId PropName3 = JsiPropId::get("3"); class ColorProp : public DerivedProp { public: - explicit ColorProp(PropId name) : DerivedProp() { - _colorProp = addProperty(std::make_shared(name)); + explicit ColorProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _colorProp = defineProperty(name); } void updateDerivedValue() override { @@ -40,6 +42,13 @@ class ColorProp : public DerivedProp { return SkColorSetARGB(a.getAsNumber() * 255.0f, r.getAsNumber() * 255.0f, g.getAsNumber() * 255.0f, b.getAsNumber() * 255.0f); + } else if (color.getType() == PropType::Array) { + auto r = color.getAsArray().at(0); + auto g = color.getAsArray().at(1); + auto b = color.getAsArray().at(2); + auto a = color.getAsArray().at(3); + return SkColorSetARGB(a.getAsNumber() * 255.0f, r.getAsNumber() * 255.0f, + g.getAsNumber() * 255.0f, b.getAsNumber() * 255.0f); } else if (color.getType() == PropType::Number) { return static_cast(color.getAsNumber()); } else { @@ -59,8 +68,10 @@ class ColorProp : public DerivedProp { class ColorsProp : public DerivedProp> { public: - explicit ColorsProp(PropId name) : DerivedProp>() { - _colorsProp = addProperty(std::make_shared(name)); + explicit ColorsProp(PropId name, + const std::function &onChange) + : DerivedProp>(onChange) { + _colorsProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/DrawingProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/DrawingProp.h index 384269e21e4bc..bfd6e756827e2 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/DrawingProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/DrawingProp.h @@ -13,9 +13,11 @@ using NotifyNeedRenderCallback = class DrawingProp : public DerivedSkProp { public: - DrawingProp(PropId name, NotifyNeedRenderCallback notifyPictureNeeded) - : _notifyPictureNeeded(notifyPictureNeeded), DerivedSkProp() { - _drawingProp = addProperty(std::make_shared(name)); + DrawingProp(PropId name, NotifyNeedRenderCallback notifyPictureNeeded, + const std::function &onChange) + : _notifyPictureNeeded(notifyPictureNeeded), DerivedSkProp( + onChange) { + _drawingProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/FontProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/FontProp.h index 99ea73b82b30a..72af25df73eb7 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/FontProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/FontProp.h @@ -10,22 +10,29 @@ namespace RNSkia { class FontProp : public DerivedProp { public: - explicit FontProp(PropId name) : DerivedProp() { - _fontProp = addProperty(std::make_shared(name)); + explicit FontProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _fontProp = defineProperty(name); } void updateDerivedValue() override { - if (!_fontProp->isSet() || - _fontProp->value().getType() != PropType::HostObject) { - throw std::runtime_error("Expected SkFont object for the Font property."); + if (_fontProp->isSet()) { + if (_fontProp->value().getType() == PropType::HostObject) { + auto ptr = _fontProp->value().getAs(); + if (ptr == nullptr) { + throw std::runtime_error( + "Expected SkFont object for the Font property."); + } + setDerivedValue(ptr->getObject()); + + } else { + throw std::runtime_error( + "Expected SkFont object or null/undefined for the Font property."); + } + } else { + setDerivedValue(nullptr); } - - auto ptr = _fontProp->value().getAs(); - if (ptr == nullptr) { - throw std::runtime_error("Expected SkFont object for the Font property."); - } - - setDerivedValue(ptr->getObject()); } private: diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/GlyphsProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/GlyphsProp.h index d35f561053589..414f4f6ff683c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/GlyphsProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/GlyphsProp.h @@ -19,8 +19,10 @@ struct GlyphInfo { class GlyphsProp : public DerivedProp { public: - explicit GlyphsProp(PropId name) : DerivedProp() { - _glyphsProp = addProperty(std::make_shared(name)); + explicit GlyphsProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _glyphsProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ImageProps.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ImageProps.h index a1337347f953d..bc2cfdf6d1fbb 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ImageProps.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/ImageProps.h @@ -25,25 +25,39 @@ static PropId PropNameFit = JsiPropId::get("fit"); class ImageProp : public DerivedSkProp { public: - explicit ImageProp(PropId name) : DerivedSkProp() { - _imageProp = addProperty(std::make_shared(name)); + explicit ImageProp(PropId name, + const std::function &onChange) + : DerivedSkProp(onChange) { + _imageProp = defineProperty(name); } void updateDerivedValue() override { - if (!_imageProp->isSet() || - _imageProp->value().getType() != PropType::HostObject) { - throw std::runtime_error("Expected SkImage object for the " + - std::string(getName()) + " property."); - } - - auto ptr = std::dynamic_pointer_cast( - _imageProp->value().getAsHostObject()); - if (ptr == nullptr) { - throw std::runtime_error("Expected SkImage object for the " + - std::string(getName()) + " property."); + if (_imageProp->isSet()) { + // Check for host object + if (_imageProp->value().getType() == PropType::HostObject) { + // This should be an SkImage wrapper: + auto ptr = std::dynamic_pointer_cast( + _imageProp->value().getAsHostObject()); + if (ptr == nullptr) { + // If not - throw an exception + throw std::runtime_error("Expected SkImage object for the " + + std::string(getName()) + + " property. Got a " + + _imageProp->value().getTypeAsString( + _imageProp->value().getType()) + + "."); + } + setDerivedValue(ptr->getObject()); + } else { + // Should be a host object if set + throw std::runtime_error( + "Expected SkImage object or null/undefined for the " + + std::string(getName()) + " property."); + } + } else { + // Set to null + setDerivedValue(nullptr); } - - setDerivedValue(ptr->getObject()); } private: @@ -52,18 +66,20 @@ class ImageProp : public DerivedSkProp { class ImageProps : public DerivedProp { public: - ImageProps() : DerivedProp() { - _fitProp = addProperty(std::make_shared(PropNameFit)); - _imageProp = addProperty(std::make_shared(PropNameImage)); - _rectProp = addProperty(std::make_shared(PropNameRect)); + explicit ImageProps(const std::function &onChange) + : DerivedProp(onChange) { + _fitProp = defineProperty(PropNameFit); + _imageProp = defineProperty(PropNameImage); + _rectProp = defineProperty(PropNameRect); } void updateDerivedValue() override { - if (!_imageProp->isSet()) { - throw std::runtime_error("Image property is not set on the Image node."); + auto image = _imageProp->getDerivedValue(); + if (image == nullptr) { + setDerivedValue(nullptr); + return; } - auto image = _imageProp->getDerivedValue(); auto imageRect = SkRect::MakeXYWH(0, 0, image->width(), image->height()); auto rect = _rectProp->getDerivedValue() ? *_rectProp->getDerivedValue() @@ -74,6 +90,7 @@ class ImageProps : public DerivedProp { } sk_sp getImage() { return _imageProp->getDerivedValue(); } + std::shared_ptr getRect() { return _rectProp->getDerivedValue(); } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/LayerProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/LayerProp.h index 80779a124b039..ad013082d380a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/LayerProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/LayerProp.h @@ -10,9 +10,11 @@ namespace RNSkia { class LayerProp : public DerivedProp { public: - explicit LayerProp(PropId name) : DerivedProp() { - _layerPaintProp = addProperty(std::make_shared(name)); - _layerBoolProp = addProperty(std::make_shared(name)); + explicit LayerProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _layerPaintProp = defineProperty(name); + _layerBoolProp = defineProperty(name); } /** @@ -31,7 +33,7 @@ class LayerProp : public DerivedProp { if (_layerPaintProp->isSet()) { // We have a paint object for the layer property - setDerivedValue(_layerPaintProp->getDerivedValue()); + setDerivedValue(_layerPaintProp->getUnsafeDerivedValue()); _isBool = false; } else { _isBool = false; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/MatrixProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/MatrixProp.h index 527265d5d5f3e..f3d8b59d9f809 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/MatrixProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/MatrixProp.h @@ -11,8 +11,10 @@ static PropId PropNameMatrix = JsiPropId::get("matrix"); class MatrixProp : public DerivedProp { public: - explicit MatrixProp(PropId name) : DerivedProp() { - _matrixProp = addProperty(std::make_shared(name)); + explicit MatrixProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _matrixProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/NumbersProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/NumbersProp.h index 80c04f5a16862..90f2863d0bc70 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/NumbersProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/NumbersProp.h @@ -11,8 +11,10 @@ namespace RNSkia { class NumbersProp : public DerivedProp> { public: - explicit NumbersProp(PropId name) : DerivedProp>() { - _positionProp = addProperty(std::make_shared(name)); + explicit NumbersProp(PropId name, + const std::function &onChange) + : DerivedProp>(onChange) { + _positionProp = defineProperty(name); } void updateDerivedValue() override { @@ -36,8 +38,10 @@ class NumbersProp : public DerivedProp> { class Numbers16Prop : public DerivedProp> { public: - explicit Numbers16Prop(PropId name) : DerivedProp>() { - _prop = addProperty(std::make_shared(name)); + explicit Numbers16Prop(PropId name, + const std::function &onChange) + : DerivedProp>(onChange) { + _prop = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PaintProps.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PaintProps.h index ec318a94076af..f131b6a7149f7 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PaintProps.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PaintProps.h @@ -13,7 +13,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPaint.h" #pragma clang diagnostic pop @@ -21,11 +21,14 @@ namespace RNSkia { class PaintProp : public DerivedProp { public: - explicit PaintProp(PropId name) : DerivedProp() { - _paintProp = addProperty(std::make_shared(name)); + explicit PaintProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _paintProp = defineProperty(name); } - PaintProp() : PaintProp(JsiPropId::get("paint")) {} + explicit PaintProp(const std::function &onChange) + : PaintProp(JsiPropId::get("paint"), onChange) {} void updateDerivedValue() override { if (_paintProp->isSet()) { @@ -50,108 +53,68 @@ class PaintProp : public DerivedProp { NodeProp *_paintProp; }; -class PaintProps : public BaseDerivedProp { +class PaintDrawingContextProp : public DerivedProp { public: - PaintProps() : BaseDerivedProp() { - _color = addProperty(std::make_shared(JsiPropId::get("color"))); - _style = addProperty(std::make_shared(JsiPropId::get("style"))); - _strokeWidth = - addProperty(std::make_shared(JsiPropId::get("strokeWidth"))); - _blendMode = addProperty( - std::make_shared(JsiPropId::get("blendMode"))); - _strokeJoin = addProperty( - std::make_shared(JsiPropId::get("strokeJoin"))); - _strokeCap = addProperty( - std::make_shared(JsiPropId::get("strokeCap"))); - _strokeMiter = - addProperty(std::make_shared(JsiPropId::get("strokeMiter"))); - _antiAlias = - addProperty(std::make_shared(JsiPropId::get("antiAlias"))); - _opacity = - addProperty(std::make_shared(JsiPropId::get("opacity"))); + explicit PaintDrawingContextProp( + PropId name, const std::function &onChange) + : DerivedProp(onChange) { + _paintProp = defineProperty(name); } - void decorate(DrawingContext *context) { - // Now we can start updating the context - - // Opacity - if (_opacity->isChanged() || context->isChanged()) { - auto parent = context->getParent(); - auto paint = context->getMutablePaint(); - if (_opacity->isSet()) { - auto currentOpacity = _opacity->value().getAsNumber(); - auto parent = context->getParent(); - if (parent != nullptr) { - currentOpacity *= parent->getPaint()->getAlphaf(); - } - paint->setAlphaf(currentOpacity); - } else { - if (parent != nullptr) { - paint->setAlphaf(parent->getPaint()->getAlphaf()); + explicit PaintDrawingContextProp( + const std::function &onChange) + : PaintDrawingContextProp(JsiPropId::get("paint"), onChange) {} + + void updateDerivedValue() override { + if (_paintProp->isSet()) { + if (_paintProp->value().getType() == PropType::HostObject) { + // Read paint property as Host Object - JsiSkPaint + auto ptr = _paintProp->value().getAs(); + if (ptr != nullptr) { + setDerivedValue(std::make_shared(ptr->getObject())); } else { - paint->setAlphaf(1.0); + throw std::runtime_error("Expected SkPaint object, got unknown " + "object when reading paint property."); } + } else { + setDerivedValue(nullptr); } + } else { + setDerivedValue(nullptr); } + } - // COLOR - if (_color->isSet() && (_color->isChanged() || context->isChanged())) { - auto paint = context->getMutablePaint(); - auto opacity = paint->getAlphaf(); - paint->setShader(nullptr); - paint->setColor(*_color->getDerivedValue()); - paint->setAlphaf(opacity * paint->getColor4f().fA); - } +private: + NodeProp *_paintProp; +}; - // Style - if (_style->isSet() && (_style->isChanged() || context->isChanged())) { - auto styleValue = _style->value().getAsString(); - if (styleValue == "stroke") { - context->getMutablePaint()->setStyle(SkPaint::Style::kStroke_Style); - } else if (styleValue == "fill") { - context->getMutablePaint()->setStyle(SkPaint::Style::kFill_Style); - } else { - throw std::runtime_error( - styleValue + " is not a valud value for the style property."); - } - } - // Stroke Width - if (_strokeWidth->isSet() && - (_strokeWidth->isChanged() || context->isChanged())) { - context->getMutablePaint()->setStrokeWidth( - _strokeWidth->value().getAsNumber()); - } - // Blend mode - if (_blendMode->isSet() && - (_blendMode->isChanged() || context->isChanged())) { - context->getMutablePaint()->setBlendMode(*_blendMode->getDerivedValue()); - } - // Stroke Join - if (_strokeJoin->isSet() && - (_strokeJoin->isChanged() || context->isChanged())) { - context->getMutablePaint()->setStrokeJoin( - *_strokeJoin->getDerivedValue()); - } - // Stroke Cap - if (_strokeCap->isSet() && - (_strokeCap->isChanged() || context->isChanged())) { - context->getMutablePaint()->setStrokeCap(*_strokeCap->getDerivedValue()); - } - // Stroke Miter - if (_strokeMiter->isSet() && - (_strokeMiter->isChanged() || context->isChanged())) { - context->getMutablePaint()->setStrokeMiter( - _strokeMiter->value().getAsNumber()); - } - // AntiAlias - if (_antiAlias->isSet() && - (_antiAlias->isChanged() || context->isChanged())) { - context->getMutablePaint()->setAntiAlias(_antiAlias->value().getAsBool()); - } +class PaintProps : public BaseDerivedProp { +public: + explicit PaintProps(const std::function &onChange) + : BaseDerivedProp(onChange) { + _color = defineProperty("color"); + _style = defineProperty("style"); + _strokeWidth = defineProperty("strokeWidth"); + _blendMode = defineProperty("blendMode"); + _strokeJoin = defineProperty("strokeJoin"); + _strokeCap = defineProperty("strokeCap"); + _strokeMiter = defineProperty("strokeMiter"); + _antiAlias = defineProperty("antiAlias"); + _opacity = defineProperty("opacity"); } void updateDerivedValue() override {} + ColorProp *getColor() { return _color; } + NodeProp *getStyle() { return _style; } + NodeProp *getStrokeWidth() { return _strokeWidth; } + BlendModeProp *getBlendMode() { return _blendMode; } + StrokeJoinProp *getStrokeJoin() { return _strokeJoin; } + StrokeCapProp *getStrokeCap() { return _strokeCap; } + NodeProp *getStrokeMiter() { return _strokeMiter; } + NodeProp *getAntiAlias() { return _antiAlias; } + NodeProp *getOpacity() { return _opacity; } + private: ColorProp *_color; NodeProp *_style; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PathProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PathProp.h index d711e16ee0772..b4b0860fe39cd 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PathProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PathProp.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPath.h" #pragma clang diagnostic pop @@ -16,36 +16,40 @@ namespace RNSkia { class PathProp : public DerivedProp { public: - explicit PathProp(PropId name) : DerivedProp() { - _pathProp = addProperty(std::make_shared(name)); + explicit PathProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _pathProp = defineProperty(name); } - void updateDerivedValue() override { - if (!_pathProp->isSet()) { - setDerivedValue(nullptr); - return; - } - - if (_pathProp->value().getType() == PropType::HostObject) { + static std::shared_ptr processPath(const JsiValue &value) { + if (value.getType() == PropType::HostObject) { // Try reading as Path - auto ptr = std::dynamic_pointer_cast( - _pathProp->value().getAsHostObject()); + auto ptr = std::dynamic_pointer_cast(value.getAsHostObject()); if (ptr != nullptr) { - setDerivedValue(ptr->getObject()); + return ptr->getObject(); } - } else if (_pathProp->value().getType() == PropType::String) { + } else if (value.getType() == PropType::String) { // Read as string - auto pathString = _pathProp->value().getAsString(); + auto pathString = value.getAsString(); SkPath result; if (SkParsePath::FromSVGString(pathString.c_str(), &result)) { - setDerivedValue(std::make_shared(result)); + return std::make_shared(result); } else { throw std::runtime_error("Could not parse path from string."); } - } else { + } + return nullptr; + } + + void updateDerivedValue() override { + if (!_pathProp->isSet()) { setDerivedValue(nullptr); + return; } + auto value = _pathProp->value(); + setDerivedValue(PathProp::processPath(value)); } private: diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PictureProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PictureProp.h index c2da4f0ae8c26..e63f8f31c235f 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PictureProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PictureProp.h @@ -11,8 +11,10 @@ namespace RNSkia { class PictureProp : public DerivedSkProp { public: - explicit PictureProp(PropId name) : DerivedSkProp() { - _pictureProp = addProperty(std::make_shared(name)); + explicit PictureProp(PropId name, + const std::function &onChange) + : DerivedSkProp(onChange) { + _pictureProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointProp.h index 70a6cafc72d67..c6f3f5ba2a145 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointProp.h @@ -9,7 +9,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPoint.h" #pragma clang diagnostic pop @@ -20,14 +20,16 @@ static PropId PropNameY = JsiPropId::get("y"); class PointProp : public DerivedProp { public: - explicit PointProp(PropId name) : DerivedProp() { - _pointProp = addProperty(std::make_shared(name)); + explicit PointProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _pointProp = defineProperty(name); } void updateDerivedValue() override { if (_pointProp->isSet()) { // Check for JsiSkRect and JsiSkPoint - setDerivedValue(std::move(processValue(_pointProp->value()))); + setDerivedValue(processValue(_pointProp->value())); } else { setDerivedValue(nullptr); } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointsProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointsProp.h index d80fb5256a0a5..c45b938fc1fb2 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointsProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/PointsProp.h @@ -11,7 +11,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPoint.h" #pragma clang diagnostic pop @@ -19,8 +19,10 @@ namespace RNSkia { class PointModeProp : public DerivedProp { public: - explicit PointModeProp(PropId name) : DerivedProp() { - _pointModeProp = addProperty(std::make_shared(name)); + explicit PointModeProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _pointModeProp = defineProperty(name); } void updateDerivedValue() override { @@ -51,8 +53,10 @@ class PointModeProp : public DerivedProp { class PointsProp : public DerivedProp> { public: - explicit PointsProp(PropId name) : DerivedProp>() { - _pointsProp = addProperty(std::make_shared(name)); + explicit PointsProp(PropId name, + const std::function &onChange) + : DerivedProp>(onChange) { + _pointsProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RRectProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RRectProp.h index f221d0e5b5244..e38fbcd9bfaf4 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RRectProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RRectProp.h @@ -9,8 +9,8 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include -#include +#include "SkRRect.h" +#include "SkRect.h" #pragma clang diagnostic pop @@ -27,39 +27,39 @@ static PropId PropNameR = JsiPropId::get("r"); */ class RRectProp : public DerivedProp { public: - explicit RRectProp(PropId name) : DerivedProp() { - _prop = addProperty(std::make_shared(name)); + explicit RRectProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _prop = defineProperty(name); } - void updateDerivedValue() override { - if (_prop->isSet()) { - // Check for JsiSkRRect - if (_prop->value().getType() == PropType::HostObject) { - // Try reading as rect - auto rectPtr = std::dynamic_pointer_cast( - _prop->value().getAsHostObject()); - if (rectPtr != nullptr) { - auto rrect = rectPtr->getObject(); - setDerivedValue(SkRRect::MakeRectXY( - SkRect::MakeXYWH(rrect->rect().x(), rrect->rect().y(), - rrect->rect().width(), rrect->rect().height()), - rrect->getSimpleRadii().x(), rrect->getSimpleRadii().y())); - } - } else { - if (_prop->isSet() && _prop->value().getType() == PropType::Object) { - auto p = _prop->value(); - if (p.hasValue(PropNameX) && p.hasValue(PropNameY) && - p.hasValue(PropNameWidth) && p.hasValue(PropNameHeight) && - p.hasValue(PropNameRx) && p.hasValue(PropNameRy)) { - auto x = _prop->value().getValue(PropNameX); - auto y = _prop->value().getValue(PropNameY); - auto width = _prop->value().getValue(PropNameWidth); - auto height = _prop->value().getValue(PropNameHeight); - auto rx = _prop->value().getValue(PropNameRx); - auto ry = _prop->value().getValue(PropNameRy); + static std::shared_ptr processRRect(const JsiValue &value) { + if (value.getType() == PropType::HostObject) { + // Try reading as rect + auto rectPtr = + std::dynamic_pointer_cast(value.getAsHostObject()); + if (rectPtr != nullptr) { + auto rrect = rectPtr->getObject(); + return std::make_shared( + SkRRect::MakeRectXY(rrect->rect(), rrect->getSimpleRadii().x(), + rrect->getSimpleRadii().y())); + } + } else { + if (value.getType() == PropType::Object) { + if (value.hasValue(PropNameRect) && value.hasValue(PropNameRx) && + value.hasValue(PropNameRy)) { + auto rect = value.getValue(PropNameRect); + if (rect.hasValue(PropNameX) && rect.hasValue(PropNameY) && + rect.hasValue(PropNameWidth) && rect.hasValue(PropNameHeight)) { + auto x = rect.getValue(PropNameX); + auto y = rect.getValue(PropNameY); + auto width = rect.getValue(PropNameWidth); + auto height = rect.getValue(PropNameHeight); + auto rx = value.getValue(PropNameRx); + auto ry = value.getValue(PropNameRy); // Update cache from js object value - setDerivedValue(SkRRect::MakeRectXY( + return std::make_shared(SkRRect::MakeRectXY( SkRect::MakeXYWH(x.getAsNumber(), y.getAsNumber(), width.getAsNumber(), height.getAsNumber()), rx.getAsNumber(), ry.getAsNumber())); @@ -67,6 +67,14 @@ class RRectProp : public DerivedProp { } } } + return nullptr; + } + + void updateDerivedValue() override { + if (_prop->isSet()) { + auto value = _prop->value(); + setDerivedValue(RRectProp::processRRect(value)); + } } private: @@ -78,12 +86,14 @@ class RRectProp : public DerivedProp { */ class RRectPropFromProps : public DerivedProp { public: - RRectPropFromProps() : DerivedProp() { - _x = addProperty(std::make_shared(PropNameX)); - _y = addProperty(std::make_shared(PropNameY)); - _width = addProperty(std::make_shared(PropNameWidth)); - _height = addProperty(std::make_shared(PropNameHeight)); - _r = addProperty(std::make_shared(PropNameR)); + explicit RRectPropFromProps( + const std::function &onChange) + : DerivedProp(onChange) { + _x = defineProperty(PropNameX); + _y = defineProperty(PropNameY); + _width = defineProperty(PropNameWidth); + _height = defineProperty(PropNameHeight); + _r = defineProperty(PropNameR); } void updateDerivedValue() override { @@ -111,17 +121,18 @@ class RRectPropFromProps : public DerivedProp { */ class RRectProps : public DerivedProp { public: - explicit RRectProps(PropId name) : DerivedProp() { - _rectProp = addProperty(std::make_shared(name)); - _rectPropFromProps = - addProperty(std::make_shared()); + explicit RRectProps(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _rectProp = defineProperty(name); + _rectPropFromProps = defineProperty(); } void updateDerivedValue() override { if (_rectProp->isSet()) { - setDerivedValue(_rectProp->getDerivedValue()); + setDerivedValue(_rectProp->getUnsafeDerivedValue()); } else if (_rectPropFromProps->isSet()) { - setDerivedValue(_rectPropFromProps->getDerivedValue()); + setDerivedValue(_rectPropFromProps->getUnsafeDerivedValue()); } else { setDerivedValue(nullptr); } @@ -138,45 +149,19 @@ class RRectProps : public DerivedProp { */ class BoxProps : public DerivedProp { public: - explicit BoxProps(PropId name) : DerivedProp() { - _boxProp = addProperty(std::make_shared(name)); + explicit BoxProps(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _boxProp = defineProperty(name); } void updateDerivedValue() override { - if (_boxProp->value().getType() == PropType::HostObject) { - auto rectPtr = std::dynamic_pointer_cast( - _boxProp->value().getAsHostObject()); - auto rrectPtr = std::dynamic_pointer_cast( - _boxProp->value().getAsHostObject()); - // 1. box is SkRect - if (rectPtr != nullptr) { - auto rect = rectPtr->getObject(); - setDerivedValue(SkRRect::MakeRect(*rect)); - // 2. box is SkRRect - } else if (rrectPtr != nullptr) { - setDerivedValue(rrectPtr->getObject()); - } - } else if (_boxProp->value().getType() == PropType::Object) { - if (_boxProp->value().hasValue(PropNameRect)) { - // 3. box is { rect: { x, y, width, height }, rx, ry } - auto rectProp = _boxProp->value().getValue(PropNameRect); - auto x = rectProp.getValue(PropNameX).getAsNumber(); - auto y = rectProp.getValue(PropNameY).getAsNumber(); - auto width = rectProp.getValue(PropNameWidth).getAsNumber(); - auto height = rectProp.getValue(PropNameHeight).getAsNumber(); - auto rx = _boxProp->value().getValue(PropNameRx).getAsNumber(); - auto ry = _boxProp->value().getValue(PropNameRy).getAsNumber(); - setDerivedValue( - SkRRect::MakeRectXY(SkRect::MakeXYWH(x, y, width, height), rx, ry)); - } else { - // 4. box is { x, y, width, height } - auto x = _boxProp->value().getValue(PropNameX).getAsNumber(); - auto y = _boxProp->value().getValue(PropNameY).getAsNumber(); - auto width = _boxProp->value().getValue(PropNameWidth).getAsNumber(); - auto height = _boxProp->value().getValue(PropNameHeight).getAsNumber(); - setDerivedValue( - SkRRect::MakeRect(SkRect::MakeXYWH(x, y, width, height))); - } + auto value = _boxProp->value(); + auto rect = RectProp::processRect(value); + if (rect) { + setDerivedValue(SkRRect::MakeRect(*rect)); + } else { + setDerivedValue(RRectProp::processRRect(value)); } } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RadiusProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RadiusProp.h index 3639fc7bbaaa5..dd858b148e59a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RadiusProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RadiusProp.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPoint.h" #pragma clang diagnostic pop @@ -16,8 +16,10 @@ namespace RNSkia { class RadiusProp : public DerivedProp { public: - explicit RadiusProp(PropId name) : DerivedProp() { - _radiusProp = addProperty(std::make_shared(name)); + explicit RadiusProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _radiusProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RectProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RectProp.h index c32e73d7fad1d..dc9247985ef56 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RectProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/RectProp.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkRect.h" #pragma clang diagnostic pop @@ -25,37 +25,41 @@ static PropId PropNameHeight = JsiPropId::get("height"); */ class RectProp : public DerivedProp { public: - explicit RectProp(PropId name) : DerivedProp() { - _prop = addProperty(std::make_shared(name)); + explicit RectProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _prop = defineProperty(name); + } + + static std::shared_ptr processRect(const JsiValue &value) { + if (value.getType() == PropType::HostObject) { + auto rectPtr = + std::dynamic_pointer_cast(value.getAsHostObject()); + if (rectPtr != nullptr) { + return std::make_shared(SkRect::MakeXYWH( + rectPtr->getObject()->x(), rectPtr->getObject()->y(), + rectPtr->getObject()->width(), rectPtr->getObject()->height())); + } + } else if (value.getType() == PropType::Object && + value.hasValue(PropNameX) && value.hasValue(PropNameY) && + value.hasValue(PropNameWidth) && + value.hasValue(PropNameHeight)) { + // Save props for fast access + auto x = value.getValue(PropNameX); + auto y = value.getValue(PropNameY); + auto width = value.getValue(PropNameWidth); + auto height = value.getValue(PropNameHeight); + // Update cache from js object value + return std::make_shared( + SkRect::MakeXYWH(x.getAsNumber(), y.getAsNumber(), + width.getAsNumber(), height.getAsNumber())); + } + return nullptr; } void updateDerivedValue() override { if (_prop->isSet()) { - // Check for JsiSkRect - if (_prop->value().getType() == PropType::HostObject) { - auto rectPtr = std::dynamic_pointer_cast( - _prop->value().getAsHostObject()); - if (rectPtr != nullptr) { - setDerivedValue(SkRect::MakeXYWH( - rectPtr->getObject()->x(), rectPtr->getObject()->y(), - rectPtr->getObject()->width(), rectPtr->getObject()->height())); - } - } else { - auto p = _prop->value(); - if (p.hasValue(PropNameX) && p.hasValue(PropNameY) && - p.hasValue(PropNameWidth) && p.hasValue(PropNameHeight)) { - // Save props for fast access - auto x = p.getValue(PropNameX); - auto y = p.getValue(PropNameY); - auto width = p.getValue(PropNameWidth); - auto height = p.getValue(PropNameHeight); - - // Update cache from js object value - setDerivedValue(SkRect::MakeXYWH(x.getAsNumber(), y.getAsNumber(), - width.getAsNumber(), - height.getAsNumber())); - } - } + setDerivedValue(RectProp::processRect(_prop->value())); } } @@ -68,11 +72,13 @@ class RectProp : public DerivedProp { */ class RectPropFromProps : public DerivedProp { public: - RectPropFromProps() : DerivedProp() { - _x = addProperty(std::make_shared(PropNameX)); - _y = addProperty(std::make_shared(PropNameY)); - _width = addProperty(std::make_shared(PropNameWidth)); - _height = addProperty(std::make_shared(PropNameHeight)); + explicit RectPropFromProps( + const std::function &onChange) + : DerivedProp(onChange) { + _x = defineProperty(PropNameX); + _y = defineProperty(PropNameY); + _width = defineProperty(PropNameWidth); + _height = defineProperty(PropNameHeight); } void updateDerivedValue() override { @@ -103,16 +109,18 @@ class RectPropFromProps : public DerivedProp { */ class RectProps : public DerivedProp { public: - explicit RectProps(PropId name) : DerivedProp() { - _rectProp = addProperty(std::make_shared(name)); - _rectPropFromProps = addProperty(std::make_shared()); + explicit RectProps(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _rectProp = defineProperty(name); + _rectPropFromProps = defineProperty(); } void updateDerivedValue() override { if (_rectProp->isSet()) { - setDerivedValue(_rectProp->getDerivedValue()); + setDerivedValue(_rectProp->getUnsafeDerivedValue()); } else if (_rectPropFromProps->isSet()) { - setDerivedValue(_rectPropFromProps->getDerivedValue()); + setDerivedValue(_rectPropFromProps->getUnsafeDerivedValue()); } else { setDerivedValue(nullptr); } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/StrokeProps.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/StrokeProps.h index 3868a707fda01..25bb3e76f7a88 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/StrokeProps.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/StrokeProps.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkPaint.h" #pragma clang diagnostic pop @@ -16,8 +16,10 @@ namespace RNSkia { class StrokeCapProp : public DerivedProp { public: - explicit StrokeCapProp(PropId name) : DerivedProp() { - _strokeCap = addProperty(std::make_shared(name)); + explicit StrokeCapProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _strokeCap = defineProperty(name); } void updateDerivedValue() override { @@ -45,8 +47,10 @@ class StrokeCapProp : public DerivedProp { class StrokeJoinProp : public DerivedProp { public: - explicit StrokeJoinProp(PropId name) : DerivedProp() { - _strokeJoin = addProperty(std::make_shared(name)); + explicit StrokeJoinProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _strokeJoin = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/SvgProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/SvgProp.h index 3f928eb748d52..fedb1dde43f85 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/SvgProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/SvgProp.h @@ -10,24 +10,32 @@ namespace RNSkia { class SvgProp : public DerivedSkProp { public: - explicit SvgProp(PropId name) : DerivedSkProp() { - _imageSvgProp = addProperty(std::make_shared(name)); + explicit SvgProp(PropId name, + const std::function &onChange) + : DerivedSkProp(onChange) { + _imageSvgProp = defineProperty(name); } void updateDerivedValue() override { - if (_imageSvgProp->value().getType() != PropType::HostObject) { - throw std::runtime_error( - "Expected SkSvgDom object for the svg property."); + if (_imageSvgProp->isSet()) { + + if (_imageSvgProp->value().getType() == PropType::HostObject) { + + auto ptr = std::dynamic_pointer_cast( + _imageSvgProp->value().getAsHostObject()); + if (ptr == nullptr) { + throw std::runtime_error( + "Expected SkSvgDom object for the svg property."); + } + setDerivedValue(ptr->getObject()); + } else { + throw std::runtime_error( + "Expected SkSvgDom object or null/undefined for the svg property."); + } + + } else { + setDerivedValue(nullptr); } - - auto ptr = std::dynamic_pointer_cast( - _imageSvgProp->value().getAsHostObject()); - if (ptr == nullptr) { - throw std::runtime_error( - "Expected SkSvgDom object for the svg property."); - } - - setDerivedValue(ptr->getObject()); } private: diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TextBlobProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TextBlobProp.h index c084899f55ad5..5050baf1da47c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TextBlobProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TextBlobProp.h @@ -12,8 +12,10 @@ namespace RNSkia { class TextBlobProp : public DerivedSkProp { public: - explicit TextBlobProp(PropId name) : DerivedSkProp() { - _textBlobProp = addProperty(std::make_shared(name)); + explicit TextBlobProp(PropId name, + const std::function &onChange) + : DerivedSkProp(onChange) { + _textBlobProp = defineProperty(name); } void updateDerivedValue() override { @@ -37,14 +39,13 @@ class TextBlobProp : public DerivedSkProp { class TextPathBlobProp : public DerivedSkProp { public: - TextPathBlobProp() : DerivedSkProp() { - _fontProp = addProperty(std::make_shared(JsiPropId::get("font"))); - _textProp = addProperty(std::make_shared(JsiPropId::get("text"))); - _pathProp = addProperty(std::make_shared(JsiPropId::get("path"))); - _offsetProp = addProperty( - std::make_shared(JsiPropId::get("initialOffset"))); - - _fontProp->require(); + explicit TextPathBlobProp(const std::function &onChange) + : DerivedSkProp(onChange) { + _fontProp = defineProperty("font"); + _textProp = defineProperty("text"); + _pathProp = defineProperty("path"); + _offsetProp = defineProperty("initialOffset"); + _textProp->require(); _pathProp->require(); _offsetProp->require(); @@ -56,66 +57,70 @@ class TextPathBlobProp : public DerivedSkProp { auto path = _pathProp->getDerivedValue(); auto offset = _offsetProp->value().getAsNumber(); - // Get glyphs - auto numGlyphIds = - font->countText(text.c_str(), text.length(), SkTextEncoding::kUTF8); - - std::vector glyphIds; - glyphIds.reserve(numGlyphIds); - auto ids = font->textToGlyphs( - text.c_str(), text.length(), SkTextEncoding::kUTF8, - static_cast(glyphIds.data()), numGlyphIds); - - // Get glyph widths - int glyphsSize = static_cast(ids); - std::vector widthPtrs; - widthPtrs.resize(glyphsSize); - font->getWidthsBounds(glyphIds.data(), numGlyphIds, - static_cast(widthPtrs.data()), nullptr, - nullptr); // TODO: Should we use paint somehow here? - - std::vector rsx; - SkContourMeasureIter meas(*path, false, 1); - - auto cont = meas.next(); - auto dist = offset; - - for (size_t i = 0; i < text.length() && cont != nullptr; ++i) { - auto width = widthPtrs[i]; - dist += width / 2; - if (dist > cont->length()) { - // jump to next contour - cont = meas.next(); - if (cont == nullptr) { - // We have come to the end of the path - terminate the string - // right here. - text = text.substr(0, i); - break; + if (font != nullptr) { + // Get glyphs + auto numGlyphIds = + font->countText(text.c_str(), text.length(), SkTextEncoding::kUTF8); + + std::vector glyphIds; + glyphIds.reserve(numGlyphIds); + auto ids = font->textToGlyphs( + text.c_str(), text.length(), SkTextEncoding::kUTF8, + static_cast(glyphIds.data()), numGlyphIds); + + // Get glyph widths + int glyphsSize = static_cast(ids); + std::vector widthPtrs; + widthPtrs.resize(glyphsSize); + font->getWidthsBounds(glyphIds.data(), numGlyphIds, + static_cast(widthPtrs.data()), nullptr, + nullptr); // TODO: Should we use paint somehow here? + + std::vector rsx; + SkContourMeasureIter meas(*path, false, 1); + + auto cont = meas.next(); + auto dist = offset; + + for (size_t i = 0; i < text.length() && cont != nullptr; ++i) { + auto width = widthPtrs[i]; + dist += width / 2; + if (dist > cont->length()) { + // jump to next contour + cont = meas.next(); + if (cont == nullptr) { + // We have come to the end of the path - terminate the string + // right here. + text = text.substr(0, i); + break; + } + dist = width / 2; } - dist = width / 2; - } - // Gives us the (x, y) coordinates as well as the cos/sin of the tangent - // line at that position. - SkPoint pos; - SkVector tan; - if (!cont->getPosTan(dist, &pos, &tan)) { - throw std::runtime_error( - "Could not calculate distance when resolving text path"); - } - auto px = pos.x(); - auto py = pos.y(); - auto tx = tan.x(); - auto ty = tan.y(); + // Gives us the (x, y) coordinates as well as the cos/sin of the tangent + // line at that position. + SkPoint pos; + SkVector tan; + if (!cont->getPosTan(dist, &pos, &tan)) { + throw std::runtime_error( + "Could not calculate distance when resolving text path"); + } + auto px = pos.x(); + auto py = pos.y(); + auto tx = tan.x(); + auto ty = tan.y(); - auto adjustedX = px - (width / 2) * tx; - auto adjustedY = py - (width / 2) * ty; + auto adjustedX = px - (width / 2) * tx; + auto adjustedY = py - (width / 2) * ty; - rsx.push_back(SkRSXform::Make(tx, ty, adjustedX, adjustedY)); - dist += width / 2; - } + rsx.push_back(SkRSXform::Make(tx, ty, adjustedX, adjustedY)); + dist += width / 2; + } - setDerivedValue(SkTextBlob::MakeFromRSXform(text.c_str(), text.length(), - rsx.data(), *font)); + setDerivedValue(SkTextBlob::MakeFromRSXform(text.c_str(), text.length(), + rsx.data(), *font)); + } else { + setDerivedValue(nullptr); + } } private: diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TileModeProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TileModeProp.h index 50b9e0b3f7966..34a0a95e57239 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TileModeProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TileModeProp.h @@ -5,7 +5,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkTileMode.h" #include #include @@ -16,8 +16,10 @@ namespace RNSkia { class TileModeProp : public DerivedProp { public: - explicit TileModeProp(PropId name) : DerivedProp() { - _tileModeProp = addProperty(std::make_shared(name)); + explicit TileModeProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _tileModeProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformProp.h index 3d3bf8b2ff066..dfb30f842d867 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformProp.h @@ -20,8 +20,10 @@ static PropId PropNameRotateZ = JsiPropId::get("rotateZ"); class TransformProp : public DerivedProp { public: - explicit TransformProp(PropId name) : DerivedProp() { - _transformProp = addProperty(std::make_shared(name)); + explicit TransformProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _transformProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformsProps.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformsProps.h index 9189ef5151dbc..3173b8d32280f 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformsProps.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/TransformsProps.h @@ -12,13 +12,11 @@ namespace RNSkia { class TransformsProps : public DerivedProp { public: - TransformsProps() : DerivedProp() { - _transformProp = addProperty( - std::make_shared(JsiPropId::get("transform"))); - _originProp = - addProperty(std::make_shared(JsiPropId::get("origin"))); - _matrixProp = - addProperty(std::make_shared(JsiPropId::get("matrix"))); + explicit TransformsProps(const std::function &onChange) + : DerivedProp(onChange) { + _transformProp = defineProperty("transform"); + _originProp = defineProperty("origin"); + _matrixProp = defineProperty("matrix"); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/UniformsProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/UniformsProp.h index a888ce46d81d5..8e222d6e1e2c8 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/UniformsProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/UniformsProp.h @@ -10,7 +10,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkRuntimeEffect.h" #pragma clang diagnostic pop @@ -80,8 +80,10 @@ void processUniform(std::vector &values, SkRuntimeEffect *source, class UniformsProp : public DerivedSkProp { public: - UniformsProp(PropId name, NodeProp *sourceProp) : DerivedSkProp() { - _uniformsProp = addProperty(std::make_shared(name)); + UniformsProp(PropId name, NodeProp *sourceProp, + const std::function &onChange) + : DerivedSkProp(onChange) { + _uniformsProp = defineProperty(name); _sourceProp = sourceProp; } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VertexModeProp.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VertexModeProp.h index 2158dbf6cb2c1..548ac48602759 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VertexModeProp.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VertexModeProp.h @@ -8,7 +8,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkVertices.h" #pragma clang diagnostic pop @@ -16,8 +16,10 @@ namespace RNSkia { class VertexModeProp : public DerivedProp { public: - explicit VertexModeProp(PropId name) : DerivedProp() { - _vertexModeProp = addProperty(std::make_shared(name)); + explicit VertexModeProp(PropId name, + const std::function &onChange) + : DerivedProp(onChange) { + _vertexModeProp = defineProperty(name); } void updateDerivedValue() override { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VerticesProps.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VerticesProps.h index be6e7a3176249..c0e23f3d22645 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VerticesProps.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/dom/props/VerticesProps.h @@ -13,7 +13,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include +#include "SkVertices.h" #pragma clang diagnostic pop @@ -21,17 +21,13 @@ namespace RNSkia { class VerticesProps : public DerivedSkProp { public: - VerticesProps() : DerivedSkProp() { - _vertexModeProp = - addProperty(std::make_shared(JsiPropId::get("mode"))); - _colorsProp = - addProperty(std::make_shared(JsiPropId::get("colors"))); - _verticesProp = - addProperty(std::make_shared(JsiPropId::get("vertices"))); - _texturesProp = - addProperty(std::make_shared(JsiPropId::get("textures"))); - _indicesProp = - addProperty(std::make_shared(JsiPropId::get("indices"))); + explicit VerticesProps(const std::function &onChange) + : DerivedSkProp(onChange) { + _vertexModeProp = defineProperty("mode"); + _colorsProp = defineProperty("colors"); + _verticesProp = defineProperty("vertices"); + _texturesProp = defineProperty("textures"); + _indicesProp = defineProperty("indices"); _vertexModeProp->require(); _verticesProp->require(); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkClockValue.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkClockValue.h index 7441c1d60d8d0..b65cb3b7997f0 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkClockValue.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkClockValue.h @@ -1,8 +1,8 @@ #pragma once -#include -#include +#include "RNSkPlatformContext.h" +#include "RNSkReadonlyValue.h" #include #include diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkComputedValue.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkComputedValue.h index d6cedf97224cd..d6071bffac2d1 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkComputedValue.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkComputedValue.h @@ -1,8 +1,8 @@ #pragma once +#include "RNSkPlatformContext.h" #include "RNSkReadonlyValue.h" -#include #include #include diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkReadonlyValue.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkReadonlyValue.h index f558918c8b75d..f8eb5aade6060 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkReadonlyValue.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkReadonlyValue.h @@ -10,9 +10,9 @@ #include -#include -#include -#include +#include "JsiSkHostObjects.h" +#include "JsiValueWrapper.h" +#include "RNSkPlatformContext.h" namespace RNSkia { namespace jsi = facebook::jsi; @@ -72,13 +72,13 @@ class RNSkReadonlyValue }); } - JSI_HOST_FUNCTION(__invalidate) { + JSI_HOST_FUNCTION(dispose) { invalidate(); return jsi::Value::undefined(); } JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkReadonlyValue, addListener), - JSI_EXPORT_FUNC(RNSkReadonlyValue, __invalidate)) + JSI_EXPORT_FUNC(RNSkReadonlyValue, dispose)) /** * Adds a callback that will be called whenever the value changes diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkValue.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkValue.h index 56879b3b870ca..381e0b8c4d7c4 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkValue.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/rnskia/values/RNSkValue.h @@ -3,10 +3,10 @@ #include #include -#include -#include -#include -#include +#include "JsiHostObject.h" +#include "RNSkAnimation.h" +#include "RNSkPlatformContext.h" +#include "RNSkReadonlyValue.h" #include namespace RNSkia { @@ -70,7 +70,7 @@ class RNSkValue : public RNSkReadonlyValue { JSI_EXPORT_PROP_GET(RNSkValue, animation)) JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkValue, addListener), - JSI_EXPORT_FUNC(RNSkReadonlyValue, __invalidate)) + JSI_EXPORT_FUNC(RNSkReadonlyValue, dispose)) private: void subscribe(std::shared_ptr animation) { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h index 5c8059cd91ee7..3407cfd02c00d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkAndroidFrameworkUtils.h @@ -27,7 +27,7 @@ class SkShader; class SkAndroidFrameworkUtils { public: -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** * clipWithStencil draws the current clip into a stencil buffer with reference value and mask * set to 0x1. This function works only on a GPU canvas. @@ -37,7 +37,7 @@ class SkAndroidFrameworkUtils { * @return true on success or false if clip is empty or not a GPU canvas. */ static bool clipWithStencil(SkCanvas* canvas); -#endif //SK_SUPPORT_GPU +#endif //defined(SK_GANESH) static void SafetyNetLog(const char*); @@ -58,12 +58,6 @@ class SkAndroidFrameworkUtils { */ static SkCanvas* getBaseWrappedCanvas(SkCanvas* canvas); - /** - * Skia will change the order in which local matrices concatenate. In order to not break Android - * apps targeting older API levels we offer this function to use the legacy concatenation order. - */ - static void UseLegacyLocalMatrixConcatenation(); - /** * If the shader represents a linear gradient ShaderAsALinearGradient * returns true and if info is not null, ShaderAsALinearGradient populates diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h new file mode 100644 index 0000000000000..14ed009f8c400 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/android/SkImageAndroid.h @@ -0,0 +1,101 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkImageAndroid_DEFINED +#define SkImageAndroid_DEFINED + +#include "include/core/SkImage.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GrTypes.h" + +class SkColorSpace; +class GrDirectContext; +class SkPixmap; +struct AHardwareBuffer; + +namespace SkImages { + +/** (See Skia bug 7447) + Creates SkImage from Android hardware buffer. + Returned SkImage takes a reference on the buffer. + Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + @param hardwareBuffer AHardwareBuffer Android hardware buffer + @param colorSpace range of colors; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer, + SkAlphaType alphaType = kPremul_SkAlphaType); +SK_API sk_sp DeferredFromAHardwareBuffer( + AHardwareBuffer* hardwareBuffer, + SkAlphaType alphaType, + sk_sp colorSpace, + GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); + +/** Creates SkImage from Android hardware buffer and uploads the data from the SkPixmap to it. + Returned SkImage takes a reference on the buffer. + Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + @param context GPU context + @param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer + @param hardwareBuffer AHardwareBuffer Android hardware buffer + @param surfaceOrigin surface origin for resulting image + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromAHardwareBufferWithData( + GrDirectContext* context, + const SkPixmap& pixmap, + AHardwareBuffer* hardwareBuffer, + GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); + +/** + * Like SkImagePriv::SkMakeImageFromRasterBitmap, except this can be pinned using + * skgpu::ganesh::PinAsTexture and CopyPixelMode is never. + */ +SK_API sk_sp PinnableRasterFromBitmap(const SkBitmap&); + +} // namespace SkImages + +// TODO(kjlubick) remove this after Android has been ported. +namespace sk_image_factory { +inline sk_sp MakePinnableFromRasterBitmap(const SkBitmap& b) { + return SkImages::PinnableRasterFromBitmap(b); +} +} // namespace sk_image_factory + +namespace skgpu::ganesh { +/** + * Will attempt to upload and lock the contents of the image as a texture, so that subsequent + * draws to a gpu-target will come from that texture (and not by looking at the original image + * src). In particular this is intended to use the texture even if the image's original content + * changes subsequent to this call (i.e. the src is mutable!). + * + * Only compatible with SkImages created from SkImages::PinnableRasterFromBitmap. + * + * All successful calls must be balanced by an equal number of calls to UnpinTexture(). + * + * Once in this "pinned" state, the image has all of the same thread restrictions that exist + * for a natively created gpu image (e.g. SkImage::MakeFromTexture) + * - all drawing, pinning, unpinning must happen in the same thread as the GrContext. + * + * @return true if the image was successfully uploaded and locked into a texture + */ +bool PinAsTexture(GrRecordingContext*, SkImage*); + +/** + * The balancing call to a successful invocation of PinAsTexture. When a balanced + * number of calls have been made, then the "pinned" texture is free to be purged, etc. This + * also means that a subsequent "pin" call will look at the original content again, and if + * its uniqueID/generationID has changed, then a newer texture will be uploaded/pinned. + * + * Only compatible with SkImages created from SkImages::PinnableRasterFromBitmap. + * + * The context passed to unpin must match the one passed to pin. + */ +void UnpinTexture(GrRecordingContext*, SkImage*); + +} // namespace skgpu::ganesh + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h index 02625838308bd..2b8a79751cfd9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkAndroidCodec.h @@ -9,24 +9,27 @@ #define SkAndroidCodec_DEFINED #include "include/codec/SkCodec.h" -#include "include/core/SkAlphaType.h" #include "include/core/SkColorSpace.h" -#include "include/core/SkColorType.h" -#include "include/core/SkEncodedImageFormat.h" #include "include/core/SkImageInfo.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" #include "include/private/SkEncodedInfo.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/skcms/skcms.h" +// TODO(kjlubick, bungeman) Replace these includes with forward declares +#include "include/codec/SkEncodedImageFormat.h" // IWYU pragma: keep +#include "include/core/SkAlphaType.h" // IWYU pragma: keep +#include "include/core/SkColorType.h" // IWYU pragma: keep + #include #include class SkData; class SkPngChunkReader; class SkStream; +struct SkGainmapInfo; struct SkIRect; /** @@ -118,10 +121,8 @@ class SK_API SkAndroidCodec : SkNoncopyable { /** * @param outputColorType Color type that the client will decode to. * @param prefColorSpace Preferred color space to decode to. - * This may not return |prefColorSpace| for a couple reasons. - * (1) Android Principles: 565 must be sRGB, F16 must be - * linear sRGB, transfer function must be parametric. - * (2) Codec Limitations: F16 requires a linear color space. + * This may not return |prefColorSpace| for + * specific color types. * * Returns the appropriate color space to decode to. */ @@ -262,6 +263,23 @@ class SK_API SkAndroidCodec : SkNoncopyable { SkCodec* codec() const { return fCodec.get(); } + /** + * Retrieve the gainmap for an image. + * + * @param outInfo On success, this is populated with the parameters for + * rendering this gainmap. This parameter must be non-nullptr. + * + * @param outGainmapImageStream On success, this is populated with a stream from which the + * gainmap image may be decoded. This parameter is optional, and + * may be set to nullptr. + * + * @return If this has a gainmap image and that gainmap image was + * successfully extracted then return true. Otherwise return + * false. + */ + bool getAndroidGainmap(SkGainmapInfo* outInfo, + std::unique_ptr* outGainmapImageStream); + protected: SkAndroidCodec(SkCodec*); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h index 5af847afcfe30..3ed1a95a800c9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkCodec.h @@ -8,10 +8,7 @@ #ifndef SkCodec_DEFINED #define SkCodec_DEFINED -#include "include/codec/SkCodecAnimation.h" #include "include/codec/SkEncodedOrigin.h" -#include "include/core/SkAlphaType.h" -#include "include/core/SkEncodedImageFormat.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" #include "include/core/SkRect.h" @@ -20,21 +17,30 @@ #include "include/core/SkTypes.h" #include "include/core/SkYUVAPixmaps.h" #include "include/private/SkEncodedInfo.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/skcms/skcms.h" #include +#include #include #include #include -class SkAndroidCodec; class SkData; class SkFrameHolder; class SkImage; class SkPngChunkReader; class SkSampler; class SkStream; +struct SkGainmapInfo; +enum SkAlphaType : int; +enum class SkEncodedImageFormat; + +namespace SkCodecAnimation { +enum class Blend; +enum class DisposalMethod; +} + namespace DM { class CodecSrc; @@ -767,6 +773,8 @@ class SK_API SkCodec : SkNoncopyable { return fSrcXformFormat; } + virtual bool onGetGainmapInfo(SkGainmapInfo*, std::unique_ptr*) { return false; } + virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const { // By default, scaling is not supported. return this->dimensions(); @@ -887,8 +895,8 @@ class SK_API SkCodec : SkNoncopyable { const SkEncodedInfo fEncodedInfo; XformFormat fSrcXformFormat; std::unique_ptr fStream; - bool fNeedsRewind; - const SkEncodedOrigin fOrigin; + bool fNeedsRewind = false; + const SkEncodedOrigin fOrigin; SkImageInfo fDstInfo; Options fOptions; @@ -904,13 +912,13 @@ class SK_API SkCodec : SkNoncopyable { skcms_AlphaFormat fDstXformAlphaFormat; // Only meaningful during scanline decodes. - int fCurrScanline; + int fCurrScanline = -1; - bool fStartedIncrementalDecode; + bool fStartedIncrementalDecode = false; // Allows SkAndroidCodec to call handleFrameIndex (potentially decoding a prior frame and - // clearing to transparent) without SkCodec calling it, too. - bool fAndroidCodecHandlesFrameIndex; + // clearing to transparent) without SkCodec itself calling it, too. + bool fUsingCallbackForHandleFrameIndex = false; bool initializeColorXform(const SkImageInfo& dstInfo, SkEncodedInfo::Alpha, bool srcIsOpaque); @@ -934,17 +942,23 @@ class SK_API SkCodec : SkNoncopyable { return nullptr; } + // Callback for decoding a prior frame. The `Options::fFrameIndex` is ignored, + // being replaced by frameIndex. This allows opts to actually be a subclass of + // SkCodec::Options which SkCodec itself does not know how to copy or modify, + // but just passes through to the caller (where it can be reinterpret_cast'd). + using GetPixelsCallback = std::function; + /** * Check for a valid Options.fFrameIndex, and decode prior frames if necessary. * - * If androidCodec is not null, that means this SkCodec is owned by an SkAndroidCodec. In that - * case, the Options will be treated as an AndroidOptions, and SkAndroidCodec will be used to - * decode a prior frame, if a prior frame is needed. When such an owned SkCodec calls - * handleFrameIndex, it will immediately return kSuccess, since SkAndroidCodec already handled - * it. + * If GetPixelsCallback is not null, it will be used to decode a prior frame instead + * of using this SkCodec directly. It may also be used recursively, if that in turn + * depends on a prior frame. This is used by SkAndroidCodec. */ Result handleFrameIndex(const SkImageInfo&, void* pixels, size_t rowBytes, const Options&, - SkAndroidCodec* androidCodec = nullptr); + GetPixelsCallback = nullptr); // Methods for scanline decoding. virtual Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/, diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h new file mode 100644 index 0000000000000..99ca44e765c53 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkEncodedImageFormat.h @@ -0,0 +1,36 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkEncodedImageFormat_DEFINED +#define SkEncodedImageFormat_DEFINED + +#include + +/** + * Enum describing format of encoded data. + */ +enum class SkEncodedImageFormat { +#ifdef SK_BUILD_FOR_GOOGLE3 + kUnknown, +#endif + kBMP, + kGIF, + kICO, + kJPEG, + kPNG, + kWBMP, + kWEBP, + kPKM, + kKTX, + kASTC, + kDNG, + kHEIF, + kAVIF, + kJPEGXL, +}; + +#endif // SkEncodedImageFormat_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h new file mode 100644 index 0000000000000..0df4a36f0c247 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPixmapUtils.h @@ -0,0 +1,31 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkPixmapUtils_DEFINED +#define SkPixmapUtils_DEFINED + +#include "include/codec/SkEncodedOrigin.h" +#include "include/core/SkImageInfo.h" +#include "include/private/base/SkAPI.h" + +class SkPixmap; + +namespace SkPixmapUtils { +/** + * Copy the pixels in src into dst, applying the orientation transformations specified + * by origin. If the inputs are invalid, this returns false and no copy is made. + */ +SK_API bool Orient(const SkPixmap& dst, const SkPixmap& src, SkEncodedOrigin origin); + +/** + * Return a copy of the provided ImageInfo with the width and height swapped. + */ +SK_API SkImageInfo SwapWidthHeight(const SkImageInfo& info); + +} // namespace SkPixmapUtils + +#endif // SkPixmapUtils_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPngChunkReader.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPngChunkReader.h similarity index 100% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPngChunkReader.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/codec/SkPngChunkReader.h diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h index 313d324e405b8..74c21f9438b9e 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/config/SkUserConfig.h @@ -1,4 +1,3 @@ - /* * Copyright 2006 The Android Open Source Project * @@ -6,7 +5,6 @@ * found in the LICENSE file. */ - #ifndef SkUserConfig_DEFINED #define SkUserConfig_DEFINED @@ -16,9 +14,9 @@ Below are optional defines that add, subtract, or change default behavior in Skia. Your port can locally edit this file to enable/disable flags as - you choose, or these can be delared on your command line (i.e. -Dfoo). + you choose, or these can be declared on your command line (i.e. -Dfoo). - By default, this include file will always default to having all of the flags + By default, this #include file will always default to having all the flags commented out, so including it will have no effect. */ @@ -32,58 +30,92 @@ By default, these mutually exclusive flags are defined in SkTypes.h, based on the presence or absence of NDEBUG, but that decision can be changed here. - */ +*/ //#define SK_DEBUG //#define SK_RELEASE /* To write debug messages to a console, skia will call SkDebugf(...) following printf conventions (e.g. const char* format, ...). If you want to redirect this to something other than printf, define yours here - */ +*/ //#define SkDebugf(...) MyFunction(__VA_ARGS__) -/* - * To specify a different default font cache limit, define this. If this is - * undefined, skia will use a built-in value. - */ +/* Skia has both debug and release asserts. When an assert fails SK_ABORT will + be used to report an abort message. SK_ABORT is expected not to return. Skia + provides a default implementation which will print the message with SkDebugf + and then call sk_abort_no_print. +*/ +//#define SK_ABORT(message, ...) + +/* To specify a different default font strike cache memory limit, define this. If this is + undefined, skia will use a built-in value. +*/ //#define SK_DEFAULT_FONT_CACHE_LIMIT (1024 * 1024) -/* - * To specify the default size of the image cache, undefine this and set it to - * the desired value (in bytes). SkGraphics.h as a runtime API to set this - * value as well. If this is undefined, a built-in value will be used. - */ +/* To specify a different default font strike cache count limit, define this. If this is + undefined, skia will use a built-in value. +*/ +// #define SK_DEFAULT_FONT_CACHE_COUNT_LIMIT 2048 + +/* To specify the default size of the image cache, undefine this and set it to + the desired value (in bytes). SkGraphics.h as a runtime API to set this + value as well. If this is undefined, a built-in value will be used. +*/ //#define SK_DEFAULT_IMAGE_CACHE_LIMIT (1024 * 1024) /* Define this to set the upper limit for text to support LCD. Values that are very large increase the cost in the font cache and draw slower, without improving readability. If this is undefined, Skia will use its default value (e.g. 48) - */ +*/ //#define SK_MAX_SIZE_FOR_LCDTEXT 48 /* Change the kN32_SkColorType ordering to BGRA to work in X windows. - */ +*/ //#define SK_R32_SHIFT 16 - -/* Determines whether to build code that supports the GPU backend. Some classes +/* Determines whether to build code that supports the Ganesh GPU backend. Some classes that are not GPU-specific, such as SkShader subclasses, have optional code - that is used allows them to interact with the GPU backend. If you'd like to - omit this code set SK_SUPPORT_GPU to 0. This also allows you to omit the gpu - directories from your include search path when you're not building the GPU - backend. Defaults to 1 (build the GPU code). - */ -//#define SK_SUPPORT_GPU 1 + that is used allows them to interact with this GPU backend. If you'd like to + include this code, include -DSK_GANESH in your cflags or uncomment below. + Defaults to not set (No Ganesh GPU backend). + This define affects the ABI of Skia, so make sure it matches the client which uses + the compiled version of Skia. +*/ +//#define SK_GANESH /* Skia makes use of histogram logging macros to trace the frequency of - * events. By default, Skia provides no-op versions of these macros. - * Skia consumers can provide their own definitions of these macros to - * integrate with their histogram collection backend. - */ + events. By default, Skia provides no-op versions of these macros. + Skia consumers can provide their own definitions of these macros to + integrate with their histogram collection backend. +*/ //#define SK_HISTOGRAM_BOOLEAN(name, sample) //#define SK_HISTOGRAM_ENUMERATION(name, sample, enum_size) //#define SK_HISTOGRAM_EXACT_LINEAR(name, sample, value_max) //#define SK_HISTOGRAM_MEMORY_KB(name, sample) +/* Skia tries to make use of some non-standard C++ language extensions. + By default, Skia provides msvc and clang/gcc versions of these macros. + Skia consumers can provide their own definitions of these macros to + integrate with their own compilers and build system. +*/ +//#define SK_UNUSED [[maybe_unused]] +//#define SK_WARN_UNUSED_RESULT [[nodiscard]] +//#define SK_ALWAYS_INLINE inline __attribute__((always_inline)) +//#define SK_NEVER_INLINE __attribute__((noinline)) +//#define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) +//#define SK_NO_SANITIZE(A) __attribute__((no_sanitize(A))) +//#define SK_TRIVIAL_ABI [[clang::trivial_abi]] + +/* + * If compiling Skia as a DLL, public APIs should be exported. Skia will set + * SK_API to something sensible for Clang and MSVC, but if clients need to + * customize it for their build system or compiler, they may. + * If a client needs to use SK_API (e.g. overriding SK_ABORT), then they + * *must* define their own, the default will not be defined prior to loading + * this file. + */ +//#define SK_API __declspec(dllexport) + + #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h index 658f20716e7e5..d4ed7a6000b7a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBitmap.h @@ -8,24 +8,32 @@ #ifndef SkBitmap_DEFINED #define SkBitmap_DEFINED +#include "include/core/SkAlphaType.h" #include "include/core/SkColor.h" #include "include/core/SkImageInfo.h" -#include "include/core/SkMatrix.h" #include "include/core/SkPixmap.h" #include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/core/SkShader.h" -#include "include/core/SkTileMode.h" +#include "include/core/SkSamplingOptions.h" +#include "include/core/SkSize.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkDebug.h" + +#include +#include -class SkBitmap; class SkColorSpace; -struct SkMask; +class SkImage; +class SkMatrix; class SkMipmap; -struct SkIRect; -struct SkRect; class SkPaint; class SkPixelRef; class SkShader; +enum SkColorType : int; +enum class SkTileMode; +struct SkMask; /** \class SkBitmap SkBitmap describes a two-dimensional raster pixel array. SkBitmap is built on @@ -766,11 +774,10 @@ class SK_API SkBitmap { treated as opaque. If colorType() is kAlpha_8_SkColorType, then RGB is ignored. @param c unpremultiplied color - @param colorSpace SkColorSpace of c example: https://fiddle.skia.org/c/@Bitmap_eraseColor */ - void eraseColor(SkColor4f c, SkColorSpace* colorSpace = nullptr) const; + void eraseColor(SkColor4f) const; /** Replaces pixel values with c, interpreted as being in the sRGB SkColorSpace. All pixels contained by bounds() are affected. If the colorType() is @@ -810,11 +817,9 @@ class SK_API SkBitmap { @param c unpremultiplied color @param area rectangle to fill - @param colorSpace SkColorSpace of c example: https://fiddle.skia.org/c/@Bitmap_erase */ - void erase(SkColor4f c, SkColorSpace* colorSpace, const SkIRect& area) const; void erase(SkColor4f c, const SkIRect& area) const; /** Replaces pixel values inside area with c. interpreted as being in the sRGB @@ -1168,23 +1173,18 @@ class SK_API SkBitmap { example: https://fiddle.skia.org/c/@Bitmap_peekPixels */ bool peekPixels(SkPixmap* pixmap) const; - sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, - const SkMatrix* = nullptr) const; + /** + * Make a shader with the specified tiling, matrix and sampling. + */ + sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, + const SkMatrix* localMatrix = nullptr) const; sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& localMatrix) const { - return this->makeShader(tmx, tmy, sampling, &localMatrix); - } - - sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix* localMatrix = nullptr) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, localMatrix); - } - + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix& localMatrix) const { - return this->makeShader(sampling, &localMatrix); - } + const SkMatrix* lm = nullptr) const; /** * Returns a new image from the bitmap. If the bitmap is marked immutable, this will diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h index aec37b6e686de..f0dde10f25c6b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkBlurTypes.h @@ -8,8 +8,6 @@ #ifndef SkBlurTypes_DEFINED #define SkBlurTypes_DEFINED -#include "include/core/SkTypes.h" - enum SkBlurStyle : int { kNormal_SkBlurStyle, //!< fuzzy inside and outside kSolid_SkBlurStyle, //!< solid inside, fuzzy outside diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h index b16872809e322..225b733a6b717 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCanvas.h @@ -12,6 +12,7 @@ #include "include/core/SkClipOp.h" #include "include/core/SkColor.h" #include "include/core/SkFontTypes.h" +#include "include/core/SkImageFilter.h" #include "include/core/SkImageInfo.h" #include "include/core/SkM44.h" #include "include/core/SkMatrix.h" @@ -26,13 +27,13 @@ #include "include/core/SkString.h" #include "include/core/SkSurfaceProps.h" #include "include/core/SkTypes.h" -#include "include/private/SkDeque.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkDeque.h" +#include #include #include #include -#include #ifndef SK_SUPPORT_LEGACY_GETTOTALMATRIX #define SK_SUPPORT_LEGACY_GETTOTALMATRIX @@ -44,34 +45,39 @@ class GlyphRunList; } class AutoLayerForImageFilter; -class GrBackendRenderTarget; class GrRecordingContext; + class SkBaseDevice; class SkBitmap; +class SkBlender; class SkData; class SkDrawable; -struct SkDrawShadowRec; class SkFont; class SkImage; -class SkImageFilter; +class SkMesh; class SkPaintFilterCanvas; class SkPath; class SkPicture; class SkPixmap; -class SkRegion; class SkRRect; -struct SkRSXform; -class SkMesh; +class SkRegion; +class SkShader; class SkSpecialImage; class SkSurface; class SkSurface_Base; class SkTextBlob; class SkVertices; +struct SkDrawShadowRec; +struct SkRSXform; namespace skgpu::graphite { class Recorder; } namespace sktext::gpu { class Slug; } namespace SkRecords { class Draw; } +#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_GANESH) +class GrBackendRenderTarget; +#endif + // TODO: // This is not ideal but Chrome is depending on a forward decl of GrSlug here. // It should be removed once Chrome has migrated to sktext::gpu::Slug. @@ -650,7 +656,7 @@ class SK_API SkCanvas { SkRect bounds suggests but does not define layer size. To clip drawing to a specific rectangle, use clipRect(). - alpha of zero is fully transparent, 255 is fully opaque. + alpha of zero is fully transparent, 1.0f is fully opaque. Call restoreToCount() with returned value to restore this and subsequent saves. @@ -660,7 +666,11 @@ class SK_API SkCanvas { example: https://fiddle.skia.org/c/@Canvas_saveLayerAlpha */ - int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); + int saveLayerAlphaf(const SkRect* bounds, float alpha); + // Helper that accepts an int between 0 and 255, and divides it by 255.0 + int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { + return this->saveLayerAlphaf(bounds, alpha * (1.0f / 255)); + } /** \enum SkCanvas::SaveLayerFlagsSet SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, @@ -2173,7 +2183,7 @@ class SK_API SkCanvas { /////////////////////////////////////////////////////////////////////////// -#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && SK_SUPPORT_GPU +#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(SK_GANESH) // These methods exist to support WebView in Android Framework. SkIRect topLayerBounds() const; GrBackendRenderTarget topLayerBackendRenderTarget() const; @@ -2290,7 +2300,7 @@ class SK_API SkCanvas { virtual void onDiscard(); -#if (SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED)) +#if (defined(SK_GANESH) || defined(SK_GRAPHITE)) /** Experimental */ virtual sk_sp onConvertGlyphRunListToSlug( @@ -2352,6 +2362,13 @@ class SK_API SkCanvas { // Encapsulate state needed to restore from saveBehind() struct BackImage { + // Out of line to avoid including SkSpecialImage.h + BackImage(sk_sp, SkIPoint); + BackImage(const BackImage&); + BackImage(BackImage&&); + BackImage& operator=(const BackImage&); + ~BackImage(); + sk_sp fImage; SkIPoint fLoc; }; @@ -2406,7 +2423,7 @@ class SK_API SkCanvas { fSurfaceBase = sb; } friend class SkSurface_Base; - friend class SkSurface_Gpu; + friend class SkSurface_Ganesh; SkIRect fClipRestrictionRect = SkIRect::MakeEmpty(); int fClipRestrictionSaveCount = -1; @@ -2440,7 +2457,7 @@ class SK_API SkCanvas { SkCanvas& operator=(SkCanvas&&) = delete; SkCanvas& operator=(const SkCanvas&) = delete; -#if (SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED)) +#if (defined(SK_GANESH) || defined(SK_GRAPHITE)) friend class sktext::gpu::Slug; /** Experimental * Convert a SkTextBlob to a sktext::gpu::Slug using the current canvas state. diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h index ef15c1670823d..214b5138f0b71 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCapabilities.h @@ -15,7 +15,7 @@ namespace SkSL { struct ShaderCaps; } #endif -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) namespace skgpu::graphite { class Caps; } #endif @@ -28,7 +28,7 @@ class SK_API SkCapabilities : public SkRefCnt { #endif protected: -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) friend class skgpu::graphite::Caps; // for ctor #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h index 6a920e93fddb4..3b46be030f224 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColor.h @@ -11,8 +11,10 @@ #include "include/core/SkAlphaType.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" #include +#include /** \file SkColor.h diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h index 29f64339baaac..f89de9db72fcb 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorPriv.h @@ -9,9 +9,11 @@ #define SkColorPriv_DEFINED #include "include/core/SkColor.h" -#include "include/core/SkMath.h" -#include "include/private/SkTPin.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkTPin.h" +#include "include/private/base/SkTo.h" + +#include /** Turn 0..255 into 0..256 by adding 1 at the half-way point. Used to turn a byte into a scale value, so that we can say scale * value >> 8 instead of @@ -146,7 +148,20 @@ static SK_ALWAYS_INLINE uint32_t SkAlphaMulQ(uint32_t c, unsigned scale) { } static inline SkPMColor SkPMSrcOver(SkPMColor src, SkPMColor dst) { - return src + SkAlphaMulQ(dst, SkAlpha255To256(255 - SkGetPackedA32(src))); + uint32_t scale = SkAlpha255To256(255 - SkGetPackedA32(src)); + + uint32_t mask = 0xFF00FF; + uint32_t rb = (((dst & mask) * scale) >> 8) & mask; + uint32_t ag = (((dst >> 8) & mask) * scale) & ~mask; + + rb += (src & mask); + ag += (src & ~mask); + + // Color channels (but not alpha) can overflow, so we have to saturate to 0xFF in each lane. + return std::min(rb & 0x000001FF, 0x000000FFU) | + std::min(ag & 0x0001FF00, 0x0000FF00U) | + std::min(rb & 0x01FF0000, 0x00FF0000U) | + (ag & 0xFF000000); } #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h index a09758645b161..57c29e222a43b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorSpace.h @@ -9,10 +9,13 @@ #define SkColorSpace_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkFixed.h" -#include "include/private/SkOnce.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkFixed.h" +#include "include/private/base/SkOnce.h" #include "modules/skcms/skcms.h" -#include + +#include +#include class SkData; @@ -147,8 +150,7 @@ class SK_API SkColorSpace : public SkNVRefCnt { bool isNumericalTransferFn(skcms_TransferFunction* fn) const; /** - * Returns true and sets |toXYZD50| if the color gamut can be described as a matrix. - * Returns false otherwise. + * Returns true and sets |toXYZD50|. */ bool toXYZD50(skcms_Matrix3x3* toXYZD50) const; @@ -160,23 +162,19 @@ class SK_API SkColorSpace : public SkNVRefCnt { /** * Returns a color space with the same gamut as this one, but with a linear gamma. - * For color spaces whose gamut can not be described in terms of XYZ D50, returns - * linear sRGB. */ sk_sp makeLinearGamma() const; /** - * Returns a color space with the same gamut as this one, with with the sRGB transfer - * function. For color spaces whose gamut can not be described in terms of XYZ D50, returns - * sRGB. + * Returns a color space with the same gamut as this one, but with the sRGB transfer + * function. */ sk_sp makeSRGBGamma() const; /** * Returns a color space with the same transfer function as this one, but with the primary - * colors rotated. For any XYZ space, this produces a new color space that maps RGB to GBR - * (when applied to a source), and maps RGB to BRG (when applied to a destination). For other - * types of color spaces, returns nullptr. + * colors rotated. In other words, this produces a new color space that maps RGB to GBR + * (when applied to a source), and maps RGB to BRG (when applied to a destination). * * This is used for testing, to construct color spaces that have severe and testable behavior. */ @@ -190,15 +188,14 @@ class SK_API SkColorSpace : public SkNVRefCnt { * in some cases: converting ICC fixed point to float, converting white point to D50, * rounding decisions on transfer function and matrix. * - * This does not consider a 2.2f exponential transfer function to be sRGB. While these + * This does not consider a 2.2f exponential transfer function to be sRGB. While these * functions are similar (and it is sometimes useful to consider them together), this * function checks for logical equality. */ bool isSRGB() const; /** - * Returns nullptr on failure. Fails when we fallback to serializing ICC data and - * the data is too large to serialize. + * Returns a serialized representation of this color space. */ sk_sp serialize() const; @@ -211,7 +208,7 @@ class SK_API SkColorSpace : public SkNVRefCnt { static sk_sp Deserialize(const void* data, size_t length); /** - * If both are null, we return true. If one is null and the other is not, we return false. + * If both are null, we return true. If one is null and the other is not, we return false. * If both are non-null, we do a deeper compare. */ static bool Equals(const SkColorSpace*, const SkColorSpace*); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h index b51aa7b96f96b..a68dc833b49b5 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkColorType.h @@ -28,6 +28,7 @@ enum SkColorType : int { kBGRA_1010102_SkColorType, //!< 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word kRGB_101010x_SkColorType, //!< pixel with 10 bits each for red, green, blue; in 32-bit word kBGR_101010x_SkColorType, //!< pixel with 10 bits each for blue, green, red; in 32-bit word + kBGR_101010x_XR_SkColorType, //!< pixel with 10 bits each for blue, green, red; in 32-bit word, extended range kGray_8_SkColorType, //!< pixel with grayscale level in 8-bit byte kRGBA_F16Norm_SkColorType, //!< pixel with half floats in [0,1] for red, green, blue, alpha; // in 64-bit word diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h index 08a50b11054c8..7090deaaed22a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkContourMeasure.h @@ -10,7 +10,7 @@ #include "include/core/SkPath.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" struct SkConic; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h index ea5b73d1a4776..aaae60c41920d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCoverageMode.h @@ -8,8 +8,6 @@ #ifndef SkCoverageMode_DEFINED #define SkCoverageMode_DEFINED -#include "include/core/SkTypes.h" - /** * Describes geometric operations (ala SkRegion::Op) that can be applied to coverage bytes. * These can be thought of as variants of porter-duff (SkBlendMode) modes, but only applied diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h index 7389b92afd099..863c9333f6e1e 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkCubicMap.h @@ -9,6 +9,8 @@ #define SkCubicMap_DEFINED #include "include/core/SkPoint.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" /** * Fast evaluation of a cubic ease-in / ease-out curve. This is defined as a parametric cubic diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkData.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkData.h index 2a4b40d5f614a..2b50cebc81b6a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkData.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkData.h @@ -8,9 +8,12 @@ #ifndef SkData_DEFINED #define SkData_DEFINED -#include - #include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" + +#include +#include class SkStream; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h index a6a510b7b221e..3aa48d5f33ea0 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDataTable.h @@ -8,8 +8,12 @@ #ifndef SkDataTable_DEFINED #define SkDataTable_DEFINED -#include "include/core/SkData.h" -#include "include/private/SkTDArray.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" + +#include +#include /** * Like SkData, SkDataTable holds an immutable data buffer. The data buffer is diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h index 28e460fa8b050..e5511beea3aea 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayList.h @@ -13,10 +13,11 @@ #include "include/core/SkTypes.h" class SkDeferredDisplayListPriv; +class SkPromiseImageTexture; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrRecordingContext.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include class GrRenderTask; class GrRenderTargetProxy; @@ -36,7 +37,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { return fCharacterization; } -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** * Iterate through the programs required by the DDL. */ @@ -52,7 +53,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { private: GrDirectContext* fDContext; - const SkTArray& fProgramData; + const skia_private::TArray& fProgramData; int fIndex; }; #endif @@ -70,7 +71,7 @@ class SkDeferredDisplayList : public SkNVRefCnt { // texture when the DDL is replayed. It has to be separately ref counted bc the lazy proxy // can outlive the DDL. class LazyProxyData : public SkRefCnt { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) public: // Upon being replayed - this field will be filled in (by the DrawingManager) with the // proxy backing the destination SkSurface. Note that, since there is no good place to @@ -87,21 +88,21 @@ class SkDeferredDisplayList : public SkNVRefCnt { sk_sp fTargetProxy, sk_sp); -#if SK_SUPPORT_GPU - const SkTArray& programData() const { +#if defined(SK_GANESH) + const skia_private::TArray& programData() const { return fProgramData; } #endif const SkSurfaceCharacterization fCharacterization; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) // These are ordered such that the destructor cleans op tasks up first (which may refer back // to the arena and memory pool in their destructors). GrRecordingContext::OwnedArenas fArenas; - SkTArray> fRenderTasks; + skia_private::TArray> fRenderTasks; - SkTArray fProgramData; + skia_private::TArray fProgramData; sk_sp fTargetProxy; sk_sp fLazyProxyData; #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h index 8103485597fcf..cd91798513bdf 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDeferredDisplayListRecorder.h @@ -50,13 +50,14 @@ class SK_API SkDeferredDisplayListRecorder { sk_sp detach(); -#if SK_SUPPORT_GPU - using PromiseImageTextureContext = SkImage::PromiseImageTextureContext; - using PromiseImageTextureFulfillProc = SkImage::PromiseImageTextureFulfillProc; - using PromiseImageTextureReleaseProc = SkImage::PromiseImageTextureReleaseProc; +#if defined(SK_GANESH) + using PromiseImageTextureContext = void*; + using PromiseImageTextureFulfillProc = + sk_sp (*)(PromiseImageTextureContext); + using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); #ifndef SK_MAKE_PROMISE_TEXTURE_DISABLE_LEGACY_API - /** Deprecated: Use SkImage::MakePromiseTexture instead. */ + /** Deprecated: Use SkImages::PromiseTextureFrom instead. */ sk_sp makePromiseTexture(const GrBackendFormat& backendFormat, int width, int height, @@ -69,14 +70,14 @@ class SK_API SkDeferredDisplayListRecorder { PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContext); - /** Deprecated: Use SkImage::MakePromiseYUVATexture instead. */ + /** Deprecated: Use SkImages::PromiseTextureFromYUVA instead. */ sk_sp makeYUVAPromiseTexture(const GrYUVABackendTextureInfo& yuvaBackendTextureInfo, sk_sp imageColorSpace, PromiseImageTextureFulfillProc textureFulfillProc, PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContexts[]); #endif // SK_MAKE_PROMISE_TEXTURE_DISABLE_LEGACY_API -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) private: SkDeferredDisplayListRecorder(const SkDeferredDisplayListRecorder&) = delete; @@ -86,7 +87,7 @@ class SK_API SkDeferredDisplayListRecorder { const SkSurfaceCharacterization fCharacterization; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) sk_sp fContext; sk_sp fTargetProxy; sk_sp fLazyProxyData; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h index c86543dc6b367..316bf058bcf5a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkDrawable.h @@ -9,14 +9,22 @@ #define SkDrawable_DEFINED #include "include/core/SkFlattenable.h" -#include "include/core/SkImageInfo.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" +#include "include/private/base/SkAPI.h" + +#include +#include +#include class GrBackendDrawableInfo; class SkCanvas; class SkMatrix; class SkPicture; -enum class GrBackendApi : unsigned; +enum class GrBackendApi : unsigned int; +struct SkDeserialProcs; +struct SkIRect; +struct SkImageInfo; struct SkRect; /** diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h index 99ca44e765c53..0db3830b9ac71 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkEncodedImageFormat.h @@ -1,36 +1,9 @@ /* - * Copyright 2015 Google Inc. + * Copyright 2023 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#ifndef SkEncodedImageFormat_DEFINED -#define SkEncodedImageFormat_DEFINED - -#include - -/** - * Enum describing format of encoded data. - */ -enum class SkEncodedImageFormat { -#ifdef SK_BUILD_FOR_GOOGLE3 - kUnknown, -#endif - kBMP, - kGIF, - kICO, - kJPEG, - kPNG, - kWBMP, - kWEBP, - kPKM, - kKTX, - kASTC, - kDNG, - kHEIF, - kAVIF, - kJPEGXL, -}; - -#endif // SkEncodedImageFormat_DEFINED +// TODO(kjlubick) remove this shim after clients have been moved to the new location +#include "include/codec/SkEncodedImageFormat.h" // IWYU pragma: export diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h index 916ee174f4828..3585e845b5489 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFlattenable.h @@ -9,13 +9,15 @@ #define SkFlattenable_DEFINED #include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +#include class SkData; class SkReadBuffer; class SkWriteBuffer; - -struct SkSerialProcs; struct SkDeserialProcs; +struct SkSerialProcs; /** \class SkFlattenable diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h index 05fb7db414887..88e92694bd455 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFont.h @@ -11,6 +11,7 @@ #include "include/core/SkFontTypes.h" #include "include/core/SkScalar.h" #include "include/core/SkTypeface.h" +#include "include/private/base/SkTemplates.h" #include diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h index 717a87f056f38..f4960393113cb 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMetrics.h @@ -9,6 +9,7 @@ #define SkFontMetrics_DEFINED #include "include/core/SkScalar.h" +#include "include/private/base/SkTo.h" /** \class SkFontMetrics The metrics of an SkFont. diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h index 125262b466753..eccb0a729cba0 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontMgr.h @@ -13,6 +13,8 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkTypes.h" +#include + class SkData; class SkFontData; class SkStreamAsset; @@ -23,23 +25,20 @@ class SK_API SkFontStyleSet : public SkRefCnt { public: virtual int count() = 0; virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0; - virtual SkTypeface* createTypeface(int index) = 0; - virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0; + virtual sk_sp createTypeface(int index) = 0; + virtual sk_sp matchStyle(const SkFontStyle& pattern) = 0; - static SkFontStyleSet* CreateEmpty(); + static sk_sp CreateEmpty(); protected: - SkTypeface* matchStyleCSS3(const SkFontStyle& pattern); - -private: - using INHERITED = SkRefCnt; + sk_sp matchStyleCSS3(const SkFontStyle& pattern); }; class SK_API SkFontMgr : public SkRefCnt { public: int countFamilies() const; void getFamilyName(int index, SkString* familyName) const; - SkFontStyleSet* createStyleSet(int index) const; + sk_sp createStyleSet(int index) const; /** * The caller must call unref() on the returned object. @@ -52,7 +51,7 @@ class SK_API SkFontMgr : public SkRefCnt { * It is possible that this will return a style set not accessible from * createStyleSet(int) due to hidden or auto-activated fonts. */ - SkFontStyleSet* matchFamily(const char familyName[]) const; + sk_sp matchFamily(const char familyName[]) const; /** * Find the closest matching typeface to the specified familyName and style @@ -66,7 +65,7 @@ class SK_API SkFontMgr : public SkRefCnt { * createStyleSet(int) or matchFamily(const char[]) due to hidden or * auto-activated fonts. */ - SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&) const; + sk_sp matchFamilyStyle(const char familyName[], const SkFontStyle&) const; /** * Use the system fallback to find a typeface for the given character. @@ -83,9 +82,9 @@ class SK_API SkFontMgr : public SkRefCnt { * most significant. If no specified bcp47 codes match, any font with the * requested character will be matched. */ - SkTypeface* matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const; + sk_sp matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const; /** * Create a typeface for the specified data and TTC index (pass 0 for none) @@ -123,16 +122,17 @@ class SK_API SkFontMgr : public SkRefCnt { protected: virtual int onCountFamilies() const = 0; virtual void onGetFamilyName(int index, SkString* familyName) const = 0; - virtual SkFontStyleSet* onCreateStyleSet(int index)const = 0; + virtual sk_sp onCreateStyleSet(int index)const = 0; /** May return NULL if the name is not found. */ - virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const = 0; + virtual sk_sp onMatchFamily(const char familyName[]) const = 0; - virtual SkTypeface* onMatchFamilyStyle(const char familyName[], - const SkFontStyle&) const = 0; - virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const = 0; + virtual sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle&) const = 0; + virtual sk_sp onMatchFamilyStyleCharacter(const char familyName[], + const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const = 0; virtual sk_sp onMakeFromData(sk_sp, int ttcIndex) const = 0; virtual sk_sp onMakeFromStreamIndex(std::unique_ptr, @@ -143,18 +143,9 @@ class SK_API SkFontMgr : public SkRefCnt { virtual sk_sp onLegacyMakeTypeface(const char familyName[], SkFontStyle) const = 0; - // this method is never called -- will be removed - virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, - const SkFontStyle&) const { - return nullptr; - } - private: - /** Implemented by porting layer to return the default factory. */ static sk_sp Factory(); - - using INHERITED = SkRefCnt; }; #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h index 04893ef2fdc59..be46b53bb2852 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkFontStyle.h @@ -9,7 +9,9 @@ #define SkFontStyle_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkTPin.h" +#include "include/private/base/SkTPin.h" + +#include class SK_API SkFontStyle { public: @@ -75,6 +77,7 @@ class SK_API SkFontStyle { } private: + friend class SkTypefaceProxyPrototype; // To serialize fValue int32_t fValue; }; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h index c24bb742e71df..6ce9175d1e091 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkGraphics.h @@ -10,9 +10,12 @@ #include "include/core/SkRefCnt.h" +#include + class SkData; class SkImageGenerator; class SkOpenTypeSVGDecoder; +class SkPath; class SkTraceMemoryDump; class SK_API SkGraphics { @@ -115,16 +118,6 @@ class SK_API SkGraphics { */ static void PurgeAllCaches(); - /** - * Applications with command line options may pass optional state, such - * as cache sizes, here, for instance: - * font-cache-limit=12345678 - * - * The flags format is name=value[;name=value...] with no spaces. - * This format is subject to change. - */ - static void SetFlags(const char* flags); - typedef std::unique_ptr (*ImageGeneratorFromEncodedDataFactory)(sk_sp); @@ -151,18 +144,28 @@ class SK_API SkGraphics { static OpenTypeSVGDecoderFactory GetOpenTypeSVGDecoderFactory(); /** - * Temporarily (until variable COLRv1 is released) pass a feature switch function for whether - * variable COLRv1 is enabled. Needed for initializing FreeType with a property setting so that - * variable COLRv1 can be enabled in Chrome Canaries during development. + * Call early in main() to allow Skia to use a JIT to accelerate CPU-bound operations. */ - using VariableColrV1EnabledFunc = bool (*)(); - static VariableColrV1EnabledFunc SetVariableColrV1EnabledFunc(VariableColrV1EnabledFunc); - static bool GetVariableColrV1Enabled(); + static void AllowJIT(); /** - * Call early in main() to allow Skia to use a JIT to accelerate CPU-bound operations. + * To override the default AA algorithm choice in the CPU backend, provide a function that + * returns whether to use analytic (true) or supersampled (false) for a given path. + * + * NOTE: This is a temporary API, intended for migration of all clients to one algorithm, + * and should not be used. */ - static void AllowJIT(); + typedef bool (*PathAnalyticAADeciderProc)(const SkPath&); + static void SetPathAnalyticAADecider(PathAnalyticAADeciderProc); + + /* + * Similar to above, but simply forces the CPU backend to always use analytic AA. + * + * NOTE: This is a temporary API, intended for migration of all clients to one algorithm. + * If the PathAnalyticAADeciderProc is *also* set, this setting has no effect. + * Unlike that API, this function is thread-safe. + */ + static void SetForceAnalyticAA(bool); }; class SkAutoGraphics { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h index cb84c1ffbc76d..c0b458100cf88 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkICC.h @@ -1,19 +1,9 @@ /* - * Copyright 2016 Google Inc. + * Copyright 2023 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#ifndef SkICC_DEFINED -#define SkICC_DEFINED - -#include "include/core/SkData.h" - -struct skcms_Matrix3x3; -struct skcms_TransferFunction; - -SK_API sk_sp SkWriteICCProfile(const skcms_TransferFunction&, - const skcms_Matrix3x3& toXYZD50); - -#endif//SkICC_DEFINED +// TODO(kjlubick) remove this shim after clients have been moved to the new location +#include "include/encode/SkICC.h" // IWYU pragma: export diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h index 4157eafa0b509..8f7d4a46bd9d9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImage.h @@ -8,581 +8,252 @@ #ifndef SkImage_DEFINED #define SkImage_DEFINED +#include "include/core/SkAlphaType.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/core/SkSamplingOptions.h" -#include "include/core/SkScalar.h" -#include "include/core/SkShader.h" -#include "include/core/SkSurfaceProps.h" -#include "include/core/SkTileMode.h" -#if SK_SUPPORT_GPU -#include "include/gpu/GrTypes.h" -#endif -#if defined(SK_GRAPHITE_ENABLED) +#include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" + +#if defined(SK_GRAPHITE) #include "include/gpu/graphite/GraphiteTypes.h" +class SkYUVAPixmaps; #endif -#include // std::function -#include -#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 -#include -#endif +#include +#include +#include +#include -class GrBackendFormat; -class GrBackendTexture; -class GrContextThreadSafeProxy; class GrDirectContext; class GrRecordingContext; -class GrYUVABackendTextureInfo; -class GrYUVABackendTextures; -class SkCanvas; +class SkBitmap; +class SkColorSpace; class SkData; class SkImage; class SkImageFilter; class SkImageGenerator; +class SkMatrix; class SkMipmap; class SkPaint; class SkPicture; class SkPixmap; -class SkPromiseImageTexture; -class SkSurface; -class SkYUVAPixmaps; +class SkShader; +class SkSurfaceProps; +enum SkColorType : int; +enum class SkTextureCompressionType; +enum class SkTileMode; -enum class SkEncodedImageFormat; +struct SkIPoint; +struct SkSamplingOptions; -#if defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GRAPHITE) namespace skgpu::graphite { class BackendTexture; class Recorder; -}; +class TextureInfo; +enum class Volatile : bool; +class YUVABackendTextures; +} #endif -/** \class SkImage - SkImage describes a two dimensional array of pixels to draw. The pixels may be - decoded in a raster bitmap, encoded in a SkPicture or compressed data stream, - or located in GPU memory as a GPU texture. - - SkImage cannot be modified after it is created. SkImage may allocate additional - storage as needed; for instance, an encoded SkImage may decode when drawn. +namespace SkImages { - SkImage width and height are greater than zero. Creating an SkImage with zero width - or height returns SkImage equal to nullptr. - - SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams, - GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported - include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details - vary with platform. +/** Caller data passed to RasterReleaseProc; may be nullptr. */ +using ReleaseContext = void*; +/** Function called when SkImage no longer shares pixels. ReleaseContext is + provided by caller when SkImage is created, and may be nullptr. */ -class SK_API SkImage : public SkRefCnt { -public: - - /** Caller data passed to RasterReleaseProc; may be nullptr. - */ - typedef void* ReleaseContext; - - /** Creates SkImage from SkPixmap and copy of pixels. Since pixels are copied, SkPixmap - pixels may be modified or deleted without affecting SkImage. - - SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param pixmap SkImageInfo, pixel address, and row bytes - @return copy of SkPixmap pixels, or nullptr +using RasterReleaseProc = void(const void* pixels, ReleaseContext); - example: https://fiddle.skia.org/c/@Image_MakeRasterCopy - */ - static sk_sp MakeRasterCopy(const SkPixmap& pixmap); - - /** Creates SkImage from SkImageInfo, sharing pixels. +/** Creates a CPU-backed SkImage from bitmap, sharing or copying bitmap pixels. If the bitmap + is marked immutable, and its pixel memory is shareable, it may be shared + instead of copied. - SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - rowBytes are large enough to hold one row of pixels; - pixels is not nullptr, and contains enough data for SkImage. - - @param info contains width, height, SkAlphaType, SkColorType, SkColorSpace - @param pixels address or pixel storage - @param rowBytes size of pixel row or larger - @return SkImage sharing pixels, or nullptr - */ - static sk_sp MakeRasterData(const SkImageInfo& info, sk_sp pixels, - size_t rowBytes); + SkImage is returned if bitmap is valid. Valid SkBitmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. - /** Function called when SkImage no longer shares pixels. ReleaseContext is - provided by caller when SkImage is created, and may be nullptr. - */ - typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext); - - /** Creates SkImage from pixmap, sharing SkPixmap pixels. Pixels must remain valid and - unchanged until rasterReleaseProc is called. rasterReleaseProc is passed - releaseContext when SkImage is deleted or no longer refers to pixmap pixels. - - Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback - when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc - does not require state. - - SkImage is returned if pixmap is valid. Valid SkPixmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param pixmap SkImageInfo, pixel address, and row bytes - @param rasterReleaseProc function called when pixels can be released; or nullptr - @param releaseContext state passed to rasterReleaseProc; or nullptr - @return SkImage sharing pixmap - */ - static sk_sp MakeFromRaster(const SkPixmap& pixmap, - RasterReleaseProc rasterReleaseProc, - ReleaseContext releaseContext); - - /** Creates SkImage from bitmap, sharing or copying bitmap pixels. If the bitmap - is marked immutable, and its pixel memory is shareable, it may be shared - instead of copied. - - SkImage is returned if bitmap is valid. Valid SkBitmap parameters include: - dimensions are greater than zero; - each dimension fits in 29 bits; - SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; - row bytes are large enough to hold one row of pixels; - pixel address is not nullptr. - - @param bitmap SkImageInfo, row bytes, and pixels - @return created SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_MakeFromBitmap - */ - static sk_sp MakeFromBitmap(const SkBitmap& bitmap); - - /** Creates SkImage from data returned by imageGenerator. Generated data is owned by SkImage and - may not be shared or accessed. - - SkImage is returned if generator data is valid. Valid data parameters vary by type of data - and platform. - - imageGenerator may wrap SkPicture data, codec data, or custom data. - - @param imageGenerator stock or custom routines to retrieve SkImage - @return created SkImage, or nullptr - */ - static sk_sp MakeFromGenerator(std::unique_ptr imageGenerator); - - /** - * Return an image backed by the encoded data, but attempt to defer decoding until the image - * is actually used/drawn. This deferral allows the system to cache the result, either on the - * CPU or on the GPU, depending on where the image is drawn. If memory is low, the cache may - * be purged, causing the next draw of the image to have to re-decode. - * - * If alphaType is nullopt, the image's alpha type will be chosen automatically based on the - * image format. Transparent images will default to kPremul_SkAlphaType. If alphaType contains - * kPremul_SkAlphaType or kUnpremul_SkAlphaType, that alpha type will be used. Forcing opaque - * (passing kOpaque_SkAlphaType) is not allowed, and will return nullptr. - * - * This is similar to DecodeTo[Raster,Texture], but this method will attempt to defer the - * actual decode, while the DecodeTo... method explicitly decode and allocate the backend - * when the call is made. - * - * If the encoded format is not supported, nullptr is returned. - * - * @param encoded the encoded data - * @return created SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_MakeFromEncoded - */ - static sk_sp MakeFromEncoded(sk_sp encoded, - std::optional alphaType = std::nullopt); - - /* - * Experimental: - * Skia | GL_COMPRESSED_* | MTLPixelFormat* | VK_FORMAT_*_BLOCK - * -------------------------------------------------------------------------------------- - * kETC2_RGB8_UNORM | ETC1_RGB8 | ETC2_RGB8 (iOS-only) | ETC2_R8G8B8_UNORM - * | RGB8_ETC2 | | - * -------------------------------------------------------------------------------------- - * kBC1_RGB8_UNORM | RGB_S3TC_DXT1_EXT | N/A | BC1_RGB_UNORM - * -------------------------------------------------------------------------------------- - * kBC1_RGBA8_UNORM | RGBA_S3TC_DXT1_EXT | BC1_RGBA (macOS-only)| BC1_RGBA_UNORM - */ - enum class CompressionType { - kNone, - kETC2_RGB8_UNORM, // the same as ETC1 - - kBC1_RGB8_UNORM, - kBC1_RGBA8_UNORM, - kLast = kBC1_RGBA8_UNORM, - }; + @param bitmap SkImageInfo, row bytes, and pixels + @return created SkImage, or nullptr +*/ +SK_API sk_sp RasterFromBitmap(const SkBitmap& bitmap); - static constexpr int kCompressionTypeCount = static_cast(CompressionType::kLast) + 1; +/** Creates a CPU-backed SkImage from compressed data. - static const CompressionType kETC1_CompressionType = CompressionType::kETC2_RGB8_UNORM; + This method will decompress the compressed data and create an image wrapping + it. Any mipmap levels present in the compressed data are discarded. - /** Creates a CPU-backed SkImage from compressed data. + @param data compressed data to store in SkImage + @param width width of full SkImage + @param height height of full SkImage + @param type type of compression used + @return created SkImage, or nullptr +*/ +SK_API sk_sp RasterFromCompressedTextureData(sk_sp data, + int width, + int height, + SkTextureCompressionType type); + +/** + * Return a SkImage using the encoded data, but attempts to defer decoding until the + * image is actually used/drawn. This deferral allows the system to cache the result, either on the + * CPU or on the GPU, depending on where the image is drawn. If memory is low, the cache may + * be purged, causing the next draw of the image to have to re-decode. + * + * If alphaType is nullopt, the image's alpha type will be chosen automatically based on the + * image format. Transparent images will default to kPremul_SkAlphaType. If alphaType contains + * kPremul_SkAlphaType or kUnpremul_SkAlphaType, that alpha type will be used. Forcing opaque + * (passing kOpaque_SkAlphaType) is not allowed, and will return nullptr. + * + * If the encoded format is not supported, nullptr is returned. + * + * @param encoded the encoded data + * @return created SkImage, or nullptr - This method will decompress the compressed data and create an image wrapping - it. Any mipmap levels present in the compressed data are discarded. + example: https://fiddle.skia.org/c/@Image_DeferredFromEncodedData +*/ +SK_API sk_sp DeferredFromEncodedData(sk_sp encoded, + std::optional alphaType = std::nullopt); - @param data compressed data to store in SkImage - @param width width of full SkImage - @param height height of full SkImage - @param type type of compression used - @return created SkImage, or nullptr - */ - static sk_sp MakeRasterFromCompressed(sk_sp data, - int width, int height, - CompressionType type); +/** Creates SkImage from data returned by imageGenerator. The image data will not be created + (on either the CPU or GPU) until the image is actually drawn. + Generated data is owned by SkImage and may not be shared or accessed. - enum class BitDepth { - kU8, //!< uses 8-bit unsigned int per color component - kF16, //!< uses 16-bit float per color component - }; + SkImage is returned if generator data is valid. Valid data parameters vary by type of data + and platform. - /** Creates SkImage from picture. Returned SkImage width and height are set by dimensions. - SkImage draws picture with matrix and paint, set to bitDepth and colorSpace. + imageGenerator may wrap SkPicture data, codec data, or custom data. - If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws - with default SkPaint. colorSpace may be nullptr. + @param imageGenerator stock or custom routines to retrieve SkImage + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromGenerator(std::unique_ptr imageGenerator); - @param picture stream of drawing commands - @param dimensions width and height - @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr - @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr - @param bitDepth 8-bit integer or 16-bit float: per component - @param colorSpace range of colors; may be nullptr - @param props props to use when rasterizing the picture - @return created SkImage, or nullptr - */ - static sk_sp MakeFromPicture(sk_sp picture, const SkISize& dimensions, - const SkMatrix* matrix, const SkPaint* paint, - BitDepth bitDepth, sk_sp colorSpace, - SkSurfaceProps props = {}); - -#if SK_SUPPORT_GPU - /** Creates a GPU-backed SkImage from compressed data. - - This method will return an SkImage representing the compressed data. - If the GPU doesn't support the specified compression method, the data - will be decompressed and then wrapped in a GPU-backed image. - - Note: one can query the supported compression formats via - GrRecordingContext::compressedBackendFormat. - - @param context GPU context - @param data compressed data to store in SkImage - @param width width of full SkImage - @param height height of full SkImage - @param type type of compression used - @param mipmapped does 'data' contain data for all the mipmap levels? - @param isProtected do the contents of 'data' require DRM protection (on Vulkan)? - @return created SkImage, or nullptr - */ - static sk_sp MakeTextureFromCompressed(GrDirectContext* direct, - sk_sp data, - int width, int height, - CompressionType type, - GrMipmapped mipmapped = GrMipmapped::kNo, - GrProtected isProtected = GrProtected::kNo); - - /** User function called when supplied texture may be deleted. - */ - typedef void (*TextureReleaseProc)(ReleaseContext releaseContext); +enum class BitDepth { + kU8, //!< uses 8-bit unsigned int per color component + kF16, //!< uses 16-bit float per color component +}; - /** Creates SkImage from GPU texture associated with context. GPU texture must stay - valid and unchanged until textureReleaseProc is called. textureReleaseProc is - passed releaseContext when SkImage is deleted or no longer refers to texture. +/** Creates SkImage from picture. Returned SkImage width and height are set by dimensions. + SkImage draws picture with matrix and paint, set to bitDepth and colorSpace. - SkImage is returned if format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. + The Picture data is not turned into an image (CPU or GPU) until it is drawn. - @note When using a DDL recording context, textureReleaseProc will be called on the - GPU thread after the DDL is played back on the direct context. + If matrix is nullptr, draws with identity SkMatrix. If paint is nullptr, draws + with default SkPaint. colorSpace may be nullptr. - @param context GPU context - @param backendTexture texture residing on GPU - @param colorSpace This describes the color space of this image's contents, as - seen after sampling. In general, if the format of the backend - texture is SRGB, some linear colorSpace should be supplied - (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the - backend texture is linear, then the colorSpace should include - a description of the transfer function as - well (e.g., SkColorSpace::MakeSRGB()). - @param textureReleaseProc function called when texture can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin origin, - SkColorType colorType, - SkAlphaType alphaType, + @param picture stream of drawing commands + @param dimensions width and height + @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr + @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr + @param bitDepth 8-bit integer or 16-bit float: per component + @param colorSpace range of colors; may be nullptr + @param props props to use when rasterizing the picture + @return created SkImage, or nullptr +*/ +SK_API sk_sp DeferredFromPicture(sk_sp picture, + const SkISize& dimensions, + const SkMatrix* matrix, + const SkPaint* paint, + BitDepth bitDepth, sk_sp colorSpace, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates an SkImage from a GPU backend texture. The backend texture must stay - valid and unchanged until textureReleaseProc is called. The textureReleaseProc is - called when the SkImage is deleted or no longer refers to the texture and will be - passed the releaseContext. - - An SkImage is returned if the format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. - - @note When using a DDL recording context, textureReleaseProc will be called on the - GPU thread after the DDL is played back on the direct context. - - @param context the GPU context - @param backendTexture a texture already allocated by the GPU - @param alphaType This characterizes the nature of the alpha values in the - backend texture. For opaque compressed formats (e.g., ETC1) - this should usually be set to kOpaque_SkAlphaType. - @param colorSpace This describes the color space of this image's contents, as - seen after sampling. In general, if the format of the backend - texture is SRGB, some linear colorSpace should be supplied - (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the - backend texture is linear, then the colorSpace should include - a description of the transfer function as - well (e.g., SkColorSpace::MakeSRGB()). - @param textureReleaseProc function called when the backend texture can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromCompressedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin origin, - SkAlphaType alphaType, - sk_sp colorSpace, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates SkImage from pixmap. SkImage is uploaded to GPU back-end using context. - - Created SkImage is available to other GPU contexts, and is available across thread - boundaries. All contexts must be in the same GPU share group, or otherwise - share resources. - - When SkImage is no longer referenced, context releases texture memory - asynchronously. - - GrBackendTexture created from pixmap is uploaded to match SkSurface created with - dstColorSpace. SkColorSpace of SkImage is determined by pixmap.colorSpace(). - - SkImage is returned referring to GPU back-end if context is not nullptr, - format of data is recognized and supported, and if context supports moving - resources between contexts. Otherwise, pixmap pixel data is copied and SkImage - as returned in raster format if possible; nullptr may be returned. - Recognized GPU formats vary by platform and GPU back-end. - - @param context GPU context - @param pixmap SkImageInfo, pixel address, and row bytes - @param buildMips create SkImage as mip map if true - @param dstColorSpace range of colors of matching SkSurface on GPU - @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary - @return created SkImage, or nullptr - */ - static sk_sp MakeCrossContextFromPixmap(GrDirectContext* context, - const SkPixmap& pixmap, - bool buildMips, - bool limitToMaxTextureSize = false); - - /** Creates SkImage from backendTexture associated with context. backendTexture and - returned SkImage are managed internally, and are released when no longer needed. - - SkImage is returned if format of backendTexture is recognized and supported. - Recognized formats vary by GPU back-end. - - @param context GPU context - @param backendTexture texture residing on GPU - @param textureOrigin origin of backendTexture - @param colorType color type of the resulting image - @param alphaType alpha type of the resulting image - @param colorSpace range of colors; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType); - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType, - SkAlphaType alphaType); - static sk_sp MakeFromAdoptedTexture(GrRecordingContext* context, - const GrBackendTexture& backendTexture, - GrSurfaceOrigin textureOrigin, - SkColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace); - - /** Creates an SkImage from YUV[A] planar textures. This requires that the textures stay valid - for the lifetime of the image. The ReleaseContext can be used to know when it is safe to - either delete or overwrite the textures. If ReleaseProc is provided it is also called before - return on failure. - - @param context GPU context - @param yuvaTextures A set of textures containing YUVA data and a description of the - data and transformation to RGBA. - @param imageColorSpace range of colors of the resulting image after conversion to RGB; - may be nullptr - @param textureReleaseProc called when the backend textures can be released - @param releaseContext state passed to textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromYUVATextures(GrRecordingContext* context, - const GrYUVABackendTextures& yuvaTextures, - sk_sp imageColorSpace = nullptr, - TextureReleaseProc textureReleaseProc = nullptr, - ReleaseContext releaseContext = nullptr); - - /** Creates SkImage from SkYUVAPixmaps. - - The image will remain planar with each plane converted to a texture using the passed - GrRecordingContext. - - SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. - The SkColorSpace of the resulting RGB values is specified by imageColorSpace. This will - be the SkColorSpace reported by the image and when drawn the RGB values will be converted - from this space into the destination space (if the destination is tagged). - - Currently, this is only supported using the GPU backend and will fail if context is nullptr. + SkSurfaceProps props); +SK_API sk_sp DeferredFromPicture(sk_sp picture, + const SkISize& dimensions, + const SkMatrix* matrix, + const SkPaint* paint, + BitDepth bitDepth, + sk_sp colorSpace); + +/** Creates a CPU-backed SkImage from pixmap, copying the pixel data. + As a result, pixmap pixels may be modified or deleted without affecting SkImage. + + SkImage is returned if SkPixmap is valid. Valid SkPixmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. + + @param pixmap SkImageInfo, pixel address, and row bytes + @return copy of SkPixmap pixels, or nullptr + + example: https://fiddle.skia.org/c/@Image_RasterFromPixmapCopy +*/ +SK_API sk_sp RasterFromPixmapCopy(const SkPixmap& pixmap); + +/** Creates CPU-backed SkImage from pixmap, sharing SkPixmap pixels. Pixels must remain valid and + unchanged until rasterReleaseProc is called. rasterReleaseProc is passed + releaseContext when SkImage is deleted or no longer refers to pixmap pixels. + + Pass nullptr for rasterReleaseProc to share SkPixmap without requiring a callback + when SkImage is released. Pass nullptr for releaseContext if rasterReleaseProc + does not require state. + + SkImage is returned if pixmap is valid. Valid SkPixmap parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + row bytes are large enough to hold one row of pixels; + pixel address is not nullptr. + + @param pixmap SkImageInfo, pixel address, and row bytes + @param rasterReleaseProc function called when pixels can be released; or nullptr + @param releaseContext state passed to rasterReleaseProc; or nullptr + @return SkImage sharing pixmap +*/ +SK_API sk_sp RasterFromPixmap(const SkPixmap& pixmap, + RasterReleaseProc rasterReleaseProc, + ReleaseContext releaseContext); + +/** Creates CPU-backed SkImage from pixel data described by info. + The pixels data will *not* be copied. + + SkImage is returned if SkImageInfo is valid. Valid SkImageInfo parameters include: + dimensions are greater than zero; + each dimension fits in 29 bits; + SkColorType and SkAlphaType are valid, and SkColorType is not kUnknown_SkColorType; + rowBytes are large enough to hold one row of pixels; + pixels is not nullptr, and contains enough data for SkImage. + + @param info contains width, height, SkAlphaType, SkColorType, SkColorSpace + @param pixels address or pixel storage + @param rowBytes size of pixel row or larger + @return SkImage sharing pixels, or nullptr +*/ +SK_API sk_sp RasterFromData(const SkImageInfo& info, + sk_sp pixels, + size_t rowBytes); - SkYUVAPixmaps does not need to remain valid after this returns. +} // namespace SkImages - @param context GPU context - @param pixmaps The planes as pixmaps with supported SkYUVAInfo that - specifies conversion to RGB. - @param buildMips create internal YUVA textures as mip map if kYes. This is - silently ignored if the context does not support mip maps. - @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary - @param imageColorSpace range of colors of the resulting image; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromYUVAPixmaps(GrRecordingContext* context, - const SkYUVAPixmaps& pixmaps, - GrMipmapped buildMips = GrMipmapped::kNo, - bool limitToMaxTextureSize = false, - sk_sp imageColorSpace = nullptr); - - using PromiseImageTextureContext = void*; - using PromiseImageTextureFulfillProc = - sk_sp (*)(PromiseImageTextureContext); - using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); - - /** Create a new SkImage that is very similar to an SkImage created by MakeFromTexture. The - difference is that the caller need not have created the texture nor populated it with the - image pixel data. Moreover, the SkImage may be created on a thread as the creation of the - image does not require access to the backend API or GrDirectContext. Instead of passing a - GrBackendTexture the client supplies a description of the texture consisting of - GrBackendFormat, width, height, and GrMipmapped state. The resulting SkImage can be drawn - to a SkDeferredDisplayListRecorder or directly to a GPU-backed SkSurface. - - When the actual texture is required to perform a backend API draw, textureFulfillProc will - be called to receive a GrBackendTexture. The properties of the GrBackendTexture must match - those set during the SkImage creation, and it must refer to a valid existing texture in the - backend API context/device, and be populated with the image pixel data. The texture cannot - be deleted until textureReleaseProc is called. - - There is at most one call to each of textureFulfillProc and textureReleaseProc. - textureReleaseProc is always called even if image creation fails or if the - image is never fulfilled (e.g. it is never drawn or all draws are clipped out) - - @param gpuContextProxy the thread-safe proxy of the gpu context. required. - @param backendFormat format of promised gpu texture - @param dimensions width & height of promised gpu texture - @param mipmapped mip mapped state of promised gpu texture - @param origin surface origin of promised gpu texture - @param colorType color type of promised gpu texture - @param alphaType alpha type of promised gpu texture - @param colorSpace range of colors; may be nullptr - @param textureFulfillProc function called to get actual gpu texture - @param textureReleaseProc function called when texture can be deleted - @param textureContext state passed to textureFulfillProc and textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakePromiseTexture(sk_sp gpuContextProxy, - const GrBackendFormat& backendFormat, - SkISize dimensions, - GrMipmapped mipmapped, - GrSurfaceOrigin origin, - SkColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace, - PromiseImageTextureFulfillProc textureFulfillProc, - PromiseImageTextureReleaseProc textureReleaseProc, - PromiseImageTextureContext textureContext); - - /** This entry point operates like 'MakePromiseTexture' but it is used to construct a SkImage - from YUV[A] data. The source data may be planar (i.e. spread across multiple textures). In - the extreme Y, U, V, and A are all in different planes and thus the image is specified by - four textures. 'backendTextureInfo' describes the planar arrangement, texture formats, - conversion to RGB, and origin of the textures. Separate 'textureFulfillProc' and - 'textureReleaseProc' calls are made for each texture. Each texture has its own - PromiseImageTextureContext. If 'backendTextureInfo' is not valid then no release proc - calls are made. Otherwise, the calls will be made even on failure. 'textureContexts' has one - entry for each of the up to four textures, as indicated by 'backendTextureInfo'. - - Currently the mip mapped property of 'backendTextureInfo' is ignored. However, in the - near future it will be required that if it is kYes then textureFulfillProc must return - a mip mapped texture for each plane in order to successfully draw the image. - - @param gpuContextProxy the thread-safe proxy of the gpu context. required. - @param backendTextureInfo info about the promised yuva gpu texture - @param imageColorSpace range of colors; may be nullptr - @param textureFulfillProc function called to get actual gpu texture - @param textureReleaseProc function called when texture can be deleted - @param textureContexts state passed to textureFulfillProc and textureReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakePromiseYUVATexture(sk_sp gpuContextProxy, - const GrYUVABackendTextureInfo& backendTextureInfo, - sk_sp imageColorSpace, - PromiseImageTextureFulfillProc textureFulfillProc, - PromiseImageTextureReleaseProc textureReleaseProc, - PromiseImageTextureContext textureContexts[]); +/** \class SkImage + SkImage describes a two dimensional array of pixels to draw. The pixels may be + decoded in a raster bitmap, encoded in a SkPicture or compressed data stream, + or located in GPU memory as a GPU texture. -#endif // SK_SUPPORT_GPU + SkImage cannot be modified after it is created. SkImage may allocate additional + storage as needed; for instance, an encoded SkImage may decode when drawn. -#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 - /** (See Skia bug 7447) - Creates SkImage from Android hardware buffer. - Returned SkImage takes a reference on the buffer. + SkImage width and height are greater than zero. Creating an SkImage with zero width + or height returns SkImage equal to nullptr. - Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. + SkImage may be created from SkBitmap, SkPixmap, SkSurface, SkPicture, encoded streams, + GPU texture, YUV_ColorSpace data, or hardware buffer. Encoded streams supported + include BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP. Supported encoding details + vary with platform. - @param hardwareBuffer AHardwareBuffer Android hardware buffer - @param colorSpace range of colors; may be nullptr - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAHardwareBuffer( - AHardwareBuffer* hardwareBuffer, - SkAlphaType alphaType = kPremul_SkAlphaType, - sk_sp colorSpace = nullptr, - GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); - - /** Creates SkImage from Android hardware buffer and uploads the data from the SkPixmap to it. - Returned SkImage takes a reference on the buffer. - - Only available on Android, when __ANDROID_API__ is defined to be 26 or greater. - - @param context GPU context - @param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer - @param hardwareBuffer AHardwareBuffer Android hardware buffer - @param surfaceOrigin surface origin for resulting image - @return created SkImage, or nullptr - */ - static sk_sp MakeFromAHardwareBufferWithData( - GrDirectContext* context, - const SkPixmap& pixmap, - AHardwareBuffer* hardwareBuffer, - GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); -#endif + See SkImages namespace for the static factory methods to make SkImages. + Clients should *not* subclass SkImage as there is a lot of internal machinery that is + not publicly accessible. +*/ +class SK_API SkImage : public SkRefCnt { +public: /** Returns a SkImageInfo describing the width, height, color type, alpha type, and color space of the SkImage. @@ -691,18 +362,12 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, const SkMatrix* localMatrix = nullptr) const; - sk_sp makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& lm) const { - return this->makeShader(tmx, tmy, sampling, &lm); - } - sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm); - } + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeShader(const SkSamplingOptions& sampling, - const SkMatrix* lm = nullptr) const { - return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm); - } + const SkMatrix* lm = nullptr) const; /** * makeRawShader functions like makeShader, but for images that contain non-color data. @@ -719,20 +384,12 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&, const SkMatrix* localMatrix = nullptr) const; - sk_sp makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling, - const SkMatrix& lm) const { - return this->makeRawShader(tmx, tmy, sampling, &lm); - } - sk_sp makeRawShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const { - return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm); - } + const SkMatrix& lm) const; + /** Defaults to clamp in both X and Y. */ + sk_sp makeRawShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const; sk_sp makeRawShader(const SkSamplingOptions& sampling, - const SkMatrix* lm = nullptr) const { - return this->makeRawShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm); - } - - using CubicResampler = SkCubicResampler; + const SkMatrix* lm = nullptr) const; /** Copies SkImage pixel address, row bytes, and SkImageInfo to pixmap, if address is available, and returns true. If pixel address is not available, return @@ -752,12 +409,12 @@ class SK_API SkImage : public SkRefCnt { example: https://fiddle.skia.org/c/@Image_isTextureBacked */ - bool isTextureBacked() const; + virtual bool isTextureBacked() const = 0; /** Returns an approximation of the amount of texture memory used by the image. Returns zero if the image is not texture backed or if the texture has an external format. */ - size_t textureSize() const; + virtual size_t textureSize() const = 0; /** Returns true if SkImage can be drawn on either raster surface or GPU surface. If context is nullptr, tests if SkImage draws on raster surface; @@ -772,43 +429,7 @@ class SK_API SkImage : public SkRefCnt { example: https://fiddle.skia.org/c/@Image_isValid */ - bool isValid(GrRecordingContext* context) const; - -#if SK_SUPPORT_GPU - /** Flushes any pending uses of texture-backed images in the GPU backend. If the image is not - texture-backed (including promise texture images) or if the GrDirectContext does not - have the same context ID as the context backing the image then this is a no-op. - - If the image was not used in any non-culled draws in the current queue of work for the - passed GrDirectContext then this is a no-op unless the GrFlushInfo contains semaphores or - a finish proc. Those are respected even when the image has not been used. - - @param context the context on which to flush pending usages of the image. - @param info flush options - */ - GrSemaphoresSubmitted flush(GrDirectContext* context, const GrFlushInfo& flushInfo) const; - - void flush(GrDirectContext* context) const { this->flush(context, {}); } - - /** Version of flush() that uses a default GrFlushInfo. Also submits the flushed work to the - GPU. - */ - void flushAndSubmit(GrDirectContext*) const; - - /** Retrieves the back-end texture. If SkImage has no back-end texture, an invalid - object is returned. Call GrBackendTexture::isValid to determine if the result - is valid. - - If flushPendingGrContextIO is true, completes deferred I/O operations. - - If origin in not nullptr, copies location of content drawn into SkImage. - - @param flushPendingGrContextIO flag to flush outstanding requests - @return back-end API texture handle; invalid on failure - */ - GrBackendTexture getBackendTexture(bool flushPendingGrContextIO, - GrSurfaceOrigin* origin = nullptr) const; -#endif // SK_SUPPORT_GPU + virtual bool isValid(GrRecordingContext* context) const = 0; /** \enum SkImage::CachingHint CachingHint selects whether Skia may internally cache SkBitmap generated by @@ -941,40 +562,11 @@ class SK_API SkImage : public SkRefCnt { enum class RescaleMode { kNearest, + kLinear, kRepeatedLinear, kRepeatedCubic, }; - /** Makes image pixel data available to caller, possibly asynchronously. - - Currently asynchronous reads are only supported on the GPU backend and only when the - underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all - other cases this operates synchronously. - - Data is read from the source sub-rectangle, then converted to the color space, color type, - and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the image - causes failure. - - When the pixel data is ready the caller's ReadPixelsCallback is called with a - AsyncReadResult containing pixel data in the requested color type, alpha type, and color - space. The AsyncReadResult will have count() == 1. Upon failure the callback is called with - nullptr for AsyncReadResult. For a GPU image this flushes work but a submit must occur to - guarantee a finite time before the callback is called. - - The data is valid for the lifetime of AsyncReadResult with the exception that if the SkImage - is GPU-backed the data is immediately invalidated if the context is abandoned or - destroyed. - - @param info info of the requested pixels - @param srcRect subrectangle of image to read - @param callback function to call with result of the read - @param context passed to callback - */ - void asyncReadPixels(const SkImageInfo& info, - const SkIRect& srcRect, - ReadPixelsCallback callback, - ReadPixelsContext context) const; - /** Makes image pixel data available to caller, possibly asynchronously. It can also rescale the image pixels. @@ -1071,44 +663,6 @@ class SK_API SkImage : public SkRefCnt { bool scalePixels(const SkPixmap& dst, const SkSamplingOptions&, CachingHint cachingHint = kAllow_CachingHint) const; - /** Encodes SkImage pixels, returning result as SkData. - - Returns nullptr if encoding fails, or if encodedImageFormat is not supported. - - SkImage encoding in a format requires both building with one or more of: - SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP; and platform support - for the encoded format. - - If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encodedImageFormat can - additionally be one of: SkEncodedImageFormat::kICO, SkEncodedImageFormat::kBMP, - SkEncodedImageFormat::kGIF. - - quality is a platform and format specific metric trading off size and encoding - error. When used, quality equaling 100 encodes with the least error. quality may - be ignored by the encoder. - - @param encodedImageFormat one of: SkEncodedImageFormat::kJPEG, SkEncodedImageFormat::kPNG, - SkEncodedImageFormat::kWEBP - @param quality encoder specific metric with 100 equaling best - @return encoded SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_encodeToData - */ - sk_sp encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const; - - /** Encodes SkImage pixels, returning result as SkData. Returns existing encoded data - if present; otherwise, SkImage is encoded with SkEncodedImageFormat::kPNG. Skia - must be built with SK_ENCODE_PNG to encode SkImage. - - Returns nullptr if existing encoded data is missing or invalid, and - encoding fails. - - @return encoded SkImage, or nullptr - - example: https://fiddle.skia.org/c/@Image_encodeToData_2 - */ - sk_sp encodeToData() const; - /** Returns encoded SkImage pixels as SkData, if SkImage was created from supported encoded stream format. Platform support for formats vary and may require building with one or more of: SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP. @@ -1151,33 +705,79 @@ class SK_API SkImage : public SkRefCnt { */ sk_sp withDefaultMipmaps() const; -#if SK_SUPPORT_GPU - /** Returns SkImage backed by GPU texture associated with context. Returned SkImage is - compatible with SkSurface created with dstColorSpace. The returned SkImage respects - mipmapped setting; if mipmapped equals GrMipmapped::kYes, the backing texture - allocates mip map levels. - - The mipmapped parameter is effectively treated as kNo if MIP maps are not supported by the - GPU. - - Returns original SkImage if the image is already texture-backed, the context matches, and - mipmapped is compatible with the backing GPU texture. SkBudgeted is ignored in this case. - - Returns nullptr if context is nullptr, or if SkImage was created with another - GrDirectContext. +#if defined(SK_GANESH) || defined(SK_GRAPHITE) + using ReleaseContext = SkImages::ReleaseContext; + using TextureReleaseProc = void (*)(ReleaseContext); +#endif - @param GrDirectContext the GrDirectContext in play, if it exists - @param GrMipmapped whether created SkImage texture must allocate mip map levels - @param SkBudgeted whether to count a newly created texture for the returned image - counts against the context's budget. - @return created SkImage, or nullptr +#if defined(SK_GRAPHITE) + // Passed to both fulfill and imageRelease + using GraphitePromiseImageContext = void*; + // Returned from fulfill and passed into textureRelease + using GraphitePromiseTextureReleaseContext = void*; + + using GraphitePromiseImageFulfillProc = + std::tuple + (*)(GraphitePromiseImageContext); + using GraphitePromiseImageReleaseProc = void (*)(GraphitePromiseImageContext); + using GraphitePromiseTextureReleaseProc = void (*)(GraphitePromiseTextureReleaseContext); + + /** Create a new SkImage that is very similar to an SkImage created by + MakeGraphiteFromBackendTexture. The difference is that the caller need not have created the + backend texture nor populated it with data when creating the image. Instead of passing a + BackendTexture to the factory the client supplies a description of the texture consisting + of dimensions, TextureInfo, SkColorInfo and Volatility. + + In general, 'fulfill' must return a BackendTexture that matches the properties + provided at SkImage creation time. The BackendTexture must refer to a valid existing + texture in the backend API context/device, and already be populated with data. + The texture cannot be deleted until 'textureRelease' is called. 'textureRelease' will + be called with the textureReleaseContext returned by 'fulfill'. + + Wrt when and how often the fulfill, imageRelease, and textureRelease callbacks will + be called: + + For non-volatile promise images, 'fulfill' will be called at Context::insertRecording + time. Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' will always be + called only once - when Skia will no longer try calling 'fulfill' to get a backend + texture. If 'fulfill' failed (i.e., it didn't return a valid backend texture) then + 'textureRelease' will never be called. If 'fulfill' was successful then + 'textureRelease' will be called only once when the GPU is done with the contents of the + promise image. This will usually occur during a Context::submit call but it could occur + earlier due to error conditions. 'fulfill' can be called multiple times if the promise + image is used in multiple recordings. If 'fulfill' fails, the insertRecording itself will + fail. Subsequent insertRecording calls (with Recordings that use the promise image) will + keep calling 'fulfill' until it succeeds. + + For volatile promise images, 'fulfill' will be called each time the Recording is inserted + into a Context. Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' + will always be called only once just like the non-volatile case. If 'fulfill' fails at + insertRecording-time, 'textureRelease' will never be called. If 'fulfill' was successful + then a 'textureRelease' matching that 'fulfill' will be called when the GPU is done with + the contents of the promise image. This will usually occur during a Context::submit call + but it could occur earlier due to error conditions. + + @param recorder the recorder that will capture the commands creating the image + @param dimensions width & height of promised gpu texture + @param textureInfo structural information for the promised gpu texture + @param colorInfo color type, alpha type and colorSpace information for the image + @param isVolatile volatility of the promise image + @param fulfill function called to get the actual backend texture + @param imageRelease function called when any image-centric data can be deleted + @param textureRelease function called when the backend texture can be deleted + @param imageContext state passed to fulfill and imageRelease + @return created SkImage, or nullptr */ - sk_sp makeTextureImage(GrDirectContext*, - GrMipmapped = GrMipmapped::kNo, - SkBudgeted = SkBudgeted::kYes) const; -#endif + static sk_sp MakeGraphitePromiseTexture(skgpu::graphite::Recorder*, + SkISize dimensions, + const skgpu::graphite::TextureInfo&, + const SkColorInfo&, + skgpu::graphite::Volatile, + GraphitePromiseImageFulfillProc, + GraphitePromiseImageReleaseProc, + GraphitePromiseTextureReleaseProc, + GraphitePromiseImageContext); -#ifdef SK_GRAPHITE_ENABLED /** Creates an SkImage from a GPU texture associated with the recorder. SkImage is returned if the format of backendTexture is recognized and supported. @@ -1198,12 +798,60 @@ class SK_API SkImage : public SkRefCnt { const skgpu::graphite::BackendTexture&, SkColorType colorType, SkAlphaType alphaType, - sk_sp colorSpace); + sk_sp colorSpace, + TextureReleaseProc = nullptr, + ReleaseContext = nullptr); + + /** Creates an SkImage from YUV[A] planar textures associated with the recorder. + @param recorder The recorder. + @param yuvaBackendTextures A set of textures containing YUVA data and a description of the + data and transformation to RGBA. + @param imageColorSpace range of colors of the resulting image after conversion to RGB; + may be nullptr + @param TextureReleaseProc called when the backend textures can be released + @param ReleaseContext state passed to TextureReleaseProc + @return created SkImage, or nullptr + */ + static sk_sp MakeGraphiteFromYUVABackendTextures( + skgpu::graphite::Recorder* recorder, + const skgpu::graphite::YUVABackendTextures& yuvaBackendTextures, + sk_sp imageColorSpace, + TextureReleaseProc = nullptr, + ReleaseContext = nullptr); struct RequiredImageProperties { - skgpu::graphite::Mipmapped fMipmapped; + skgpu::Mipmapped fMipmapped; }; + /** Creates SkImage from SkYUVAPixmaps. + + The image will remain planar with each plane converted to a texture using the passed + Recorder. + + SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. + The SkColorSpace of the resulting RGB values is specified by imgColorSpace. This will + be the SkColorSpace reported by the image and when drawn the RGB values will be converted + from this space into the destination space (if the destination is tagged). + + This is only supported using the GPU backend and will fail if recorder is nullptr. + + SkYUVAPixmaps does not need to remain valid after this returns. + + @param Recorder The Recorder to use for storing commands + @param pixmaps The planes as pixmaps with supported SkYUVAInfo that + specifies conversion to RGB. + @param RequiredImageProperties Properties the returned SkImage must possess (e.g., + mipmaps) + @param limitToMaxTextureSize Downscale image to GPU maximum texture size, if necessary + @param imgColorSpace Range of colors of the resulting image; may be nullptr + @return Created SkImage, or nullptr + */ + static sk_sp MakeGraphiteFromYUVAPixmaps(skgpu::graphite::Recorder*, + const SkYUVAPixmaps& pixmaps, + RequiredImageProperties = {}, + bool limitToMaxTextureSize = false, + sk_sp imgColorSpace = nullptr); + /** Graphite version of makeTextureImage. Returns an SkImage backed by a Graphite texture, using the provided Recorder for creation @@ -1225,9 +873,70 @@ class SK_API SkImage : public SkRefCnt { mipmaps) @return created SkImage, or nullptr */ - sk_sp makeTextureImage(skgpu::graphite::Recorder*, - RequiredImageProperties = {}) const; -#endif + virtual sk_sp makeTextureImage(skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const = 0; + + /** Returns subset of this image. + + Returns nullptr if any of the following are true: + - Subset is empty + - Subset is not contained inside the image's bounds + - Pixels in the image could not be read or copied + + If this image is texture-backed, the recorder parameter is required. + If the recorder parameter is provided, and the image is raster-backed, the subset will + be converted to texture-backed. + + @param subset bounds of returned SkImage + @param recorder the recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return the subsetted image, or nullptr + */ + sk_sp makeSubset(const SkIRect& subset, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + + /** Creates SkImage in target SkColorSpace. + Returns nullptr if SkImage could not be created. + + Returns original SkImage if it is in target SkColorSpace. + Otherwise, converts pixels from SkImage SkColorSpace to target SkColorSpace. + If SkImage colorSpace() returns nullptr, SkImage SkColorSpace is assumed to be sRGB. + + If this image is graphite-backed, the recorder parameter is required. + + @param targetColorSpace SkColorSpace describing color range of returned SkImage + @param recorder The Recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return created SkImage in target SkColorSpace + */ + sk_sp makeColorSpace(sk_sp targetColorSpace, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + + /** Experimental. + Creates SkImage in target SkColorType and SkColorSpace. + Returns nullptr if SkImage could not be created. + + Returns original SkImage if it is in target SkColorType and SkColorSpace. + + If this image is graphite-backed, the recorder parameter is required. + + @param targetColorType SkColorType of returned SkImage + @param targetColorSpace SkColorSpace of returned SkImage + @param recorder The Recorder in which to create the new image + @param RequiredImageProperties properties the returned SkImage must possess (e.g., + mipmaps) + @return created SkImage in target SkColorType and SkColorSpace + */ + sk_sp makeColorTypeAndColorSpace(SkColorType targetColorType, + sk_sp targetColorSpace, + skgpu::graphite::Recorder*, + RequiredImageProperties = {}) const; + +#endif // SK_GRAPHITE /** Returns raster image or lazy image. Copies SkImage backed by GPU texture into CPU memory if needed. Returns original SkImage if decoded in raster bitmap, @@ -1285,38 +994,6 @@ class SK_API SkImage : public SkRefCnt { const SkIRect& clipBounds, SkIRect* outSubset, SkIPoint* offset) const; - /** Defines a callback function, taking one parameter of type GrBackendTexture with - no return value. Function is called when back-end texture is to be released. - */ - typedef std::function BackendTextureReleaseProc; - -#if SK_SUPPORT_GPU - /** Creates a GrBackendTexture from the provided SkImage. Returns true and - stores result in backendTexture and backendTextureReleaseProc if - texture is created; otherwise, returns false and leaves - backendTexture and backendTextureReleaseProc unmodified. - - Call backendTextureReleaseProc after deleting backendTexture. - backendTextureReleaseProc cleans up auxiliary data related to returned - backendTexture. The caller must delete returned backendTexture after use. - - If SkImage is both texture backed and singly referenced, image is returned in - backendTexture without conversion or making a copy. SkImage is singly referenced - if its was transferred solely using std::move(). - - If SkImage is not texture backed, returns texture with SkImage contents. - - @param context GPU context - @param image SkImage used for texture - @param backendTexture storage for back-end texture - @param backendTextureReleaseProc storage for clean up function - @return true if back-end texture was created - */ - static bool MakeBackendTextureFromSkImage(GrDirectContext* context, - sk_sp image, - GrBackendTexture* backendTexture, - BackendTextureReleaseProc* backendTextureReleaseProc); -#endif /** Deprecated. */ enum LegacyBitmapMode { @@ -1393,7 +1070,8 @@ class SK_API SkImage : public SkRefCnt { SkImage(const SkImageInfo& info, uint32_t uniqueID); friend class SkBitmap; - friend class SkImage_Base; + friend class SkImage_Base; // for private ctor + friend class SkImage_Raster; // for withMipmaps friend class SkMipmapBuilder; SkImageInfo fInfo; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h deleted file mode 100644 index be0183c094cba..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageEncoder.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkImageEncoder_DEFINED -#define SkImageEncoder_DEFINED - -#include "include/core/SkEncodedImageFormat.h" -#include "include/core/SkRefCnt.h" -#include "include/core/SkTypes.h" - -class SkBitmap; -class SkData; -class SkPixmap; -class SkWStream; - -/** - * Encode SkPixmap in the given binary image format. - * - * @param dst results are written to this stream. - * @param src source pixels. - * @param format image format, not all formats are supported. - * @param quality range from 0-100, this is supported by jpeg and webp. - * higher values correspond to improved visual quality, but less compression. - * - * @return false iff input is bad or format is unsupported. - * - * Will always return false if Skia is compiled without image - * encoders. - * - * For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise - * it will use lossy. - * - * For examples of encoding an image to a file or to a block of memory, - * see tools/ToolUtils.h. - */ -SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src, - SkEncodedImageFormat format, int quality); - -/** - * The following helper function wraps SkEncodeImage(). - */ -SK_API bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q); - -/** - * Encode SkPixmap in the given binary image format. - * - * @param src source pixels. - * @param format image format, not all formats are supported. - * @param quality range from 0-100, this is supported by jpeg and webp. - * higher values correspond to improved visual quality, but less compression. - * - * @return encoded data or nullptr if input is bad or format is unsupported. - * - * Will always return nullptr if Skia is compiled without image - * encoders. - * - * For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise - * it will use lossy. - */ -SK_API sk_sp SkEncodePixmap(const SkPixmap& src, SkEncodedImageFormat format, int quality); - -/** - * Helper that extracts the pixmap from the bitmap, and then calls SkEncodePixmap() - */ -SK_API sk_sp SkEncodeBitmap(const SkBitmap& src, SkEncodedImageFormat format, int quality); - -#endif // SkImageEncoder_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h index 42125214e7167..ba9ae09833066 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageGenerator.h @@ -8,32 +8,25 @@ #ifndef SkImageGenerator_DEFINED #define SkImageGenerator_DEFINED -#include "include/core/SkBitmap.h" -#include "include/core/SkColor.h" -#include "include/core/SkImage.h" +#include "include/core/SkData.h" #include "include/core/SkImageInfo.h" -#include "include/core/SkSurfaceProps.h" +#include "include/core/SkPixmap.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkYUVAPixmaps.h" +#include "include/private/base/SkAPI.h" +#if defined(SK_GRAPHITE) +#include "include/core/SkImage.h" +#include "include/gpu/graphite/Recorder.h" +#endif + +#include +#include +#include #include class GrRecordingContext; -class GrSurfaceProxyView; -class GrSamplerState; -class SkBitmap; -class SkData; -class SkMatrix; -class SkPaint; -class SkPicture; - -enum class GrImageTexGenPolicy : int; - -#if SK_GRAPHITE_ENABLED -namespace skgpu::graphite { -enum class Mipmapped : bool; -class Recorder; -} -#endif +enum SkAlphaType : int; class SK_API SkImageGenerator { public: @@ -121,36 +114,12 @@ class SK_API SkImageGenerator { */ bool getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps); -#if SK_SUPPORT_GPU - /** - * If the generator can natively/efficiently return its pixels as a GPU image (backed by a - * texture) this will return that image. If not, this will return NULL. - * - * Regarding the GrRecordingContext parameter: - * - * It must be non-NULL. The generator should only succeed if: - * - its internal context is the same - * - it can somehow convert its texture into one that is valid for the provided context. - * - * If the mipmapped parameter is kYes, the generator should try to create a TextureProxy that - * at least has the mip levels allocated and the base layer filled in. If this is not possible, - * the generator is allowed to return a non mipped proxy, but this will have some additional - * overhead in later allocating mips and copying of the base layer. - * - * GrImageTexGenPolicy determines whether or not a new texture must be created (and its budget - * status) or whether this may (but is not required to) return a pre-existing texture that is - * retained by the generator (kDraw). - */ - GrSurfaceProxyView generateTexture(GrRecordingContext*, - const SkImageInfo& info, - GrMipmapped mipmapped, - GrImageTexGenPolicy); -#endif + virtual bool isTextureGenerator() const { return false; } -#if SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) sk_sp makeTextureImage(skgpu::graphite::Recorder*, const SkImageInfo&, - skgpu::graphite::Mipmapped); + skgpu::Mipmapped); #endif /** @@ -164,17 +133,6 @@ class SK_API SkImageGenerator { static std::unique_ptr MakeFromEncoded( sk_sp, std::optional = std::nullopt); - /** Return a new image generator backed by the specified picture. If the size is empty or - * the picture is NULL, this returns NULL. - * The optional matrix and paint arguments are passed to drawPicture() at rasterization - * time. - */ - static std::unique_ptr MakeFromPicture(const SkISize&, sk_sp, - const SkMatrix*, const SkPaint*, - SkImage::BitDepth, - sk_sp, - SkSurfaceProps props = {}); - protected: static constexpr int kNeedNewImageUniqueID = 0; @@ -187,30 +145,17 @@ class SK_API SkImageGenerator { virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes&, SkYUVAPixmapInfo*) const { return false; } virtual bool onGetYUVAPlanes(const SkYUVAPixmaps&) { return false; } -#if SK_SUPPORT_GPU - // returns nullptr - virtual GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&, - GrMipmapped, GrImageTexGenPolicy); - - // Most internal SkImageGenerators produce textures and views that use kTopLeft_GrSurfaceOrigin. - // If the generator may produce textures with different origins (e.g. - // GrAHardwareBufferImageGenerator) it should override this function to return the correct - // origin. - virtual GrSurfaceOrigin origin() const { return kTopLeft_GrSurfaceOrigin; } -#endif -#if SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) virtual sk_sp onMakeTextureImage(skgpu::graphite::Recorder*, const SkImageInfo&, - skgpu::graphite::Mipmapped); + skgpu::Mipmapped); #endif + const SkImageInfo fInfo; private: - const SkImageInfo fInfo; const uint32_t fUniqueID; - friend class SkImage_Lazy; - // This is our default impl, which may be different on different platforms. // It is called from NewFromEncoded() after it has checked for any runtime factory. // The SkData will never be NULL, as that will have been checked by NewFromEncoded. diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h index 9befe3071fb2b..b5661719006ef 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkImageInfo.h @@ -10,16 +10,18 @@ #include "include/core/SkAlphaType.h" #include "include/core/SkColorType.h" -#include "include/core/SkMath.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkTFitsIn.h" -#include "include/private/SkTFitsIn.h" -#include "include/private/SkTo.h" +#include +#include +#include -class SkReadBuffer; -class SkWriteBuffer; class SkColorSpace; /** Returns the number of bytes required to store a pixel, including unused padding. diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h index 7fdbcb8e820d3..11a06a15b1a6d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkM44.h @@ -99,6 +99,11 @@ struct SK_API SkV4 { } bool operator!=(const SkV4& v) const { return !(*this == v); } + static SkScalar Dot(const SkV4& a, const SkV4& b) { + return a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; + } + static SkV4 Normalize(const SkV4& v) { return v * (1.0f / v.length()); } + SkV4 operator-() const { return {-x, -y, -z, -w}; } SkV4 operator+(const SkV4& v) const { return { x + v.x, y + v.y, z + v.z, w + v.w }; } SkV4 operator-(const SkV4& v) const { return { x - v.x, y - v.y, z - v.z, w - v.w }; } @@ -111,6 +116,12 @@ struct SK_API SkV4 { } friend SkV4 operator*(SkScalar s, const SkV4& v) { return v*s; } + SkScalar lengthSquared() const { return Dot(*this, *this); } + SkScalar length() const { return SkScalarSqrt(Dot(*this, *this)); } + + SkScalar dot(const SkV4& v) const { return Dot(*this, v); } + SkV4 normalize() const { return Normalize(*this); } + const float* ptr() const { return &x; } float* ptr() { return &x; } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h index 3fde51b717e53..9d03e98c0c5f8 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMaskFilter.h @@ -8,12 +8,15 @@ #ifndef SkMaskFilter_DEFINED #define SkMaskFilter_DEFINED -#include "include/core/SkBlurTypes.h" -#include "include/core/SkCoverageMode.h" #include "include/core/SkFlattenable.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" -class SkMatrix; +#include + +enum SkBlurStyle : int; +struct SkDeserialProcs; struct SkRect; /** \class SkMaskFilter diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h index 03140760d6f2b..cf84d26228b60 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMatrix.h @@ -8,12 +8,19 @@ #ifndef SkMatrix_DEFINED #define SkMatrix_DEFINED +#include "include/core/SkPoint.h" #include "include/core/SkRect.h" -#include "include/private/SkMacros.h" -#include "include/private/SkTo.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkMacros.h" +#include "include/private/base/SkTo.h" + +#include +#include -struct SkRSXform; struct SkPoint3; +struct SkRSXform; +struct SkSize; // Remove when clients are updated to live without this #define SK_SUPPORT_LEGACY_MATRIX_RECTTORECT @@ -1812,7 +1819,10 @@ class SK_API SkMatrix { if (tx != 0.0f || ty != 0.0f) { mask |= kTranslate_Mask; } - this->setTypeMask(mask | kRectStaysRect_Mask); + if (sx != 0 && sy != 0) { + mask |= kRectStaysRect_Mask; + } + this->setTypeMask(mask); } /** Returns true if all elements of the matrix are finite. Returns false if any diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h index f34672e3ab05e..360a039e7f531 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMesh.h @@ -19,6 +19,7 @@ #include "include/effects/SkRuntimeEffect.h" #include +#include #include class GrDirectContext; @@ -29,22 +30,31 @@ namespace SkSL { struct Program; } /** * A specification for custom meshes. Specifies the vertex buffer attributes and stride, the - * vertex program that produces a user-defined set of varyings, a fragment program that ingests - * the interpolated varyings and produces local coordinates and optionally a color. + * vertex program that produces a user-defined set of varyings, and a fragment program that ingests + * the interpolated varyings and produces local coordinates for shading and optionally a color. + * + * The varyings must include a float2 named "position". If the passed varyings does not + * contain such a varying then one is implicitly added to the final specification and the SkSL + * Varyings struct described below. It is an error to have a varying named "position" that has a + * type other than float2. + * + * The provided attributes and varyings are used to create Attributes and Varyings structs in SkSL + * that are used by the shaders. Each attribute from the Attribute span becomes a member of the + * SkSL Attributes struct and likewise for the varyings. * * The signature of the vertex program must be: - * float2 main(Attributes, out Varyings) - * where the return value is a local position that will be transformed by SkCanvas's matrix. + * Varyings main(const Attributes). * * The signature of the fragment program must be either: - * (float2|void) main(Varyings) + * float2 main(const Varyings) * or - * (float2|void) main(Varyings, out (half4|float4) color) + * float2 main(const Varyings, out (half4|float4) color) * * where the return value is the local coordinates that will be used to access SkShader. If the - * return type is void then the interpolated position from vertex shader return is used as the local - * coordinate. If the color variant is used it will be blended with SkShader (or SkPaint color in - * absence of a shader) using the SkBlender provided to the SkCanvas draw call. + * color variant is used, the returned color will be blended with SkPaint's SkShader (or SkPaint + * color in absence of a SkShader) using the SkBlender passed to SkCanvas drawMesh(). To use + * interpolated local space positions as the shader coordinates, equivalent to how SkPaths are + * shaded, return the position field from the Varying struct as the coordinates. * * The vertex and fragment programs may both contain uniforms. Uniforms with the same name are * assumed to be shared between stages. It is an error to specify uniforms in the vertex and @@ -187,11 +197,12 @@ class SkMeshSpecification : public SkNVRefCnt { SkMeshSpecification(SkSpan, size_t, SkSpan, + int passthroughLocalCoordsVaryingIndex, + uint32_t deadVaryingMask, std::vector uniforms, std::unique_ptr, std::unique_ptr, ColorType, - bool hasLocalCoords, sk_sp, SkAlphaType); @@ -208,8 +219,9 @@ class SkMeshSpecification : public SkNVRefCnt { const std::unique_ptr fFS; const size_t fStride; uint32_t fHash; + const int fPassthroughLocalCoordsVaryingIndex; + const uint32_t fDeadVaryingMask; const ColorType fColorType; - const bool fHasLocalCoords; const sk_sp fColorSpace; const SkAlphaType fAlphaType; }; @@ -295,8 +307,11 @@ class SkMesh { */ static sk_sp MakeIndexBuffer(GrDirectContext*, const void* data, size_t size); - /** Deprecated in favor of const void* and size_t version above. */ - static sk_sp MakeIndexBuffer(GrDirectContext*, sk_sp); + /** + * Makes a copy of an index buffer. The implementation currently only supports a CPU-backed + * source buffer. + */ + static sk_sp CopyIndexBuffer(GrDirectContext*, sk_sp); /** * Makes a vertex buffer to be used with SkMeshes. The buffer may be CPU- or GPU-backed @@ -313,12 +328,23 @@ class SkMesh { */ static sk_sp MakeVertexBuffer(GrDirectContext*, const void*, size_t size); - /** Deprecated in favor of const void* and size_t version above. */ - static sk_sp MakeVertexBuffer(GrDirectContext*, sk_sp); + /** + * Makes a copy of a vertex buffer. The implementation currently only supports a CPU-backed + * source buffer. + */ + static sk_sp CopyVertexBuffer(GrDirectContext*, sk_sp); enum class Mode { kTriangles, kTriangleStrip }; - static SkMesh Make(sk_sp, + struct Result; + + /** + * Creates a non-indexed SkMesh. The returned SkMesh can be tested for validity using + * SkMesh::isValid(). An invalid mesh simply fails to draws if passed to SkCanvas::drawMesh(). + * If the mesh is invalid the returned string give contain the reason for the failure (e.g. the + * vertex buffer was null or uniform data too small). + */ + static Result Make(sk_sp, Mode, sk_sp, size_t vertexCount, @@ -326,7 +352,13 @@ class SkMesh { sk_sp uniforms, const SkRect& bounds); - static SkMesh MakeIndexed(sk_sp, + /** + * Creates an indexed SkMesh. The returned SkMesh can be tested for validity using + * SkMesh::isValid(). A invalid mesh simply fails to draw if passed to SkCanvas::drawMesh(). + * If the mesh is invalid the returned string give contain the reason for the failure (e.g. the + * index buffer was null or uniform data too small). + */ + static Result MakeIndexed(sk_sp, Mode, sk_sp, size_t vertexCount, @@ -364,7 +396,7 @@ class SkMesh { private: friend struct SkMeshPriv; - bool validate() const; + std::tuple validate() const; sk_sp fSpec; @@ -384,6 +416,8 @@ class SkMesh { SkRect fBounds = SkRect::MakeEmpty(); }; +struct SkMesh::Result { SkMesh mesh; SkString error; }; + #endif // SK_ENABLE_SKSL #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h index a6c6bdf195e1f..398de57d0c59f 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkMilestone.h @@ -5,5 +5,5 @@ * found in the LICENSE file. */ #ifndef SK_MILESTONE -#define SK_MILESTONE 108 +#define SK_MILESTONE 114 #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h index d6c1d830c7ed3..157dbb59d8d6c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPaint.h @@ -8,23 +8,28 @@ #ifndef SkPaint_DEFINED #define SkPaint_DEFINED -#include "include/core/SkBlendMode.h" #include "include/core/SkColor.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTo.h" - +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkFloatingPoint.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" + +#include #include +#include class SkBlender; class SkColorFilter; class SkColorSpace; -struct SkRect; class SkImageFilter; class SkMaskFilter; -class SkMatrix; -class SkPath; class SkPathEffect; class SkShader; +enum class SkBlendMode; +struct SkRect; /** \class SkPaint SkPaint controls options applied when drawing. SkPaint collects all @@ -383,34 +388,6 @@ class SK_API SkPaint { */ void setStrokeJoin(Join join); - /** Returns the filled equivalent of the stroked path. - - @param src SkPath read to create a filled version - @param dst resulting SkPath; may be the same as src, but may not be nullptr - @param cullRect optional limit passed to SkPathEffect - @param resScale if > 1, increase precision, else if (0 < resScale < 1) reduce precision - to favor speed and size - @return true if the path represents style fill, or false if it represents hairline - */ - bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect, - SkScalar resScale = 1) const; - - bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect, - const SkMatrix& ctm) const; - - /** Returns the filled equivalent of the stroked path. - - Replaces dst with the src path modified by SkPathEffect and style stroke. - SkPathEffect, if any, is not culled. stroke width is created with default precision. - - @param src SkPath read to create a filled version - @param dst resulting SkPath dst may be the same as src, but may not be nullptr - @return true if the path represents style fill, or false if it represents hairline - */ - bool getFillPath(const SkPath& src, SkPath* dst) const { - return this->getFillPath(src, dst, nullptr, 1); - } - /** Returns optional colors used when filling a path, such as a gradient. Does not alter SkShader SkRefCnt. diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h index fea6932e04035..0b69dd2b6fd95 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPath.h @@ -10,20 +10,29 @@ #include "include/core/SkMatrix.h" #include "include/core/SkPathTypes.h" +#include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTo.h" - +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" + +#include +#include +#include #include #include +#include -class SkAutoPathBoundsUpdate; class SkData; class SkPathRef; class SkRRect; class SkWStream; - enum class SkPathConvexity; enum class SkPathFirstDirection; +struct SkPathVerbAnalysis; // WIP -- define this locally, and fix call-sites to use SkPathBuilder (skbug.com/9000) //#define SK_HIDE_PATH_EDIT_METHODS @@ -1866,6 +1875,16 @@ class SK_API SkPath { */ void shrinkToFit(); + // Creates a new Path after the supplied arguments have been validated by + // sk_path_analyze_verbs(). + static SkPath MakeInternal(const SkPathVerbAnalysis& analsis, + const SkPoint points[], + const uint8_t verbs[], + int verbCount, + const SkScalar conics[], + SkPathFillType fillType, + bool isVolatile); + friend class SkAutoPathBoundsUpdate; friend class SkAutoDisableOvalCheck; friend class SkAutoDisableDirectionCheck; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h index b52eaaaa96b0b..247c08624c554 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathBuilder.h @@ -8,11 +8,19 @@ #ifndef SkPathBuilder_DEFINED #define SkPathBuilder_DEFINED -#include "include/core/SkMatrix.h" #include "include/core/SkPath.h" #include "include/core/SkPathTypes.h" +#include "include/core/SkPoint.h" +#include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTDArray.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" +#include "include/private/SkPathRef.h" +#include "include/private/base/SkTo.h" + +#include + +class SkRRect; class SK_API SkPathBuilder { public: @@ -220,9 +228,9 @@ class SK_API SkPathBuilder { } private: - SkTDArray fPts; - SkTDArray fVerbs; - SkTDArray fConicWeights; + SkPathRef::PointsArray fPts; + SkPathRef::VerbsArray fVerbs; + SkPathRef::ConicWeightsArray fConicWeights; SkPathFillType fFillType; bool fIsVolatile; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h index 2335c7c23ce13..167b18278d923 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathMeasure.h @@ -10,7 +10,7 @@ #include "include/core/SkContourMeasure.h" #include "include/core/SkPath.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" class SK_API SkPathMeasure { public: diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h index f589ea46ce2e3..963a6bda00b00 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathTypes.h @@ -8,8 +8,6 @@ #ifndef SkPathTypes_DEFINED #define SkPathTypes_DEFINED -#include "include/core/SkTypes.h" - enum class SkPathFillType { /** Specifies that "inside" is computed by a non-zero sum of signed edge crossings */ kWinding, diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h new file mode 100644 index 0000000000000..6285da7996033 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPathUtils.h @@ -0,0 +1,42 @@ +/* + * 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 SkPathUtils_DEFINED +#define SkPathUtils_DEFINED + +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" + +class SkMatrix; +class SkPaint; +class SkPath; +struct SkRect; + +namespace skpathutils { + +/** Returns the filled equivalent of the stroked path. + + @param src SkPath read to create a filled version + @param paint SkPaint, from which attributes such as stroke cap, width, miter, and join, + as well as pathEffect will be used. + @param dst resulting SkPath; may be the same as src, but may not be nullptr + @param cullRect optional limit passed to SkPathEffect + @param resScale if > 1, increase precision, else if (0 < resScale < 1) reduce precision + to favor speed and size + @return true if the dst path was updated, false if it was not (e.g. if the path + represents hairline and cannot be filled). +*/ +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, + const SkRect *cullRect, SkScalar resScale = 1); + +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, + const SkRect *cullRect, const SkMatrix &ctm); + +SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst); + +} + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h index b6422dd56e3ee..bb384dfab1b8c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPicture.h @@ -243,8 +243,9 @@ class SK_API SkPicture : public SkRefCnt { void serialize(SkWStream*, const SkSerialProcs*, class SkRefCntSet* typefaces, bool textBlobsOnly=false) const; - static sk_sp MakeFromStream(SkStream*, const SkDeserialProcs*, - class SkTypefacePlayback*); + static sk_sp MakeFromStreamPriv(SkStream*, const SkDeserialProcs*, + class SkTypefacePlayback*, + int recursionLimit); friend class SkPictureData; /** Return true if the SkStream/Buffer represents a serialized picture, and diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h index af3926dd25f0f..d91d105000ef0 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPictureRecorder.h @@ -12,6 +12,8 @@ #include "include/core/SkPicture.h" #include "include/core/SkRefCnt.h" +#include + #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK namespace android { class Picture; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h index ce25665b01a6a..12779890f8859 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixelRef.h @@ -8,20 +8,16 @@ #ifndef SkPixelRef_DEFINED #define SkPixelRef_DEFINED -#include "include/core/SkBitmap.h" -#include "include/core/SkImageInfo.h" -#include "include/core/SkPixmap.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/private/SkIDChangeListener.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkTo.h" #include +#include +#include -struct SkIRect; - -class GrTexture; class SkDiscardableMemory; /** \class SkPixelRef diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h index 7bc2aa05ac73e..ad4c7dd6d8464 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPixmap.h @@ -9,11 +9,21 @@ #define SkPixmap_DEFINED #include "include/core/SkColor.h" +#include "include/core/SkColorType.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkRect.h" +#include "include/core/SkRefCnt.h" #include "include/core/SkSamplingOptions.h" +#include "include/core/SkSize.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" + +#include +#include class SkColorSpace; -class SkData; +enum SkAlphaType : int; struct SkMask; /** \class SkPixmap @@ -702,39 +712,21 @@ class SK_API SkPixmap { */ bool erase(SkColor color) const { return this->erase(color, this->bounds()); } - /** Writes color to pixels bounded by subset; returns true on success. - if subset is nullptr, writes colors pixels inside bounds(). Returns false if - colorType() is kUnknown_SkColorType, if subset is not nullptr and does - not intersect bounds(), or if subset is nullptr and bounds() is empty. - - @param color sRGB unpremultiplied color to write - @param subset bounding integer SkRect of pixels to write; may be nullptr - @return true if pixels are changed - - example: https://fiddle.skia.org/c/@Pixmap_erase_3 - */ - bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const { - return this->erase(color, nullptr, subset); - } - /** Writes color to pixels bounded by subset; returns true on success. if subset is nullptr, writes colors pixels inside bounds(). Returns false if colorType() is kUnknown_SkColorType, if subset is not nullptr and does not intersect bounds(), or if subset is nullptr and bounds() is empty. @param color unpremultiplied color to write - @param cs SkColorSpace of color @param subset bounding integer SkRect of pixels to write; may be nullptr @return true if pixels are changed */ - bool erase(const SkColor4f& color, SkColorSpace* cs, const SkIRect* subset = nullptr) const; + bool erase(const SkColor4f& color, const SkIRect* subset = nullptr) const; private: const void* fPixels; size_t fRowBytes; SkImageInfo fInfo; - - friend class SkPixmapPriv; }; #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h index 92cb0b7f09994..a5e7fa09fbab5 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPoint.h @@ -8,9 +8,11 @@ #ifndef SkPoint_DEFINED #define SkPoint_DEFINED -#include "include/core/SkMath.h" #include "include/core/SkScalar.h" -#include "include/private/SkSafe32.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkSafe32.h" + +#include struct SkIPoint; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h index 05434c0942517..0bd4034fdcda6 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkPromiseImageTexture.h @@ -10,7 +10,7 @@ #include "include/core/SkTypes.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/core/SkRefCnt.h" #include "include/gpu/GrBackendSurface.h" /** @@ -41,6 +41,6 @@ class SK_API SkPromiseImageTexture : public SkNVRefCnt { GrBackendTexture fBackendTexture; }; -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) #endif // SkPromiseImageTexture_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h index 099385168ff73..73bc4a95b99ec 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRRect.h @@ -10,8 +10,12 @@ #include "include/core/SkPoint.h" #include "include/core/SkRect.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" + +#include +#include -class SkPath; class SkMatrix; class SkString; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h index 9467a331c3e19..1ed7823c23773 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRect.h @@ -9,12 +9,15 @@ #define SkRect_DEFINED #include "include/core/SkPoint.h" +#include "include/core/SkScalar.h" #include "include/core/SkSize.h" -#include "include/private/SkSafe32.h" -#include "include/private/SkTFitsIn.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkSafe32.h" +#include "include/private/base/SkTFitsIn.h" +#include #include -#include +#include struct SkRect; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h index fc687b3840171..668de14e1d1af 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRefCnt.h @@ -9,14 +9,14 @@ #define SkRefCnt_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkDebug.h" -#include // std::atomic, std::memory_order_* -#include // std::nullptr_t -#include // std::basic_ostream -#include // TODO: unused -#include // std::enable_if, std::is_convertible -#include // std::forward, std::swap +#include +#include +#include +#include +#include +#include /** \class SkRefCntBase @@ -174,7 +174,7 @@ class SkNVRefCnt { bool unique() const { return 1 == fRefCnt.load(std::memory_order_acquire); } void ref() const { (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed); } - void unref() const { + void unref() const { if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) { // restore the 1 for our destructor's assert SkDEBUGCODE(fRefCnt.store(1, std::memory_order_relaxed)); @@ -217,12 +217,7 @@ class SkNVRefCnt { * may be considered as trivially relocatable by the compiler so that destroying-move operations * i.e. move constructor followed by destructor can be optimized to memcpy. */ -#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::trivial_abi) -#define SK_SP_TRIVIAL_ABI [[clang::trivial_abi]] -#else -#define SK_SP_TRIVIAL_ABI -#endif -template class SK_SP_TRIVIAL_ABI sk_sp { +template class SK_TRIVIAL_ABI sk_sp { public: using element_type = T; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h index 463a39ff36d54..6f8aa25d54282 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkRegion.h @@ -9,7 +9,7 @@ #define SkRegion_DEFINED #include "include/core/SkRect.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTypeTraits.h" class SkPath; class SkRgnBuilder; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h index 2a6bb3ec361ef..f3e11b34c2504 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkScalar.h @@ -8,10 +8,8 @@ #ifndef SkScalar_DEFINED #define SkScalar_DEFINED -#include "include/private/SkFloatingPoint.h" - -#undef SK_SCALAR_IS_FLOAT -#define SK_SCALAR_IS_FLOAT 1 +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkFloatingPoint.h" typedef float SkScalar; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h index 87e10d847ce6c..a9a0386370cd9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSerialProcs.h @@ -8,9 +8,15 @@ #ifndef SkSerialProcs_DEFINED #define SkSerialProcs_DEFINED -#include "include/core/SkImage.h" -#include "include/core/SkPicture.h" -#include "include/core/SkTypeface.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" + +#include + +class SkData; +class SkImage; +class SkPicture; +class SkTypeface; /** * A serial-proc is asked to serialize the specified object (e.g. picture or image). @@ -22,30 +28,32 @@ * The default action for typefaces is to use Skia's internal format. */ -typedef sk_sp (*SkSerialPictureProc)(SkPicture*, void* ctx); -typedef sk_sp (*SkSerialImageProc)(SkImage*, void* ctx); -typedef sk_sp (*SkSerialTypefaceProc)(SkTypeface*, void* ctx); +using SkSerialPictureProc = sk_sp (*)(SkPicture*, void* ctx); +using SkSerialImageProc = sk_sp (*)(SkImage*, void* ctx); +using SkSerialTypefaceProc = sk_sp (*)(SkTypeface*, void* ctx); /** * Called with the encoded form of a picture (previously written with a custom * SkSerialPictureProc proc). Return a picture object, or nullptr indicating failure. */ -typedef sk_sp (*SkDeserialPictureProc)(const void* data, size_t length, void* ctx); +using SkDeserialPictureProc = sk_sp (*)(const void* data, size_t length, void* ctx); /** - * Called with the encoded from of an image. The proc can return an image object, or if it + * Called with the encoded form of an image. The proc can return an image object, or if it * returns nullptr, then Skia will take its default action to try to create an image from the data. * + * This will also be used to decode the internal mipmap layers that are saved on some images. + * * Note that unlike SkDeserialPictureProc and SkDeserialTypefaceProc, return nullptr from this * does not indicate failure, but is a signal for Skia to take its default action. */ -typedef sk_sp (*SkDeserialImageProc)(const void* data, size_t length, void* ctx); +using SkDeserialImageProc = sk_sp (*)(const void* data, size_t length, void* ctx); /** * Called with the encoded form of a typeface (previously written with a custom * SkSerialTypefaceProc proc). Return a typeface object, or nullptr indicating failure. */ -typedef sk_sp (*SkDeserialTypefaceProc)(const void* data, size_t length, void* ctx); +using SkDeserialTypefaceProc = sk_sp (*)(const void* data, size_t length, void* ctx); struct SK_API SkSerialProcs { SkSerialPictureProc fPictureProc = nullptr; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h index 1c05c6238cb59..be42a87b9a9c6 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkShader.h @@ -56,69 +56,6 @@ class SK_API SkShader : public SkFlattenable { return this->isAImage(nullptr, (SkTileMode*)nullptr) != nullptr; } - // TODO(skbug.com/8941): Have Android use SkAndroidFrameworkUtils, move types to SkShaderBase, - // and delete asAGradient(). -#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK -private: -#endif - - /** - * If the shader subclass can be represented as a gradient, asAGradient - * returns the matching GradientType enum (or kNone_GradientType if it - * cannot). Also, if info is not null, asAGradient populates info with - * the relevant (see below) parameters for the gradient. fColorCount - * is both an input and output parameter. On input, it indicates how - * many entries in fColors and fColorOffsets can be used, if they are - * non-NULL. After asAGradient has run, fColorCount indicates how - * many color-offset pairs there are in the gradient. If there is - * insufficient space to store all of the color-offset pairs, fColors - * and fColorOffsets will not be altered. fColorOffsets specifies - * where on the range of 0 to 1 to transition to the given color. - * The meaning of fPoint and fRadius is dependant on the type of gradient. - * - * None: - * info is ignored. - * Color: - * fColorOffsets[0] is meaningless. - * Linear: - * fPoint[0] and fPoint[1] are the end-points of the gradient - * Radial: - * fPoint[0] and fRadius[0] are the center and radius - * Conical: - * fPoint[0] and fRadius[0] are the center and radius of the 1st circle - * fPoint[1] and fRadius[1] are the center and radius of the 2nd circle - * Sweep: - * fPoint[0] is the center of the sweep. - */ - - enum GradientType { - kNone_GradientType, - kColor_GradientType, - kLinear_GradientType, - kRadial_GradientType, - kSweep_GradientType, - kConical_GradientType, - }; - - struct GradientInfo { - int fColorCount = 0; //!< In-out parameter, specifies passed size - // of fColors/fColorOffsets on input, and - // actual number of colors/offsets on - // output. - SkColor* fColors = nullptr; //!< The colors in the gradient. - SkScalar* fColorOffsets = nullptr; //!< The unit offset for color transitions. - SkPoint fPoint[2]; //!< Type specific, see above. - SkScalar fRadius[2]; //!< Type specific, see above. - SkTileMode fTileMode; - uint32_t fGradientFlags = 0; //!< see SkGradientShader::Flags - }; - - GradientType asAGradient(GradientInfo* info) const; - -#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK -public: -#endif - ////////////////////////////////////////////////////////////////////////// // Methods to create combinations or variants of shaders @@ -148,7 +85,7 @@ class SK_API SkShaders { static sk_sp Color(const SkColor4f&, sk_sp); static sk_sp Blend(SkBlendMode mode, sk_sp dst, sk_sp src); static sk_sp Blend(sk_sp, sk_sp dst, sk_sp src); - + static sk_sp CoordClamp(sk_sp, const SkRect& subset); private: SkShaders() = delete; }; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h index 79d673775e8d1..867f4eeb97b90 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSize.h @@ -10,6 +10,8 @@ #include "include/core/SkScalar.h" +#include + struct SkISize { int32_t fWidth; int32_t fHeight; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h index 03eb3b5b0fb66..37cac632b1e8d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSpan.h @@ -5,117 +5,9 @@ * found in the LICENSE file. */ -#ifndef SkSpan_DEFINED -#define SkSpan_DEFINED +// We want SkSpan to be a public API, but it is also fundamental to many of our internal types. +// Thus, we have a public file that clients can include. This file defers to the private copy +// so we do not have a dependency cycle from our "base" files to our "core" files. -#include -#include -#include -#include -#include -#include "include/private/SkTLogic.h" +#include "include/private/base/SkSpan_impl.h" // IWYU pragma: export -// Add macro to check the lifetime of initializer_list arguments. initializer_list has a very -// short life span, and can only be used as a parameter, and not as a variable. -#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::lifetimebound) -#define SK_CHECK_IL_LIFETIME [[clang::lifetimebound]] -#else -#define SK_CHECK_IL_LIFETIME -#endif - -/** - * SkSpan holds a reference to contiguous data of type T along with a count. SkSpan does not own - * the data itself but is merely a reference, therefore you must take care with the lifetime of - * the underlying data. - * - * SkSpan is a count and a pointer into existing array or data type that stores its data in - * contiguous memory like std::vector. Any container that works with std::size() and std::data() - * can be used. - * - * SkSpan makes a convenient parameter for a routine to accept array like things. This allows you to - * write the routine without overloads for all different container types. - * - * Example: - * void routine(SkSpan a) { ... } - * - * std::vector v = {1, 2, 3, 4, 5}; - * - * routine(a); - * - * A word of caution when working with initializer_list, initializer_lists have a lifetime that is - * limited to the current statement. The following is correct and safe: - * - * Example: - * routine({1,2,3,4,5}); - * - * The following is undefined, and will result in erratic execution: - * - * Bad Example: - * initializer_list l = {1, 2, 3, 4, 5}; // The data behind l dies at the ;. - * routine(l); - */ -template -class SkSpan { -public: - constexpr SkSpan() : fPtr{nullptr}, fSize{0} {} - constexpr SkSpan(T* ptr, size_t size) : fPtr{ptr}, fSize{size} { - SkASSERT(ptr || size == 0); // disallow nullptr + a nonzero size - SkASSERT(size < kMaxSize); - } - template ::value>::type> - constexpr SkSpan(const SkSpan& that) : fPtr(std::data(that)), fSize{std::size(that)} {} - constexpr SkSpan(const SkSpan& o) = default; - template constexpr SkSpan(T(&a)[N]) : SkSpan(a, N) { } - template - constexpr SkSpan(Container& c) : SkSpan{std::data(c), std::size(c)} { } - SkSpan(std::initializer_list il SK_CHECK_IL_LIFETIME) - : SkSpan(std::data(il), std::size(il)) {} - - constexpr SkSpan& operator=(const SkSpan& that) = default; - - constexpr T& operator [] (size_t i) const { - SkASSERT(i < this->size()); - return fPtr[i]; - } - constexpr T& front() const { return fPtr[0]; } - constexpr T& back() const { return fPtr[fSize - 1]; } - constexpr T* begin() const { return fPtr; } - constexpr T* end() const { return fPtr + fSize; } - constexpr auto rbegin() const { return std::make_reverse_iterator(this->end()); } - constexpr auto rend() const { return std::make_reverse_iterator(this->begin()); } - constexpr T* data() const { return this->begin(); } - constexpr size_t size() const { return fSize; } - constexpr bool empty() const { return fSize == 0; } - constexpr size_t size_bytes() const { return fSize * sizeof(T); } - constexpr SkSpan first(size_t prefixLen) const { - SkASSERT(prefixLen <= this->size()); - return SkSpan{fPtr, prefixLen}; - } - constexpr SkSpan last(size_t postfixLen) const { - SkASSERT(postfixLen <= this->size()); - return SkSpan{fPtr + (this->size() - postfixLen), postfixLen}; - } - constexpr SkSpan subspan(size_t offset) const { - return this->subspan(offset, this->size() - offset); - } - constexpr SkSpan subspan(size_t offset, size_t count) const { - SkASSERT(offset <= this->size()); - SkASSERT(count <= this->size() - offset); - return SkSpan{fPtr + offset, count}; - } - -private: - static const constexpr size_t kMaxSize = std::numeric_limits::max() / sizeof(T); - T* fPtr; - size_t fSize; -}; - -template -SkSpan(Container&) -> - SkSpan()))>>; - -template -SkSpan(std::initializer_list) -> - SkSpan>()))>>; - -#endif // SkSpan_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h index 768de9b5a33d0..c582c80a0528c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h @@ -11,15 +11,16 @@ #include "include/core/SkData.h" #include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" -#include "include/private/SkTo.h" - -#include - -class SkStream; -class SkStreamRewindable; -class SkStreamSeekable; +#include "include/core/SkTypes.h" +#include "include/private/base/SkCPUTypes.h" +#include "include/private/base/SkTo.h" + +#include +#include +#include +#include +#include class SkStreamAsset; -class SkStreamMemory; /** * SkStream -- abstraction for a source of bytes. Subclasses can be backed by @@ -255,10 +256,10 @@ class SK_API SkWStream { bool writeText(const char text[]) { SkASSERT(text); - return this->write(text, strlen(text)); + return this->write(text, std::strlen(text)); } - bool newline() { return this->write("\n", strlen("\n")); } + bool newline() { return this->write("\n", std::strlen("\n")); } bool writeDecAsText(int32_t); bool writeBigDecAsText(int64_t, int minDigits = 0); @@ -296,8 +297,6 @@ class SK_API SkNullWStream : public SkWStream { //////////////////////////////////////////////////////////////////////////////////////// -#include - /** A stream that wraps a C FILE* file stream. */ class SK_API SkFILEStream : public SkStreamAsset { public: diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkString.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkString.h index e659910c6f00e..1b27fbf44b07c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkString.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkString.h @@ -11,15 +11,16 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" -#include -#include #include +#include +#include +#include #include #include +#include /* Some helper functions for C strings */ static inline bool SkStrStartsWith(const char string[], const char prefixStr[]) { @@ -128,6 +129,7 @@ class SK_API SkString { bool isEmpty() const { return 0 == fRec->fLength; } size_t size() const { return (size_t) fRec->fLength; } + const char* data() const { return fRec->data(); } const char* c_str() const { return fRec->data(); } char operator[](size_t n) const { return this->c_str()[n]; } @@ -173,8 +175,8 @@ class SK_API SkString { SkString& operator=(SkString&&); SkString& operator=(const char text[]); - char* writable_str(); - char& operator[](size_t n) { return this->writable_str()[n]; } + char* data(); + char& operator[](size_t n) { return this->data()[n]; } void reset(); /** String contents are preserved on resize. (For destructive resize, `set(nullptr, length)`.) @@ -286,22 +288,4 @@ static inline void swap(SkString& a, SkString& b) { a.swap(b); } -enum SkStrSplitMode { - // Strictly return all results. If the input is ",," and the separator is ',' this will return - // an array of three empty strings. - kStrict_SkStrSplitMode, - - // Only nonempty results will be added to the results. Multiple separators will be - // coalesced. Separators at the beginning and end of the input will be ignored. If the input is - // ",," and the separator is ',', this will return an empty vector. - kCoalesce_SkStrSplitMode -}; - -// Split str on any characters in delimiters into out. (Think, strtok with a sane API.) -void SkStrSplit(const char* str, const char* delimiters, SkStrSplitMode splitMode, - SkTArray* out); -inline void SkStrSplit(const char* str, const char* delimiters, SkTArray* out) { - SkStrSplit(str, delimiters, kCoalesce_SkStrSplitMode, out); -} - #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h index b4796fcbfa6ca..1257d04a844b7 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkStrokeRec.h @@ -9,7 +9,7 @@ #define SkStrokeRec_DEFINED #include "include/core/SkPaint.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" class SkPath; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h index 98dcfdefcb3db..3673d172b6d02 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurface.h @@ -9,41 +9,61 @@ #define SkSurface_DEFINED #include "include/core/SkImage.h" +#include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkSamplingOptions.h" +#include "include/core/SkScalar.h" #include "include/core/SkSurfaceProps.h" +#include "include/core/SkTypes.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrTypes.h" +#else +enum GrSurfaceOrigin: int; +#endif + +#if defined(SK_GRAPHITE) +#include "include/gpu/GpuTypes.h" +namespace skgpu::graphite { +class BackendTexture; +} #endif #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 #include +class GrDirectContext; #endif -#if SK_SUPPORT_GPU && defined(SK_METAL) +#if defined(SK_GANESH) && defined(SK_METAL) #include "include/gpu/mtl/GrMtlTypes.h" #endif +#include +#include +#include + +class GrBackendRenderTarget; +class GrBackendSemaphore; +class GrBackendTexture; +class GrRecordingContext; +class SkBitmap; class SkCanvas; class SkCapabilities; +class SkColorSpace; class SkDeferredDisplayList; class SkPaint; class SkSurfaceCharacterization; -class GrBackendRenderTarget; -class GrBackendSemaphore; -class GrBackendTexture; -class GrDirectContext; -class GrRecordingContext; -class GrRenderTarget; -enum GrSurfaceOrigin: int; +enum SkColorType : int; +struct SkIRect; +struct SkISize; namespace skgpu { class MutableTextureState; +enum class Budgeted : bool; } namespace skgpu::graphite { -class BackendTexture; class Recorder; } @@ -206,7 +226,7 @@ class SK_API SkSurface : public SkRefCnt { backend API (accounting only for use of the texture by this surface). If SkSurface creation fails textureReleaseProc is called before this function returns. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param backendTexture texture residing on GPU @@ -241,7 +261,7 @@ class SK_API SkSurface : public SkRefCnt { backend API (accounting only for use of the render target by this surface). If SkSurface creation fails releaseProc is called before this function returns. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param backendRenderTarget GPU intermediate memory buffer @@ -276,7 +296,7 @@ class SK_API SkSurface : public SkRefCnt { shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map. - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. + If defined(SK_GANESH) is defined as zero, has no effect and returns nullptr. @param context GPU context @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace; @@ -287,9 +307,11 @@ class SK_API SkSurface : public SkRefCnt { @param shouldCreateWithMips hint that SkSurface will host mip map images @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, const SkImageInfo& imageInfo, - int sampleCount, GrSurfaceOrigin surfaceOrigin, + int sampleCount, + GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps* surfaceProps, bool shouldCreateWithMips = false); @@ -314,10 +336,12 @@ class SK_API SkSurface : public SkRefCnt { fonts; may be nullptr @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, - const SkImageInfo& imageInfo, int sampleCount, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, + const SkImageInfo& imageInfo, + int sampleCount, const SkSurfaceProps* surfaceProps) { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) return MakeRenderTarget(context, budgeted, imageInfo, sampleCount, kBottomLeft_GrSurfaceOrigin, surfaceProps); #else @@ -339,9 +363,10 @@ class SK_API SkSurface : public SkRefCnt { of raster surface; width, or height, or both, may be zero @return SkSurface if all parameters are valid; otherwise, nullptr */ - static sk_sp MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted, + static sk_sp MakeRenderTarget(GrRecordingContext* context, + skgpu::Budgeted budgeted, const SkImageInfo& imageInfo) { -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) if (!imageInfo.width() || !imageInfo.height()) { return nullptr; } @@ -362,8 +387,7 @@ class SK_API SkSurface : public SkRefCnt { */ static sk_sp MakeRenderTarget(GrRecordingContext* context, const SkSurfaceCharacterization& characterization, - SkBudgeted budgeted); - + skgpu::Budgeted budgeted); #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 /** Private. @@ -398,7 +422,7 @@ class SK_API SkSurface : public SkRefCnt { ); #endif -#ifdef SK_GRAPHITE_ENABLED +#if defined(SK_GRAPHITE) /** * In Graphite, while clients hold a ref on an SkSurface, the backing gpu object does _not_ * count against the budget. Once an SkSurface is freed, the backing gpu object may or may @@ -408,7 +432,7 @@ class SK_API SkSurface : public SkRefCnt { static sk_sp MakeGraphite( skgpu::graphite::Recorder*, const SkImageInfo& imageInfo, - skgpu::graphite::Mipmapped = skgpu::graphite::Mipmapped::kNo, + skgpu::Mipmapped = skgpu::Mipmapped::kNo, const SkSurfaceProps* surfaceProps = nullptr); /** @@ -430,9 +454,9 @@ class SK_API SkSurface : public SkRefCnt { sk_sp colorSpace, const SkSurfaceProps* props); -#endif // SK_GRAPHITE_ENABLED +#endif // SK_GRAPHITE -#if SK_SUPPORT_GPU && defined(SK_METAL) +#if defined(SK_GANESH) && defined(SK_METAL) /** Creates SkSurface from CAMetalLayer. Returned SkSurface takes a reference on the CAMetalLayer. The ref on the layer will be released when the SkSurface is destroyed. @@ -525,7 +549,7 @@ class SK_API SkSurface : public SkRefCnt { /** Returns an ImageInfo describing the surface. */ - SkImageInfo imageInfo(); + virtual SkImageInfo imageInfo() const { return SkImageInfo::MakeUnknown(fWidth, fHeight); } /** Returns unique value identifying the content of SkSurface. Returned value changes each time the content changes. Content is changed by drawing, or by calling @@ -566,7 +590,7 @@ class SK_API SkSurface : public SkRefCnt { */ skgpu::graphite::Recorder* recorder(); -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) enum BackendHandleAccess { kFlushRead_BackendHandleAccess, //!< back-end object is readable kFlushWrite_BackendHandleAccess, //!< back-end object is writable @@ -669,7 +693,7 @@ class SK_API SkSurface : public SkRefCnt { /** Returns SkImage capturing SkSurface contents. Subsequent drawing to SkSurface contents are not captured. SkImage allocation is accounted for if SkSurface was created with - SkBudgeted::kYes. + skgpu::Budgeted::kYes. @return SkImage initialized with SkSurface contents @@ -690,6 +714,34 @@ class SK_API SkSurface : public SkRefCnt { */ sk_sp makeImageSnapshot(const SkIRect& bounds); +#if defined(SK_GRAPHITE) + /** + * The 'asImage' and 'makeImageCopy' API/entry points are currently only available for + * Graphite. + * + * In this API, SkSurface no longer supports copy-on-write behavior. Instead, when creating + * an image for a surface, the client must explicitly indicate if a copy should be made. + * In both of the below calls the resource backing the surface will never change. + * + * The 'asImage' entry point has some major ramifications for the mutability of the + * returned SkImage. Since the originating surface and the returned image share the + * same backing, care must be taken by the client to ensure that the contents of the image + * reflect the desired contents when it is consumed by the gpu. + * Note: if the backing GPU buffer isn't textureable this method will return null. Graphite + * will not attempt to make a copy. + * Note: For 'asImage', the mipmapping of the image will match that of the source surface. + * + * The 'makeImageCopy' entry point allows subsetting and the addition of mipmaps (since + * a copy is already being made). + * + * In Graphite, the legacy API call (i.e., makeImageSnapshot) will just always make a copy. + */ + sk_sp asImage(); + + sk_sp makeImageCopy(const SkIRect* subset = nullptr, + skgpu::Mipmapped mipmapped = skgpu::Mipmapped::kNo); +#endif + /** Draws SkSurface contents to canvas, with its top-left corner at (x, y). If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter, and SkBlendMode. @@ -834,36 +886,6 @@ class SK_API SkSurface : public SkRefCnt { using RescaleGamma = SkImage::RescaleGamma; using RescaleMode = SkImage::RescaleMode; - /** Makes surface pixel data available to caller, possibly asynchronously. - - Currently asynchronous reads are only supported on the GPU backend and only when the - underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all - other cases this operates synchronously. - - Data is read from the source sub-rectangle, then converted to the color space, color type, - and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the surface - causes failure. - - When the pixel data is ready the caller's ReadPixelsCallback is called with a - AsyncReadResult containing pixel data in the requested color type, alpha type, and color - space. The AsyncReadResult will have count() == 1. Upon failure the callback is called - with nullptr for AsyncReadResult. For a GPU surface this flushes work but a submit must - occur to guarantee a finite time before the callback is called. - - The data is valid for the lifetime of AsyncReadResult with the exception that if the - SkSurface is GPU-backed the data is immediately invalidated if the context is abandoned - or destroyed. - - @param info info of the requested pixels - @param srcRect subrectangle of surface to read - @param callback function to call with result of the read - @param context passed to callback - */ - void asyncReadPixels(const SkImageInfo& info, - const SkIRect& srcRect, - ReadPixelsCallback callback, - ReadPixelsContext context); - /** Makes surface pixel data available to caller, possibly asynchronously. It can also rescale the surface pixels. @@ -994,7 +1016,7 @@ class SK_API SkSurface : public SkRefCnt { kPresent, //!< back-end surface will be used for presenting to screen }; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) /** If a surface is GPU texture backed, is being drawn with MSAA, and there is a resolve texture, this call will insert a resolve command into the stream of gpu commands. In order for the resolve to actually have an effect, the work still needs to be flushed and submitted @@ -1100,7 +1122,7 @@ class SK_API SkSurface : public SkRefCnt { */ GrSemaphoresSubmitted flush(const GrFlushInfo& info, const skgpu::MutableTextureState* newState = nullptr); -#endif // SK_SUPPORT_GPU +#endif // defined(SK_GANESH) void flush(); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h index 91b10e87bf7a9..0b65a10d03c4b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceCharacterization.h @@ -17,7 +17,7 @@ class SkColorSpace; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrContextThreadSafeProxy.h" #include "include/gpu/GrTypes.h" @@ -118,7 +118,7 @@ class SK_API SkSurfaceCharacterization { bool isCompatible(const GrBackendTexture&) const; private: - friend class SkSurface_Gpu; // for 'set' & 'config' + friend class SkSurface_Ganesh; // for 'set' & 'config' friend class GrVkSecondaryCBDrawContext; // for 'set' & 'config' friend class GrContextThreadSafeProxy; // for private ctor friend class SkDeferredDisplayListRecorder; // for 'config' @@ -210,7 +210,7 @@ class SK_API SkSurfaceCharacterization { SkSurfaceProps fSurfaceProps; }; -#else// !SK_SUPPORT_GPU +#else// !defined(SK_GANESH) class GrBackendFormat; class SK_API SkSurfaceCharacterization { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h index 7b07554e5be34..4790f258e4ad5 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkSurfaceProps.h @@ -9,6 +9,7 @@ #define SkSurfaceProps_DEFINED #include "include/core/SkTypes.h" +#include "include/private/base/SkTo.h" /** * Description of how the LCD strips are arranged for each pixel. If this is unknown, or the @@ -53,7 +54,10 @@ class SK_API SkSurfaceProps { enum Flags { kUseDeviceIndependentFonts_Flag = 1 << 0, // Use internal MSAA to render to non-MSAA GPU surfaces. - kDynamicMSAA_Flag = 1 << 1 + kDynamicMSAA_Flag = 1 << 1, + // If set, all rendering will have dithering enabled + // Currently this only impacts GPU backends + kAlwaysDither_Flag = 1 << 2, }; /** Deprecated alias used by Chromium. Will be removed. */ static const Flags kUseDistanceFieldFonts_Flag = kUseDeviceIndependentFonts_Flag; @@ -76,6 +80,10 @@ class SK_API SkSurfaceProps { return SkToBool(fFlags & kUseDeviceIndependentFonts_Flag); } + bool isAlwaysDither() const { + return SkToBool(fFlags & kAlwaysDither_Flag); + } + bool operator==(const SkSurfaceProps& that) const { return fFlags == that.fFlags && fPixelGeometry == that.fPixelGeometry; } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h index e010ea9cc788d..8f6cb01c045ff 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextBlob.h @@ -12,7 +12,7 @@ #include "include/core/SkPaint.h" #include "include/core/SkRefCnt.h" #include "include/core/SkString.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include @@ -491,7 +491,7 @@ class SK_API SkTextBlobBuilder { friend class SkTextBlobPriv; friend class SkTextBlobBuilderPriv; - SkAutoTMalloc fStorage; + skia_private::AutoTMalloc fStorage; size_t fStorageSize; size_t fStorageUsed; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h new file mode 100644 index 0000000000000..e9b441378d0c4 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTextureCompressionType.h @@ -0,0 +1,30 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkTextureCompressionType_DEFINED +#define SkTextureCompressionType_DEFINED +/* + * Skia | GL_COMPRESSED_* | MTLPixelFormat* | VK_FORMAT_*_BLOCK + * -------------------------------------------------------------------------------------- + * kETC2_RGB8_UNORM | ETC1_RGB8 | ETC2_RGB8 (iOS-only) | ETC2_R8G8B8_UNORM + * | RGB8_ETC2 | | + * -------------------------------------------------------------------------------------- + * kBC1_RGB8_UNORM | RGB_S3TC_DXT1_EXT | N/A | BC1_RGB_UNORM + * -------------------------------------------------------------------------------------- + * kBC1_RGBA8_UNORM | RGBA_S3TC_DXT1_EXT | BC1_RGBA (macOS-only)| BC1_RGBA_UNORM + */ +enum class SkTextureCompressionType { + kNone, + kETC2_RGB8_UNORM, + + kBC1_RGB8_UNORM, + kBC1_RGBA8_UNORM, + kLast = kBC1_RGBA8_UNORM, + kETC1_RGB8 = kETC2_RGB8_UNORM, +}; + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h index 3da2c8c7715b9..9135c7e113c0d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTime.h @@ -11,7 +11,7 @@ #define SkTime_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" #include diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h index d4a13877152d3..9e099d41e37f5 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypeface.h @@ -14,8 +14,8 @@ #include "include/core/SkFontTypes.h" #include "include/core/SkRect.h" #include "include/core/SkString.h" -#include "include/private/SkOnce.h" #include "include/private/SkWeakRefCnt.h" +#include "include/private/base/SkOnce.h" class SkData; class SkDescriptor; @@ -360,6 +360,12 @@ class SK_API SkTypeface : public SkWeakRefCnt { return this->onGetCTFontRef(); } + /* Skia reserves all tags that begin with a lower case letter and 0 */ + using FactoryId = SkFourByteTag; + static void Register( + FactoryId id, + sk_sp (*make)(std::unique_ptr, const SkFontArguments&)); + protected: explicit SkTypeface(const SkFontStyle& style, bool isFixedPitch = false); ~SkTypeface() override; @@ -435,7 +441,8 @@ class SK_API SkTypeface : public SkWeakRefCnt { * typefaces that contain a COLR table. */ bool glyphMaskNeedsCurrentColor() const; - friend class SkStrikeServerImpl; // glyphMaskNeedsCurrentColor + friend class SkStrikeServerImpl; // glyphMaskNeedsCurrentColor + friend class SkTypefaceProxyPrototype; // glyphMaskNeedsCurrentColor /** Retrieve detailed typeface metrics. Used by the PDF backend. */ std::unique_ptr getAdvancedMetrics() const; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h index 8f7a2c0982b68..5530cc4463b39 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkTypes.h @@ -8,235 +8,25 @@ #ifndef SkTypes_DEFINED #define SkTypes_DEFINED -/** \file SkTypes.h -*/ - -// Pre-SkUserConfig.h setup. - -// Allows embedders that want to disable macros that take arguments to just -// define that symbol to be one of these -#define SK_NOTHING_ARG1(arg1) -#define SK_NOTHING_ARG2(arg1, arg2) -#define SK_NOTHING_ARG3(arg1, arg2, arg3) - -#if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && \ - !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) - - #ifdef __APPLE__ - #include - #endif - - #if defined(_WIN32) || defined(__SYMBIAN32__) - #define SK_BUILD_FOR_WIN - #elif defined(ANDROID) || defined(__ANDROID__) - #define SK_BUILD_FOR_ANDROID - #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || \ - defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || \ - defined(__DragonFly__) || defined(__Fuchsia__) || \ - defined(__GLIBC__) || defined(__GNU__) || defined(__unix__) - #define SK_BUILD_FOR_UNIX - #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR - #define SK_BUILD_FOR_IOS - #else - #define SK_BUILD_FOR_MAC - #endif - -#endif - -#if defined(SK_BUILD_FOR_WIN) && !defined(__clang__) - #if !defined(SK_RESTRICT) - #define SK_RESTRICT __restrict - #endif - #if !defined(SK_WARN_UNUSED_RESULT) - #define SK_WARN_UNUSED_RESULT - #endif -#endif - -#if !defined(SK_RESTRICT) - #define SK_RESTRICT __restrict__ -#endif - -#if !defined(SK_WARN_UNUSED_RESULT) - #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#endif - -#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) - #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) - #define SK_CPU_BENDIAN - #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) - #define SK_CPU_LENDIAN - #elif defined(__sparc) || defined(__sparc__) || \ - defined(_POWER) || defined(__powerpc__) || \ - defined(__ppc__) || defined(__hppa) || \ - defined(__PPC__) || defined(__PPC64__) || \ - defined(_MIPSEB) || defined(__ARMEB__) || \ - defined(__s390__) || \ - (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ - (defined(__ia64) && defined(__BIG_ENDIAN__)) - #define SK_CPU_BENDIAN - #else - #define SK_CPU_LENDIAN - #endif -#endif - -#if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) - #define SK_CPU_X86 1 -#endif - -/** - * SK_CPU_SSE_LEVEL - * - * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. - * On non-intel CPU this should be undefined. - */ -#define SK_CPU_SSE_LEVEL_SSE1 10 -#define SK_CPU_SSE_LEVEL_SSE2 20 -#define SK_CPU_SSE_LEVEL_SSE3 30 -#define SK_CPU_SSE_LEVEL_SSSE3 31 -#define SK_CPU_SSE_LEVEL_SSE41 41 -#define SK_CPU_SSE_LEVEL_SSE42 42 -#define SK_CPU_SSE_LEVEL_AVX 51 -#define SK_CPU_SSE_LEVEL_AVX2 52 -#define SK_CPU_SSE_LEVEL_SKX 60 - -// Are we in GCC/Clang? -#ifndef SK_CPU_SSE_LEVEL - // These checks must be done in descending order to ensure we set the highest - // available SSE level. - #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ - defined(__AVX512BW__) && defined(__AVX512VL__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX - #elif defined(__AVX2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 - #elif defined(__AVX__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX - #elif defined(__SSE4_2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42 - #elif defined(__SSE4_1__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41 - #elif defined(__SSSE3__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 - #elif defined(__SSE3__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 - #elif defined(__SSE2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #endif -#endif - -// Are we in VisualStudio? -#ifndef SK_CPU_SSE_LEVEL - // These checks must be done in descending order to ensure we set the highest - // available SSE level. 64-bit intel guarantees at least SSE2 support. - #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ - defined(__AVX512BW__) && defined(__AVX512VL__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX - #elif defined(__AVX2__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 - #elif defined(__AVX__) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX - #elif defined(_M_X64) || defined(_M_AMD64) - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #elif defined(_M_IX86_FP) - #if _M_IX86_FP >= 2 - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 - #elif _M_IX86_FP == 1 - #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 - #endif - #endif -#endif - -// ARM defines -#if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) - #define SK_CPU_ARM32 -#elif defined(__aarch64__) - #define SK_CPU_ARM64 -#endif - -// All 64-bit ARM chips have NEON. Many 32-bit ARM chips do too. -#if !defined(SK_ARM_HAS_NEON) && defined(__ARM_NEON) - #define SK_ARM_HAS_NEON -#endif - -#if defined(__ARM_FEATURE_CRC32) - #define SK_ARM_HAS_CRC32 -#endif - - -// DLL/.so exports. -#if !defined(SKIA_IMPLEMENTATION) - #define SKIA_IMPLEMENTATION 0 -#endif -#if !defined(SK_API) - #if defined(SKIA_DLL) - #if defined(_MSC_VER) - #if SKIA_IMPLEMENTATION - #define SK_API __declspec(dllexport) - #else - #define SK_API __declspec(dllimport) - #endif - #else - #define SK_API __attribute__((visibility("default"))) - #endif - #else - #define SK_API - #endif -#endif - -// SK_SPI is functionally identical to SK_API, but used within src to clarify that it's less stable -#if !defined(SK_SPI) - #define SK_SPI SK_API -#endif - +// All of these files should be independent of things users can set via the user config file. +// They should also be able to be included in any order. // IWYU pragma: begin_exports -#if defined (SK_USER_CONFIG_HEADER) - #include SK_USER_CONFIG_HEADER -#else - #include "include/config/SkUserConfig.h" -#endif -// IWYU pragma: end_exports -#include -#include - -// Post SkUserConfig.h checks and such. -#if !defined(SK_DEBUG) && !defined(SK_RELEASE) - #ifdef NDEBUG - #define SK_RELEASE - #else - #define SK_DEBUG - #endif -#endif +#include "include/private/base/SkFeatures.h" -#if defined(SK_DEBUG) && defined(SK_RELEASE) -# error "cannot define both SK_DEBUG and SK_RELEASE" -#elif !defined(SK_DEBUG) && !defined(SK_RELEASE) -# error "must define either SK_DEBUG or SK_RELEASE" -#endif - -#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) -# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" -#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) -# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" -#endif - -#if defined(SK_CPU_BENDIAN) && !defined(I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN) - #error "The Skia team is not endian-savvy enough to support big-endian CPUs." - #error "If you still want to use Skia," - #error "please define I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN." -#endif +// Load and verify defines from the user config file. +#include "include/private/base/SkLoadUserConfig.h" -#if !defined(SK_ATTRIBUTE) -# if defined(__clang__) || defined(__GNUC__) -# define SK_ATTRIBUTE(attr) __attribute__((attr)) -# else -# define SK_ATTRIBUTE(attr) -# endif -#endif +// Any includes or defines below can be configured by the user config file. +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkDebug.h" +// IWYU pragma: end_exports -#if !defined(SK_SUPPORT_GPU) -# define SK_SUPPORT_GPU 1 -#endif +#include +#include -#if SK_SUPPORT_GPU || defined(SK_GRAPHITE_ENABLED) +#if defined(SK_GANESH) || defined(SK_GRAPHITE) # if !defined(SK_ENABLE_SKSL) # define SK_ENABLE_SKSL # endif @@ -248,45 +38,6 @@ # undef SK_DIRECT3D #endif -#if !defined(SkUNREACHABLE) -# if defined(_MSC_VER) && !defined(__clang__) -# include -# define FAST_FAIL_INVALID_ARG 5 -// See https://developercommunity.visualstudio.com/content/problem/1128631/code-flow-doesnt-see-noreturn-with-extern-c.html -// for why this is wrapped. Hopefully removable after msvc++ 19.27 is no longer supported. -[[noreturn]] static inline void sk_fast_fail() { __fastfail(FAST_FAIL_INVALID_ARG); } -# define SkUNREACHABLE sk_fast_fail() -# else -# define SkUNREACHABLE __builtin_trap() -# endif -#endif - -#if defined(SK_BUILD_FOR_GOOGLE3) - void SkDebugfForDumpStackTrace(const char* data, void* unused); - namespace base { - void DumpStackTrace(int skip_count, void w(const char*, void*), void* arg); - } -# define SK_DUMP_GOOGLE3_STACK() ::base::DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr) -#else -# define SK_DUMP_GOOGLE3_STACK() -#endif - -#ifndef SK_ABORT -# ifdef SK_BUILD_FOR_WIN - // This style lets Visual Studio follow errors back to the source file. -# define SK_DUMP_LINE_FORMAT "%s(%d)" -# else -# define SK_DUMP_LINE_FORMAT "%s:%d" -# endif -# define SK_ABORT(message, ...) \ - do { \ - SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \ - __FILE__, __LINE__, ##__VA_ARGS__); \ - SK_DUMP_GOOGLE3_STACK(); \ - sk_abort_no_print(); \ - } while (false) -#endif - // If SK_R32_SHIFT is set, we'll use that to choose RGBA or BGRA. // If not, we'll default to RGBA everywhere except BGRA on Windows. #if defined(SK_R32_SHIFT) @@ -306,7 +57,6 @@ #define SK_G32_SHIFT 8 #define SK_A32_SHIFT 24 - /** * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. */ @@ -332,48 +82,6 @@ #undef free #endif -#if !defined(SK_UNUSED) -# if !defined(__clang__) && defined(_MSC_VER) -# define SK_UNUSED __pragma(warning(suppress:4189)) -# else -# define SK_UNUSED SK_ATTRIBUTE(unused) -# endif -#endif - -/** - * If your judgment is better than the compiler's (i.e. you've profiled it), - * you can use SK_ALWAYS_INLINE to force inlining. E.g. - * inline void someMethod() { ... } // may not be inlined - * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined - */ -#if !defined(SK_ALWAYS_INLINE) -# if defined(SK_BUILD_FOR_WIN) -# define SK_ALWAYS_INLINE __forceinline -# else -# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline -# endif -#endif - -/** - * If your judgment is better than the compiler's (i.e. you've profiled it), - * you can use SK_NEVER_INLINE to prevent inlining. - */ -#if !defined(SK_NEVER_INLINE) -# if defined(SK_BUILD_FOR_WIN) -# define SK_NEVER_INLINE __declspec(noinline) -# else -# define SK_NEVER_INLINE SK_ATTRIBUTE(noinline) -# endif -#endif - -#ifndef SK_PRINTF_LIKE -# if defined(__clang__) || defined(__GNUC__) -# define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) -# else -# define SK_PRINTF_LIKE(A, B) -# endif -#endif - #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 0 #endif @@ -386,11 +94,6 @@ # define GR_TEST_UTILS 0 #endif -#if !SK_SUPPORT_GPU - #define SK_GPU_V1 0 // always false if Ganesh is disabled -#elif !defined(SK_GPU_V1) -# define SK_GPU_V1 1 // otherwise default to v1 enabled -#endif #if defined(SK_HISTOGRAM_ENUMERATION) || \ defined(SK_HISTOGRAM_BOOLEAN) || \ @@ -420,145 +123,44 @@ #define SK_HISTOGRAM_PERCENTAGE(name, percent_as_int) \ SK_HISTOGRAM_EXACT_LINEAR(name, percent_as_int, 101) -#ifndef SK_DISABLE_LEGACY_SHADERCONTEXT -#define SK_ENABLE_LEGACY_SHADERCONTEXT +// The top-level define SK_ENABLE_OPTIMIZE_SIZE can be used to remove several large features at once +#if defined(SK_ENABLE_OPTIMIZE_SIZE) +# define SK_FORCE_RASTER_PIPELINE_BLITTER +# define SK_DISABLE_SDF_TEXT #endif -#ifdef SK_ENABLE_API_AVAILABLE -#define SK_API_AVAILABLE API_AVAILABLE -#else -#define SK_API_AVAILABLE(...) +#ifndef SK_DISABLE_LEGACY_SHADERCONTEXT +# define SK_ENABLE_LEGACY_SHADERCONTEXT #endif #if defined(SK_BUILD_FOR_LIBFUZZER) || defined(SK_BUILD_FOR_AFL_FUZZ) +#if !defined(SK_BUILD_FOR_FUZZER) #define SK_BUILD_FOR_FUZZER #endif +#endif -/** Called internally if we hit an unrecoverable error. - The platform implementation must not return, but should either throw - an exception or otherwise exit. -*/ -[[noreturn]] SK_API extern void sk_abort_no_print(void); +/** + * Gr defines are set to 0 or 1, rather than being undefined or defined + */ -#ifndef SkDebugf - SK_API void SkDebugf(const char format[], ...) SK_PRINTF_LIKE(1, 2); +#if !defined(GR_CACHE_STATS) + #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) + #define GR_CACHE_STATS 1 + #else + #define GR_CACHE_STATS 0 + #endif #endif -// SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g. -// uint32_t foo(int x) { -// SkASSERT(x > 4); -// return x - 4; -// } -// and are also written to be compatible with constexpr functions: -// constexpr uint32_t foo(int x) { -// return SkASSERT(x > 4), -// x - 4; -// } -#define SkASSERT_RELEASE(cond) \ - static_cast( (cond) ? (void)0 : []{ SK_ABORT("assert(%s)", #cond); }() ) - -#ifdef SK_DEBUG - #define SkASSERT(cond) SkASSERT_RELEASE(cond) - #define SkASSERTF(cond, fmt, ...) static_cast( (cond) ? (void)0 : [&]{ \ - SkDebugf(fmt"\n", ##__VA_ARGS__); \ - SK_ABORT("assert(%s)", #cond); \ - }() ) - #define SkDEBUGFAIL(message) SK_ABORT("%s", message) - #define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__) - #define SkDEBUGCODE(...) __VA_ARGS__ - #define SkDEBUGF(...) SkDebugf(__VA_ARGS__) - #define SkAssertResult(cond) SkASSERT(cond) -#else - #define SkASSERT(cond) static_cast(0) - #define SkASSERTF(cond, fmt, ...) static_cast(0) - #define SkDEBUGFAIL(message) - #define SkDEBUGFAILF(fmt, ...) - #define SkDEBUGCODE(...) - #define SkDEBUGF(...) - - // unlike SkASSERT, this macro executes its condition in the non-debug build. - // The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT. - #define SkAssertResult(cond) if (cond) {} do {} while(false) +#if !defined(GR_GPU_STATS) + #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || GR_TEST_UTILS + #define GR_GPU_STATS 1 + #else + #define GR_GPU_STATS 0 + #endif #endif //////////////////////////////////////////////////////////////////////////////// -/** Fast type for unsigned 8 bits. Use for parameter passing and local - variables, not for storage -*/ -typedef unsigned U8CPU; - -/** Fast type for unsigned 16 bits. Use for parameter passing and local - variables, not for storage -*/ -typedef unsigned U16CPU; - -/** @return false or true based on the condition -*/ -template static constexpr bool SkToBool(const T& x) { - return (bool)x; -} - -static constexpr int16_t SK_MaxS16 = INT16_MAX; -static constexpr int16_t SK_MinS16 = -SK_MaxS16; - -static constexpr int32_t SK_MaxS32 = INT32_MAX; -static constexpr int32_t SK_MinS32 = -SK_MaxS32; -static constexpr int32_t SK_NaN32 = INT32_MIN; - -static constexpr int64_t SK_MaxS64 = INT64_MAX; -static constexpr int64_t SK_MinS64 = -SK_MaxS64; - -static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { - return (int32_t) ((uint32_t) value << shift); -} - -static inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) { - return (int64_t) ((uint64_t) value << shift); -} - -//////////////////////////////////////////////////////////////////////////////// - -/** @return the number of entries in an array (not a pointer) -*/ -// The SkArrayCountHelper template returns a type 'char (&)[N]', a reference to an array of -// char with N elements, where N is deduced using function parameter type deduction. This is then -// used in the sizeof operator in SK_ARRAY_COUNT. The sizeof operator ignores the reference, and -// just evaluates the size of the array type. -// -// DEPRECATED: use std::size() instead. -// Note: Rarely, std::size(z) can't deduce the type of z during compile time for static_assert -// while SK_ARRAY_COUNT can. It can't be deduced because z is part of class, and the class' this -// pointer is not a valid constexpr expression. Use SkASSERT instead. -template char (&SkArrayCountHelper(T (&array)[N]))[N]; -#define SK_ARRAY_COUNT(array) (sizeof(SkArrayCountHelper(array))) - -//////////////////////////////////////////////////////////////////////////////// - -template static constexpr T SkAlign2(T x) { return (x + 1) >> 1 << 1; } -template static constexpr T SkAlign4(T x) { return (x + 3) >> 2 << 2; } -template static constexpr T SkAlign8(T x) { return (x + 7) >> 3 << 3; } - -template static constexpr bool SkIsAlign2(T x) { return 0 == (x & 1); } -template static constexpr bool SkIsAlign4(T x) { return 0 == (x & 3); } -template static constexpr bool SkIsAlign8(T x) { return 0 == (x & 7); } - -template static constexpr T SkAlignPtr(T x) { - return sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x); -} -template static constexpr bool SkIsAlignPtr(T x) { - return sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x); -} - -/** - * align up to a power of 2 - */ -static inline constexpr size_t SkAlignTo(size_t x, size_t alignment) { - // The same as alignment && SkIsPow2(value), w/o a dependency cycle. - SkASSERT(alignment && (alignment & (alignment - 1)) == 0); - return (x + alignment - 1) & ~(alignment - 1); -} - typedef uint32_t SkFourByteTag; static inline constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d) { return (((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | (uint32_t)d); @@ -591,36 +193,5 @@ static constexpr uint32_t SK_InvalidGenID = 0; */ static constexpr uint32_t SK_InvalidUniqueID = 0; -static inline int32_t SkAbs32(int32_t value) { - SkASSERT(value != SK_NaN32); // The most negative int32_t can't be negated. - if (value < 0) { - value = -value; - } - return value; -} - -template static inline T SkTAbs(T value) { - if (value < 0) { - value = -value; - } - return value; -} - -//////////////////////////////////////////////////////////////////////////////// - -/** Indicates whether an allocation should count against a cache budget. -*/ -enum class SkBudgeted : bool { - kNo = false, - kYes = true -}; - -/** Indicates whether a backing store needs to be an exact match or can be - larger than is strictly necessary -*/ -enum class SkBackingFit { - kApprox, - kExact -}; #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h index fc53e9d01aaf8..2c3f784a42674 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkVertices.h @@ -12,6 +12,8 @@ #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include + class SkData; struct SkPoint; class SkVerticesPriv; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h index a3cf210f37099..bbbae5d383d94 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAInfo.h @@ -10,9 +10,13 @@ #include "include/codec/SkEncodedOrigin.h" #include "include/core/SkImageInfo.h" +#include "include/core/SkMatrix.h" #include "include/core/SkSize.h" +#include "include/core/SkTypes.h" #include +#include +#include #include /** diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h index de04ab14dc3c9..2ecb9005df1af 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/core/SkYUVAPixmaps.h @@ -8,14 +8,20 @@ #ifndef SkYUVAPixmaps_DEFINED #define SkYUVAPixmaps_DEFINED +#include "include/core/SkColorType.h" #include "include/core/SkData.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPixmap.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSize.h" +#include "include/core/SkTypes.h" #include "include/core/SkYUVAInfo.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" #include #include +#include +#include class GrImageContext; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h index bf131848baa12..16e953be5e5ed 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/docs/SkPDFDocument.h @@ -12,7 +12,7 @@ #include "include/core/SkScalar.h" #include "include/core/SkString.h" #include "include/core/SkTime.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #define SKPDF_STRING(X) SKPDF_STRING_IMPL(X) #define SKPDF_STRING_IMPL(X) #X @@ -143,6 +143,17 @@ struct Metadata { */ SkExecutor* fExecutor = nullptr; + /** PDF streams may be compressed to save space. + Use this to specify the desired compression vs time tradeoff. + */ + enum class CompressionLevel : int { + Default = -1, + None = 0, + LowButFast = 1, + Average = 6, + HighButSlow = 9, + } fCompressionLevel = CompressionLevel::Default; + /** Preferred Subsetter. Only respected if both are compiled in. The Sfntly subsetter is deprecated. diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h index ee470f96d38b2..5092278f0def3 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkColorMatrix.h @@ -8,12 +8,13 @@ #ifndef SkColorMatrix_DEFINED #define SkColorMatrix_DEFINED -#include "include/core/SkImageInfo.h" #include "include/core/SkTypes.h" #include #include +enum SkYUVColorSpace : int; + class SK_API SkColorMatrix { public: constexpr SkColorMatrix() : SkColorMatrix(1, 0, 0, 0, 0, diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h index df08c96f59322..43a67e242e11e 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkGradientShader.h @@ -62,10 +62,43 @@ class SK_API SkGradientShader { struct Interpolation { enum class InPremul : bool { kNo = false, kYes = true }; - InPremul fInPremul = InPremul::kNo; + enum class ColorSpace : uint8_t { + // Default Skia behavior: interpolate in the color space of the destination surface + kDestination, + + // https://www.w3.org/TR/css-color-4/#interpolation-space + kSRGBLinear, + kLab, + kOKLab, + kLCH, + kOKLCH, + kSRGB, + kHSL, + kHWB, + + kLastColorSpace = kHWB, + }; + static constexpr int kColorSpaceCount = static_cast(ColorSpace::kLastColorSpace) + 1; + + enum class HueMethod : uint8_t { + // https://www.w3.org/TR/css-color-4/#hue-interpolation + kShorter, + kLonger, + kIncreasing, + kDecreasing, + + kLastHueMethod = kDecreasing, + }; + static constexpr int kHueMethodCount = static_cast(HueMethod::kLastHueMethod) + 1; + + InPremul fInPremul = InPremul::kNo; + ColorSpace fColorSpace = ColorSpace::kDestination; + HueMethod fHueMethod = HueMethod::kShorter; // Only relevant for LCH, OKLCH, HSL, or HWB static Interpolation FromFlags(uint32_t flags) { - return {flags & kInterpolateColorsInPremul_Flag ? InPremul::kYes : InPremul::kNo}; + return {flags & kInterpolateColorsInPremul_Flag ? InPremul::kYes : InPremul::kNo, + ColorSpace::kDestination, + HueMethod::kShorter}; } }; @@ -76,8 +109,11 @@ class SK_API SkGradientShader { @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the start and end point. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >=2. The number of colors (and pos if not NULL) entries. @param mode The tiling mode @@ -95,8 +131,11 @@ class SK_API SkGradientShader { @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the start and end point. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >=2. The number of colors (and pos if not NULL) entries. @param mode The tiling mode @@ -123,8 +162,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the center and edge of the circle. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode The tiling mode */ @@ -141,8 +183,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, the the colors are distributed evenly between the center and edge of the circle. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode The tiling mode */ @@ -214,8 +259,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, then the colors are distributed evenly within the angular range. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode Tiling mode: controls drawing outside of the gradient angular range. @param startAngle Start of the angular range, corresponding to pos == 0. @@ -250,8 +298,11 @@ class SK_API SkGradientShader { @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of each corresponding color in the colors array. If this is NULL, then the colors are distributed evenly within the angular range. - If this is not null, the values must begin with 0, end with 1.0, and - intermediate values must be strictly increasing. + If this is not null, the values must lie between 0.0 and 1.0, and be + strictly increasing. If the first value is not 0.0, then an additional + color stop is added at position 0.0, with the same color as colors[0]. + If the the last value is not 1.0, then an additional color stop is added + at position 1.0, with the same color as colors[count - 1]. @param count Must be >= 2. The number of colors (and pos if not NULL) entries @param mode Tiling mode: controls drawing outside of the gradient angular range. @param startAngle Start of the angular range, corresponding to pos == 0. diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h index 5665c607015c7..75d2cb0bcc54f 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkImageFilters.h @@ -310,17 +310,6 @@ class SK_API SkImageFilters { static sk_sp Offset(SkScalar dx, SkScalar dy, sk_sp input, const CropRect& cropRect = {}); - /** - * Create a filter that fills the output with the given paint. - * @param paint The paint to fill - * @param cropRect Optional rectangle that will be filled. If null, the source bitmap's bounds - * are filled even though the source bitmap itself is not used. - * - * DEPRECATED: Use Shader() instead, since many features of SkPaint are ignored when filling - * the target output, and paint color/alpha can be emulated with SkShaders::Color(). - */ - static sk_sp Paint(const SkPaint& paint, const CropRect& cropRect = {}); - /** * Create a filter that produces the SkPicture as its output, drawn into targetRect. Note that * the targetRect is not the same as the SkIRect cropRect that many filters accept. Returns diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h index a8e0f4d7dc837..4d3450ee25878 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/effects/SkRuntimeEffect.h @@ -16,8 +16,10 @@ #include "include/core/SkShader.h" #include "include/core/SkSpan.h" #include "include/core/SkString.h" -#include "include/private/SkOnce.h" +#include "include/core/SkTypes.h" #include "include/private/SkSLSampleUsage.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkTemplates.h" #include #include @@ -34,6 +36,7 @@ class SkRuntimeImageFilter; namespace SkSL { class DebugTrace; +class DebugTracePriv; class ErrorReporter; class FunctionDefinition; struct Program; @@ -43,7 +46,11 @@ struct ProgramSettings; namespace skvm { class Program; -} // namespace skvm +} + +namespace SkSL::RP { +class Program; +} /* * SkRuntimeEffect supports creating custom SkShader and SkColorFilter objects using Skia's SkSL @@ -126,9 +133,9 @@ class SK_API SkRuntimeEffect : public SkRefCnt { friend class SkRuntimeEffect; friend class SkRuntimeEffectPriv; - // Public SkSL does not allow access to sk_FragCoord. The semantics of that variable are - // confusing, and expose clients to implementation details of saveLayer and image filters. - bool usePrivateRTShaderModule = false; + // This flag allows Runtime Effects to access Skia implementation details like sk_FragCoord + // and functions with private identifiers (e.g. $rgb_to_hsl). + bool allowPrivateAccess = false; // TODO(skia:11209) - Replace this with a promised SkCapabilities? // This flag lifts the ES2 restrictions on Runtime Effects that are gated by the @@ -276,6 +283,7 @@ class SK_API SkRuntimeEffect : public SkRefCnt { kSamplesOutsideMain_Flag = 0x10, kUsesColorTransform_Flag = 0x20, kAlwaysOpaque_Flag = 0x40, + kAlphaUnchanged_Flag = 0x80, }; SkRuntimeEffect(std::unique_ptr baseProgram, @@ -301,15 +309,17 @@ class SK_API SkRuntimeEffect : public SkRefCnt { bool samplesOutsideMain() const { return (fFlags & kSamplesOutsideMain_Flag); } bool usesColorTransform() const { return (fFlags & kUsesColorTransform_Flag); } bool alwaysOpaque() const { return (fFlags & kAlwaysOpaque_Flag); } + bool isAlphaUnchanged() const { return (fFlags & kAlphaUnchanged_Flag); } const SkFilterColorProgram* getFilterColorProgram() const; + const SkSL::RP::Program* getRPProgram(SkSL::DebugTracePriv* debugTrace) const; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) friend class GrSkSLFP; // fBaseProgram, fSampleUsages friend class GrGLSLSkSLFP; // #endif - friend class SkRTShader; // fBaseProgram, fMain + friend class SkRTShader; // fBaseProgram, fMain, fSampleUsages, getRPProgram() friend class SkRuntimeBlender; // friend class SkRuntimeColorFilter; // @@ -319,6 +329,8 @@ class SK_API SkRuntimeEffect : public SkRefCnt { uint32_t fHash; std::unique_ptr fBaseProgram; + std::unique_ptr fRPProgram; + mutable SkOnce fCompileRPProgramOnce; const SkSL::FunctionDefinition& fMain; std::vector fUniforms; std::vector fChildren; @@ -415,6 +427,11 @@ class SkRuntimeEffectBuilder { BuilderUniform uniform(std::string_view name) { return { this, fEffect->findUniform(name) }; } BuilderChild child(std::string_view name) { return { this, fEffect->findChild(name) }; } + // Get access to the collated uniforms and children (in the order expected by APIs like + // makeShader on the effect): + sk_sp uniforms() { return fUniforms; } + SkSpan children() { return fChildren; } + protected: SkRuntimeEffectBuilder() = delete; explicit SkRuntimeEffectBuilder(sk_sp effect) @@ -432,10 +449,6 @@ class SkRuntimeEffectBuilder { SkRuntimeEffectBuilder& operator=(SkRuntimeEffectBuilder&&) = delete; SkRuntimeEffectBuilder& operator=(const SkRuntimeEffectBuilder&) = delete; - sk_sp uniforms() { return fUniforms; } - SkRuntimeEffect::ChildPtr* children() { return fChildren.data(); } - size_t numChildren() { return fChildren.size(); } - private: void* writableUniformData() { if (!fUniforms->unique()) { @@ -492,6 +505,23 @@ class SK_API SkRuntimeShaderBuilder : public SkRuntimeEffectBuilder { friend class SkRuntimeImageFilter; }; +/** + * SkRuntimeColorFilterBuilder makes it easy to setup and assign uniforms to runtime color filters. + */ +class SK_API SkRuntimeColorFilterBuilder : public SkRuntimeEffectBuilder { +public: + explicit SkRuntimeColorFilterBuilder(sk_sp); + ~SkRuntimeColorFilterBuilder(); + + SkRuntimeColorFilterBuilder(const SkRuntimeColorFilterBuilder&) = delete; + SkRuntimeColorFilterBuilder& operator=(const SkRuntimeColorFilterBuilder&) = delete; + + sk_sp makeColorFilter(); + +private: + using INHERITED = SkRuntimeEffectBuilder; +}; + /** * SkRuntimeBlendBuilder is a utility to simplify creation and uniform setup of runtime blenders. */ diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h index 657b9a98a96c7..8f76e8016c848 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkEncoder.h @@ -9,8 +9,12 @@ #define SkEncoder_DEFINED #include "include/core/SkPixmap.h" -#include "include/private/SkNoncopyable.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkNoncopyable.h" +#include "include/private/base/SkTemplates.h" + +#include +#include class SK_API SkEncoder : SkNoncopyable { public: @@ -53,7 +57,7 @@ class SK_API SkEncoder : SkNoncopyable { const SkPixmap& fSrc; int fCurrRow; - SkAutoTMalloc fStorage; + skia_private::AutoTMalloc fStorage; }; #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h new file mode 100644 index 0000000000000..b14836b2ab6aa --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkICC.h @@ -0,0 +1,36 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkICC_DEFINED +#define SkICC_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" + +#include + +class SkData; +struct skcms_ICCProfile; +struct skcms_Matrix3x3; +struct skcms_TransferFunction; + +SK_API sk_sp SkWriteICCProfile(const skcms_TransferFunction&, + const skcms_Matrix3x3& toXYZD50); + +SK_API sk_sp SkWriteICCProfile(const skcms_ICCProfile*, const char* description); + +// Utility function for populating the grid_16 member of skcms_A2B and skcms_B2A +// structures. This converts a point in XYZD50 to its representation in grid_16_lab. +// It will write 6 bytes. The behavior of this function matches how skcms will decode +// values, but might not match the specification, see https://crbug.com/skia/13807. +SK_API void SkICCFloatXYZD50ToGrid16Lab(const float* float_xyz, uint8_t* grid16_lab); + +// Utility function for popluating the table_16 member of skcms_Curve structure. +// This converts a float to its representation in table_16. It will write 2 bytes. +SK_API void SkICCFloatToTable16(const float f, uint8_t* table_16); + +#endif//SkICC_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h index f2107f1263a38..f7e8effa7fa5b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkJpegEncoder.h @@ -8,90 +8,121 @@ #ifndef SkJpegEncoder_DEFINED #define SkJpegEncoder_DEFINED -#include "include/encode/SkEncoder.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" -class SkJpegEncoderMgr; +#include + +class SkColorSpace; +class SkData; +class SkEncoder; +class SkPixmap; class SkWStream; +class SkImage; +class GrDirectContext; +class SkYUVAPixmaps; +struct skcms_ICCProfile; + +namespace SkJpegEncoder { -class SK_API SkJpegEncoder : public SkEncoder { -public: - - enum class AlphaOption { - kIgnore, - kBlendOnBlack, - }; - - enum class Downsample { - /** - * Reduction by a factor of two in both the horizontal and vertical directions. - */ - k420, - - /** - * Reduction by a factor of two in the horizontal direction. - */ - k422, - - /** - * No downsampling. - */ - k444, - }; - - struct Options { - /** - * |fQuality| must be in [0, 100] where 0 corresponds to the lowest quality. - */ - int fQuality = 100; - - /** - * Choose the downsampling factor for the U and V components. This is only - * meaningful if the |src| is not kGray, since kGray will not be encoded as YUV. - * - * Our default value matches the libjpeg-turbo default. - */ - Downsample fDownsample = Downsample::k420; - - /** - * Jpegs must be opaque. This instructs the encoder on how to handle input - * images with alpha. - * - * The default is to ignore the alpha channel and treat the image as opaque. - * Another option is to blend the pixels onto a black background before encoding. - * In the second case, the encoder supports linear or legacy blending. - */ - AlphaOption fAlphaOption = AlphaOption::kIgnore; - }; +enum class AlphaOption { + kIgnore, + kBlendOnBlack, +}; +enum class Downsample { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * Reduction by a factor of two in both the horizontal and vertical directions. */ - static bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + k420, /** - * Create a jpeg encoder that will encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * |dst| is unowned but must remain valid for the lifetime of the object. - * - * This returns nullptr on an invalid or unsupported |src|. + * Reduction by a factor of two in the horizontal direction. */ - static std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, - const Options& options); + k422, - ~SkJpegEncoder() override; + /** + * No downsampling. + */ + k444, +}; + +struct Options { + /** + * |fQuality| must be in [0, 100] where 0 corresponds to the lowest quality. + */ + int fQuality = 100; + + /** + * Choose the downsampling factor for the U and V components. This is only + * meaningful if the |src| is not kGray, since kGray will not be encoded as YUV. + * This is ignored in favor of |src|'s subsampling when |src| is an SkYUVAPixmaps. + * + * Our default value matches the libjpeg-turbo default. + */ + Downsample fDownsample = Downsample::k420; -protected: - bool onEncodeRows(int numRows) override; + /** + * Jpegs must be opaque. This instructs the encoder on how to handle input + * images with alpha. + * + * The default is to ignore the alpha channel and treat the image as opaque. + * Another option is to blend the pixels onto a black background before encoding. + * In the second case, the encoder supports linear or legacy blending. + */ + AlphaOption fAlphaOption = AlphaOption::kIgnore; -private: - SkJpegEncoder(std::unique_ptr, const SkPixmap& src); + /** + * Optional XMP metadata. + */ + const SkData* xmpMetadata = nullptr; - std::unique_ptr fEncoderMgr; - using INHERITED = SkEncoder; + /** + * An optional ICC profile to override the default behavior. + * + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. + */ + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; }; +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); +SK_API bool Encode(SkWStream* dst, + const SkYUVAPixmaps& src, + const SkColorSpace* srcColorSpace, + const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Create a jpeg encoder that will encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * |dst| is unowned but must remain valid for the lifetime of the object. + * + * This returns nullptr on an invalid or unsupported |src|. + */ +SK_API std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, const Options& options); +SK_API std::unique_ptr Make(SkWStream* dst, + const SkYUVAPixmaps& src, + const SkColorSpace* srcColorSpace, + const Options& options); +} // namespace SkJpegEncoder + #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h index ccfa292f747d7..b26befa323ef3 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkPngEncoder.h @@ -9,91 +9,109 @@ #define SkPngEncoder_DEFINED #include "include/core/SkDataTable.h" -#include "include/encode/SkEncoder.h" +#include "include/core/SkRefCnt.h" +#include "include/private/base/SkAPI.h" -class SkPngEncoderMgr; +// TODO(kjlubick) update clients to directly include this +#include "include/encode/SkEncoder.h" // IWYU pragma: keep + +#include + +class GrDirectContext; +class SkData; +class SkImage; +class SkPixmap; class SkWStream; +struct skcms_ICCProfile; + +namespace SkPngEncoder { + +enum class FilterFlag : int { + kZero = 0x00, + kNone = 0x08, + kSub = 0x10, + kUp = 0x20, + kAvg = 0x40, + kPaeth = 0x80, + kAll = kNone | kSub | kUp | kAvg | kPaeth, +}; -class SK_API SkPngEncoder : public SkEncoder { -public: - - enum class FilterFlag : int { - kZero = 0x00, - kNone = 0x08, - kSub = 0x10, - kUp = 0x20, - kAvg = 0x40, - kPaeth = 0x80, - kAll = kNone | kSub | kUp | kAvg | kPaeth, - }; - - struct Options { - /** - * Selects which filtering strategies to use. - * - * If a single filter is chosen, libpng will use that filter for every row. - * - * If multiple filters are chosen, libpng will use a heuristic to guess which filter - * will encode smallest, then apply that filter. This happens on a per row basis, - * different rows can use different filters. - * - * Using a single filter (or less filters) is typically faster. Trying all of the - * filters may help minimize the output file size. - * - * Our default value matches libpng's default. - */ - FilterFlag fFilterFlags = FilterFlag::kAll; - - /** - * Must be in [0, 9] where 9 corresponds to maximal compression. This value is passed - * directly to zlib. 0 is a special case to skip zlib entirely, creating dramatically - * larger pngs. - * - * Our default value matches libpng's default. - */ - int fZLibLevel = 6; - - /** - * Represents comments in the tEXt ancillary chunk of the png. - * The 2i-th entry is the keyword for the i-th comment, - * and the (2i + 1)-th entry is the text for the i-th comment. - */ - sk_sp fComments; - }; +inline FilterFlag operator|(FilterFlag x, FilterFlag y) { return (FilterFlag)((int)x | (int)y); } +struct Options { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * Selects which filtering strategies to use. + * + * If a single filter is chosen, libpng will use that filter for every row. + * + * If multiple filters are chosen, libpng will use a heuristic to guess which filter + * will encode smallest, then apply that filter. This happens on a per row basis, + * different rows can use different filters. + * + * Using a single filter (or less filters) is typically faster. Trying all of the + * filters may help minimize the output file size. * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * Our default value matches libpng's default. */ - static bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + FilterFlag fFilterFlags = FilterFlag::kAll; /** - * Create a png encoder that will encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * Must be in [0, 9] where 9 corresponds to maximal compression. This value is passed + * directly to zlib. 0 is a special case to skip zlib entirely, creating dramatically + * larger pngs. * - * |dst| is unowned but must remain valid for the lifetime of the object. - * - * This returns nullptr on an invalid or unsupported |src|. + * Our default value matches libpng's default. */ - static std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, - const Options& options); - - ~SkPngEncoder() override; - -protected: - bool onEncodeRows(int numRows) override; + int fZLibLevel = 6; - SkPngEncoder(std::unique_ptr, const SkPixmap& src); + /** + * Represents comments in the tEXt ancillary chunk of the png. + * The 2i-th entry is the keyword for the i-th comment, + * and the (2i + 1)-th entry is the text for the i-th comment. + */ + sk_sp fComments; - std::unique_ptr fEncoderMgr; - using INHERITED = SkEncoder; + /** + * An optional ICC profile to override the default behavior. + * + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. + */ + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; }; -static inline SkPngEncoder::FilterFlag operator|(SkPngEncoder::FilterFlag x, - SkPngEncoder::FilterFlag y) { - return (SkPngEncoder::FilterFlag)((int)x | (int)y); -} +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Create a png encoder that will encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * The primary use of this is incremental encoding of the pixels. + * + * |dst| is unowned but must remain valid for the lifetime of the object. + * + * This returns nullptr on an invalid or unsupported |src|. + */ +SK_API std::unique_ptr Make(SkWStream* dst, const SkPixmap& src, const Options& options); + +} // namespace SkPngEncoder #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h index 1930e4099f84a..fe11044e73804 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/encode/SkWebpEncoder.h @@ -8,58 +8,85 @@ #ifndef SkWebpEncoder_DEFINED #define SkWebpEncoder_DEFINED -#include "include/core/SkSpan.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSpan.h" // IWYU pragma: keep #include "include/encode/SkEncoder.h" +#include "include/private/base/SkAPI.h" +class SkPixmap; class SkWStream; +class SkData; +class GrDirectContext; +class SkImage; +struct skcms_ICCProfile; namespace SkWebpEncoder { - enum class Compression { - kLossy, - kLossless, - }; - - struct SK_API Options { - /** - * |fCompression| determines whether we will use webp lossy or lossless compression. - * - * |fQuality| must be in [0.0f, 100.0f]. - * If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the - * encoding. Decreasing the quality will result in a smaller encoded image. - * If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort - * put into the encoding. Lower values will compress faster into larger files, - * while larger values will compress slower into smaller files. - * - * This scheme is designed to match the libwebp API. - */ - Compression fCompression = Compression::kLossy; - float fQuality = 100.0f; - }; +enum class Compression { + kLossy, + kLossless, +}; +struct SK_API Options { /** - * Encode the |src| pixels to the |dst| stream. - * |options| may be used to control the encoding behavior. + * |fCompression| determines whether we will use webp lossy or lossless compression. + * + * |fQuality| must be in [0.0f, 100.0f]. + * If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the + * encoding. Decreasing the quality will result in a smaller encoded image. + * If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort + * put into the encoding. Lower values will compress faster into larger files, + * while larger values will compress slower into smaller files. * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * This scheme is designed to match the libwebp API. */ - SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + Compression fCompression = Compression::kLossy; + float fQuality = 100.0f; /** - * Encode the |src| frames to the |dst| stream. - * |options| may be used to control the encoding behavior. - * - * The size of the first frame will be used as the canvas size. If any other frame does - * not match the canvas size, this is an error. - * - * Returns true on success. Returns false on an invalid or unsupported |src|. + * An optional ICC profile to override the default behavior. * - * Note: libwebp API also supports set background color, loop limit and customize - * lossy/lossless for each frame. These could be added later as needed. + * The default behavior is to generate an ICC profile using a primary matrix and + * analytic transfer function. If the color space of |src| cannot be represented + * in this way (e.g, it is HLG or PQ), then no profile will be embedded. */ - SK_API bool EncodeAnimated(SkWStream* dst, - SkSpan src, - const Options& options); + const skcms_ICCProfile* fICCProfile = nullptr; + const char* fICCProfileDescription = nullptr; +}; + +/** + * Encode the |src| pixels to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ +SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); + +/** +* Encode the provided image and return the resulting bytes. If the image was created as +* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels +* can be read before being encoded. For raster-backed images, |ctx| can be nullptr. +* |options| may be used to control the encoding behavior. +* +* Returns nullptr if the pixels could not be read or encoding otherwise fails. +*/ +SK_API sk_sp Encode(GrDirectContext* ctx, const SkImage* img, const Options& options); + +/** + * Encode the |src| frames to the |dst| stream. + * |options| may be used to control the encoding behavior. + * + * The size of the first frame will be used as the canvas size. If any other frame does + * not match the canvas size, this is an error. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + * + * Note: libwebp API also supports set background color, loop limit and customize + * lossy/lossless for each frame. These could be added later as needed. + */ +SK_API bool EncodeAnimated(SkWStream* dst, + SkSpan src, + const Options& options); } // namespace SkWebpEncoder #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h index 2eb88a8d433ce..e2e3961f8b9e5 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GpuTypes.h @@ -26,16 +26,29 @@ enum class BackendApi : unsigned { kMock, }; +/** Indicates whether an allocation should count against a cache budget. */ +enum class Budgeted : bool { + kNo = false, + kYes = true, +}; + /** * Value passed into various callbacks to tell the client the result of operations connected to a * specific callback. The actual interpretation of kFailed and kSuccess are dependent on the * specific callbacks and are documented with the callback itself. */ enum class CallbackResult : bool { - kFailed = true, + kFailed = false, kSuccess = true, }; +/** + * Is the texture mipmapped or not + */ +enum class Mipmapped : bool { + kNo = false, + kYes = true, +}; /** * Is the data protected on the GPU or not. @@ -45,6 +58,15 @@ enum class Protected : bool { kYes = true, }; +/** + * Is a texture renderable or not + */ +enum class Renderable : bool { + kNo = false, + kYes = true, +}; + } // namespace skgpu + #endif // skgpu_GpuTypes_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h index 759cc1d39837a..37ab666d52ec4 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrBackendSurface.h @@ -35,6 +35,7 @@ class GrVkImageLayout; class GrGLTextureParameters; class GrColorFormatDesc; +enum class SkTextureCompressionType; namespace skgpu { class MutableTextureStateRef; @@ -57,7 +58,7 @@ class GrD3DResourceState; class SkString; #endif -#if !SK_SUPPORT_GPU +#if !defined(SK_GANESH) // SkSurfaceCharacterization always needs a minimal version of this class SK_API GrBackendFormat { @@ -124,7 +125,8 @@ class SK_API GrBackendFormat { } #endif - static GrBackendFormat MakeMock(GrColorType colorType, SkImage::CompressionType compression, + static GrBackendFormat MakeMock(GrColorType colorType, + SkTextureCompressionType compression, bool isStencilFormat = false); bool operator==(const GrBackendFormat& that) const; @@ -191,7 +193,7 @@ class SK_API GrBackendFormat { * kUnknown, the compression type is not kNone, or this is a mock stencil format. */ GrColorType asMockColorType() const; - SkImage::CompressionType asMockCompressionType() const; + SkTextureCompressionType asMockCompressionType() const; bool isMockStencilFormat() const; // If possible, copies the GrBackendFormat and forces the texture type to be Texture2D. If the @@ -228,7 +230,7 @@ class SK_API GrBackendFormat { GrBackendFormat(DXGI_FORMAT dxgiFormat); #endif - GrBackendFormat(GrColorType, SkImage::CompressionType, bool isStencilFormat); + GrBackendFormat(GrColorType, SkTextureCompressionType, bool isStencilFormat); #ifdef SK_DEBUG bool validateMock() const; @@ -259,9 +261,9 @@ class SK_API GrBackendFormat { DXGI_FORMAT fDxgiFormat; #endif struct { - GrColorType fColorType; - SkImage::CompressionType fCompressionType; - bool fIsStencilFormat; + GrColorType fColorType; + SkTextureCompressionType fCompressionType; + bool fIsStencilFormat; } fMock; }; GrTextureType fTextureType = GrTextureType::kNone; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h deleted file mode 100644 index 9fe6629dd7ead..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrConfig.h +++ /dev/null @@ -1,53 +0,0 @@ - -/* - * Copyright 2010 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrConfig_DEFINED -#define GrConfig_DEFINED - -#include "include/core/SkTypes.h" - -/** - * Gr defines are set to 0 or 1, rather than being undefined or defined - */ - -#if !defined(GR_CACHE_STATS) - #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) - #define GR_CACHE_STATS 1 - #else - #define GR_CACHE_STATS 0 - #endif -#endif - -#if !defined(GR_GPU_STATS) - #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || GR_TEST_UTILS - #define GR_GPU_STATS 1 - #else - #define GR_GPU_STATS 0 - #endif -#endif - -#endif - -/** - * GR_STRING makes a string of X where X is expanded before conversion to a string - * if X itself contains macros. - */ -#define GR_STRING(X) GR_STRING_IMPL(X) -#define GR_STRING_IMPL(X) #X - -/** - * GR_CONCAT concatenates X and Y where each is expanded before - * contanenation if either contains macros. - */ -#define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y) -#define GR_CONCAT_IMPL(X,Y) X##Y - -/** - * Creates a string of the form "() : " - */ -#define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : " diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h index 28675297a1331..bf4ca409a8f6d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextOptions.h @@ -20,7 +20,7 @@ class SkExecutor; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) struct SK_API GrContextOptions { enum class Enable { /** Forces an option to be disabled. */ @@ -80,8 +80,9 @@ struct SK_API GrContextOptions { /** * Controls whether we check for GL errors after functions that allocate resources (e.g. - * glTexImage2D), for shader compilation success, and program link success. Ignored on - * backends other than GL. + * glTexImage2D), at the end of a GPU submission, or checking framebuffer completeness. The + * results of shader compilation and program linking are always checked, regardless of this + * option. Ignored on backends other than GL. */ Enable fSkipGLErrorChecks = Enable::kDefault; @@ -244,6 +245,12 @@ struct SK_API GrContextOptions { */ bool fSuppressMipmapSupport = false; + /** + * If true, the TessellationPathRenderer will not be used for path rendering. + * If false, will fallback to any driver workarounds, if set. + */ + bool fDisableTessellationPathRenderer = false; + /** * If true, and if supported, enables hardware tessellation in the caps. * DEPRECATED: This value is ignored; experimental hardware tessellation is always disabled. @@ -254,13 +261,7 @@ struct SK_API GrContextOptions { * If true, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp * rendering of all glyphs. This must be set to true to use Slugs. */ - #if defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_STRIKE_SERIALIZE) - bool fSupportBilerpFromGlyphAtlas = true; - #else bool fSupportBilerpFromGlyphAtlas = false; - #endif /** * Uses a reduced variety of shaders. May perform less optimally in steady state but can reduce @@ -273,6 +274,24 @@ struct SK_API GrContextOptions { */ bool fAllowMSAAOnNewIntel = false; + /** + * Currently on ARM Android we disable the use of GL TexStorage because of memory regressions. + * However, some clients may still want to use TexStorage. For example, TexStorage support is + * required for creating protected textures. + * + * This flag has no impact on non GL backends. + */ + bool fAlwaysUseTexStorageWhenAvailable = false; + + /** + * Optional callback that can be passed into the GrDirectContext which will be called when the + * GrDirectContext is about to be destroyed. When this call is made, it will be safe for the + * client to delete the GPU backend context that is backing the GrDirectContext. The + * GrDirectContextDestroyedContext will be passed back to the client in the callback. + */ + GrDirectContextDestroyedContext fContextDeleteContext = nullptr; + GrDirectContextDestroyedProc fContextDeleteProc = nullptr; + #if GR_TEST_UTILS /** * Private options that are only meant for testing within Skia's tools. diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h index 7e1ee65ffcdd5..eb755553647b9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrContextThreadSafeProxy.h @@ -10,9 +10,10 @@ #include "include/core/SkRefCnt.h" -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) #include "include/core/SkImageInfo.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/GrContextOptions.h" #include "include/gpu/GrTypes.h" @@ -25,6 +26,7 @@ class GrThreadSafeCache; class GrThreadSafePipelineBuilder; class SkSurfaceCharacterization; class SkSurfaceProps; +enum class SkTextureCompressionType; namespace sktext::gpu { class TextBlobRedrawCoordinator; } @@ -107,13 +109,13 @@ class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt fAbandoned{false}; }; -#else // !SK_SUPPORT_GPU +#else // !defined(SK_GANESH) class SK_API GrContextThreadSafeProxy final : public SkNVRefCnt {}; #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h index 903623fb7161d..a22fc4fe5784c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDirectContext.h @@ -8,46 +8,52 @@ #ifndef GrDirectContext_DEFINED #define GrDirectContext_DEFINED +#include "include/core/SkColor.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" +#include "include/gpu/GpuTypes.h" +#include "include/gpu/GrContextOptions.h" #include "include/gpu/GrRecordingContext.h" +#include "include/gpu/GrTypes.h" -#include "include/gpu/GrBackendSurface.h" - -// We shouldn't need this but currently Android is relying on this being include transitively. -#include "include/core/SkUnPreMultiply.h" +#include +#include +#include +#include +#include class GrAtlasManager; class GrBackendSemaphore; +class GrBackendFormat; +class GrBackendTexture; +class GrBackendRenderTarget; class GrClientMappedBufferManager; -class GrDirectContextPriv; class GrContextThreadSafeProxy; -struct GrD3DBackendContext; -class GrFragmentProcessor; +class GrDirectContextPriv; class GrGpu; -struct GrGLInterface; -struct GrMtlBackendContext; -struct GrMockOptions; -class GrPath; class GrResourceCache; class GrResourceProvider; -class GrSurfaceProxy; -class GrTextureProxy; -struct GrVkBackendContext; - +class SkData; class SkImage; -class SkString; -class SkSurfaceCharacterization; -class SkSurfaceProps; +class SkPixmap; class SkTaskGroup; class SkTraceMemoryDump; +enum SkColorType : int; +enum class SkTextureCompressionType; +struct GrGLInterface; +struct GrMockOptions; +struct GrVkBackendContext; // IWYU pragma: keep +struct GrD3DBackendContext; // IWYU pragma: keep +struct GrMtlBackendContext; // IWYU pragma: keep namespace skgpu { -class Swizzle; -namespace v1 { class SmallPathAtlasMgr; } -} - -namespace sktext::gpu { -class StrikeCache; + class MutableTextureState; +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + namespace ganesh { class SmallPathAtlasMgr; } +#endif } +namespace sktext { namespace gpu { class StrikeCache; } } +namespace wgpu { class Device; } // IWYU pragma: keep class SK_API GrDirectContext : public GrRecordingContext { public: @@ -387,7 +393,24 @@ class SK_API GrDirectContext : public GrRecordingContext { */ GrSemaphoresSubmitted flush(const GrFlushInfo& info); - void flush() { this->flush({}); } + void flush() { this->flush(GrFlushInfo()); } + + /** Flushes any pending uses of texture-backed images in the GPU backend. If the image is not + * texture-backed (including promise texture images) or if the GrDirectContext does not + * have the same context ID as the context backing the image then this is a no-op. + * If the image was not used in any non-culled draws in the current queue of work for the + * passed GrDirectContext then this is a no-op unless the GrFlushInfo contains semaphores or + * a finish proc. Those are respected even when the image has not been used. + * @param image the non-null image to flush. + * @param info flush options + */ + GrSemaphoresSubmitted flush(sk_sp image, const GrFlushInfo& info); + void flush(sk_sp image); + + /** Version of flush() that uses a default GrFlushInfo. Also submits the flushed work to the + GPU. + */ + void flushAndSubmit(sk_sp image); /** * Submit outstanding work to the gpu from all previously un-submitted flushes. The return @@ -548,10 +571,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(&srcData, 1, textureOrigin, renderable, isProtected, - finishedProc, finishedContext, label); - } + std::string_view label = {}); // Deprecated versions that do not take origin and assume top-left. GrBackendTexture createBackendTexture(const SkPixmap srcData[], @@ -560,30 +580,14 @@ class SK_API GrDirectContext : public GrRecordingContext { GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(srcData, - numLevels, - kTopLeft_GrSurfaceOrigin, - renderable, - isProtected, - finishedProc, - finishedContext, - label); - } + std::string_view label = {}); + GrBackendTexture createBackendTexture(const SkPixmap& srcData, GrRenderable renderable, GrProtected isProtected, GrGpuFinishedProc finishedProc = nullptr, GrGpuFinishedContext finishedContext = nullptr, - std::string_view label = {}) { - return this->createBackendTexture(&srcData, - 1, - renderable, - isProtected, - finishedProc, - finishedContext, - label); - } + std::string_view label = {}); /** * If possible, updates a backend texture to be filled to a particular color. The client should @@ -662,17 +666,10 @@ class SK_API GrDirectContext : public GrRecordingContext { const SkPixmap srcData[], int numLevels, GrGpuFinishedProc finishedProc, - GrGpuFinishedContext finishedContext) { - return this->updateBackendTexture(texture, - srcData, - numLevels, - kTopLeft_GrSurfaceOrigin, - finishedProc, - finishedContext); - } + GrGpuFinishedContext finishedContext); /** - * Retrieve the GrBackendFormat for a given SkImage::CompressionType. This is + * Retrieve the GrBackendFormat for a given SkTextureCompressionType. This is * guaranteed to match the backend format used by the following * createCompressedBackendTexture methods that take a CompressionType. * @@ -698,7 +695,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrGpuFinishedContext finishedContext = nullptr); GrBackendTexture createCompressedBackendTexture(int width, int height, - SkImage::CompressionType, + SkTextureCompressionType, const SkColor4f& color, GrMipmapped, GrProtected = GrProtected::kNo, @@ -726,7 +723,7 @@ class SK_API GrDirectContext : public GrRecordingContext { GrGpuFinishedContext finishedContext = nullptr); GrBackendTexture createCompressedBackendTexture(int width, int height, - SkImage::CompressionType, + SkTextureCompressionType, const void* data, size_t dataSize, GrMipmapped, GrProtected = GrProtected::kNo, @@ -850,7 +847,9 @@ class SK_API GrDirectContext : public GrRecordingContext { bool init() override; GrAtlasManager* onGetAtlasManager() { return fAtlasManager.get(); } - skgpu::v1::SmallPathAtlasMgr* onGetSmallPathAtlasMgr(); +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + skgpu::ganesh::SmallPathAtlasMgr* onGetSmallPathAtlasMgr(); +#endif GrDirectContext* asDirectContext() override { return this; } @@ -868,6 +867,28 @@ class SK_API GrDirectContext : public GrRecordingContext { // bool is used for this signal. void syncAllOutstandingGpuWork(bool shouldExecuteWhileAbandoned); + // This delete callback needs to be the first thing on the GrDirectContext so that it is the + // last thing destroyed. The callback may signal the client to clean up things that may need + // to survive the lifetime of some of the other objects on the GrDirectCotnext. So make sure + // we don't call it until all else has been destroyed. + class DeleteCallbackHelper { + public: + DeleteCallbackHelper(GrDirectContextDestroyedContext context, + GrDirectContextDestroyedProc proc) + : fContext(context), fProc(proc) {} + + ~DeleteCallbackHelper() { + if (fProc) { + fProc(fContext); + } + } + + private: + GrDirectContextDestroyedContext fContext; + GrDirectContextDestroyedProc fProc; + }; + std::unique_ptr fDeleteCallbackHelper; + const DirectContextID fDirectContextID; // fTaskGroup must appear before anything that uses it (e.g. fGpu), so that it is destroyed // after all of its users. Clients of fTaskGroup will generally want to ensure that they call @@ -894,11 +915,11 @@ class SK_API GrDirectContext : public GrRecordingContext { std::unique_ptr fMappedBufferManager; std::unique_ptr fAtlasManager; - std::unique_ptr fSmallPathAtlasMgr; +#if !defined(SK_ENABLE_OPTIMIZE_SIZE) + std::unique_ptr fSmallPathAtlasMgr; +#endif friend class GrDirectContextPriv; - - using INHERITED = GrRecordingContext; }; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h index c57efc6016586..1aa995c79177a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrDriverBugWorkarounds.h @@ -13,7 +13,8 @@ #ifdef SK_GPU_WORKAROUNDS_HEADER #include SK_GPU_WORKAROUNDS_HEADER #else -// To regenerate this file, set gn arg "skia_generate_workarounds = true". +// To regenerate this file, set gn arg "skia_generate_workarounds = true" +// or invoke `bazel run //tools:generate_workarounds` // This is not rebuilt by default to avoid embedders having to have extra // build steps. #include "include/gpu/GrDriverBugWorkaroundsAutogen.h" diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h index f8b9c3f39230a..85cc77c051c8f 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrRecordingContext.h @@ -9,7 +9,8 @@ #define GrRecordingContext_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkTArray.h" +#include "include/core/SkTypes.h" +#include "include/private/base/SkTArray.h" #include "include/private/gpu/ganesh/GrImageContext.h" #if GR_GPU_STATS && GR_TEST_UTILS @@ -190,7 +191,7 @@ class GrRecordingContext : public GrImageContext { // of the programInfos matches the intended use. For example, in DDL-record mode it // is known that all the programInfos will have been allocated in an arena with the // same lifetime at the DDL itself. - virtual void detachProgramData(SkTArray*) {} + virtual void detachProgramData(skia_private::TArray*) {} sktext::gpu::TextBlobRedrawCoordinator* getTextBlobRedrawCoordinator(); const sktext::gpu::TextBlobRedrawCoordinator* getTextBlobRedrawCoordinator() const; @@ -223,7 +224,8 @@ class GrRecordingContext : public GrImageContext { #if GR_TEST_UTILS void dump(SkString* out) const; - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const; + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const; #endif private: @@ -236,14 +238,16 @@ class GrRecordingContext : public GrImageContext { #if GR_TEST_UTILS void dump(SkString*) const {} - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const {} + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const {} #endif #endif // GR_GPU_STATS } fStats; #if GR_GPU_STATS && GR_TEST_UTILS struct DMSAAStats { - void dumpKeyValuePairs(SkTArray* keys, SkTArray* values) const; + void dumpKeyValuePairs(skia_private::TArray* keys, + skia_private::TArray* values) const; void dump() const; void merge(const DMSAAStats&); int fNumRenderPasses = 0; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h index f8895345d658a..177a35a9437f9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/GrTypes.h @@ -8,13 +8,18 @@ #ifndef GrTypes_DEFINED #define GrTypes_DEFINED -#include "include/core/SkMath.h" #include "include/core/SkTypes.h" -#include "include/gpu/GrConfig.h" +#include "include/private/base/SkTo.h" // IWYU pragma: keep +#include +#include class GrBackendSemaphore; -class SkImage; -class SkSurface; + +namespace skgpu { +enum class Mipmapped : bool; +enum class Protected : bool; +enum class Renderable : bool; +} //////////////////////////////////////////////////////////////////////////////// @@ -122,28 +127,20 @@ static constexpr GrBackendApi kMock_GrBackend = GrBackendApi::kMock; /** * Used to say whether a texture has mip levels allocated or not. */ -enum class GrMipmapped : bool { - kNo = false, - kYes = true -}; -/** Deprecated legacy alias of GrMipmapped. */ -using GrMipMapped = GrMipmapped; +/** Deprecated legacy alias of skgpu::Mipmapped. */ +using GrMipmapped = skgpu::Mipmapped; +/** Deprecated legacy alias of skgpu::Mipmapped. */ +using GrMipMapped = skgpu::Mipmapped; /* * Can a GrBackendObject be rendered to? */ -enum class GrRenderable : bool { - kNo = false, - kYes = true -}; +using GrRenderable = skgpu::Renderable; /* * Used to say whether texture is backed by protected memory. */ -enum class GrProtected : bool { - kNo = false, - kYes = true -}; +using GrProtected = skgpu::Protected; /////////////////////////////////////////////////////////////////////////////// @@ -188,6 +185,9 @@ typedef void (*GrGpuFinishedProc)(GrGpuFinishedContext finishedContext); typedef void* GrGpuSubmittedContext; typedef void (*GrGpuSubmittedProc)(GrGpuSubmittedContext submittedContext, bool success); +typedef void* GrDirectContextDestroyedContext; +typedef void (*GrDirectContextDestroyedProc)(GrDirectContextDestroyedContext destroyedContext); + /** * Struct to supply options to flush calls. * diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h index d2e890f780a1f..b595422e8692a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/d3d/GrD3DTypes.h @@ -22,7 +22,7 @@ // prepared to rename those identifiers. #include "include/core/SkRefCnt.h" -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include #include @@ -184,7 +184,7 @@ struct GrD3DTextureResourceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; unsigned int fSampleQualityPattern = DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrD3DTextureResourceInfo() = default; @@ -195,7 +195,7 @@ struct GrD3DTextureResourceInfo { uint32_t sampleCount, uint32_t levelCount, unsigned int sampleQualityLevel, - GrProtected isProtected = GrProtected::kNo) + skgpu::Protected isProtected = skgpu::Protected::kNo) : fResource(resource) , fAlloc(alloc) , fResourceState(resourceState) @@ -239,7 +239,7 @@ struct GrD3DFenceInfo { struct GrD3DSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; DXGI_FORMAT fFormat = DXGI_FORMAT_UNKNOWN; unsigned int fSampleQualityPattern = DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h index 70a2f9f6d6c5d..fbd3dbaf55cb1 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/dawn/GrDawnTypes.h @@ -8,7 +8,7 @@ #ifndef GrDawnTypes_DEFINED #define GrDawnTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #ifdef Always #undef Always @@ -22,7 +22,7 @@ static constexpr int Success = 0; #undef None static constexpr int None = 0L; #endif -#include "webgpu/webgpu_cpp.h" +#include "webgpu/webgpu_cpp.h" // IWYU pragma: export struct GrDawnTextureInfo { wgpu::Texture fTexture; @@ -87,7 +87,7 @@ struct GrDawnRenderTargetInfo { struct GrDawnSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; wgpu::TextureFormat fFormat; }; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h new file mode 100644 index 0000000000000..68f13ce4b5119 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h @@ -0,0 +1,77 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrTextureGenerator_DEFINED +#define GrTextureGenerator_DEFINED + +#include "include/core/SkImageGenerator.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GrTypes.h" +#include "include/private/base/SkAPI.h" + +#include +#include + +class GrRecordingContext; +class GrSurfaceProxyView; +class SkImage; +enum class GrImageTexGenPolicy : int; +namespace skgpu { enum class Mipmapped : bool; } +struct SkImageInfo; + +class SK_API GrTextureGenerator : public SkImageGenerator { +public: + bool isTextureGenerator() const final { return true; } + + /** + * If the generator can natively/efficiently return its pixels as a GPU image (backed by a + * texture) this will return that image. If not, this will return NULL. + * + * Regarding the GrRecordingContext parameter: + * + * It must be non-NULL. The generator should only succeed if: + * - its internal context is the same + * - it can somehow convert its texture into one that is valid for the provided context. + * + * If the mipmapped parameter is kYes, the generator should try to create a TextureProxy that + * at least has the mip levels allocated and the base layer filled in. If this is not possible, + * the generator is allowed to return a non mipped proxy, but this will have some additional + * overhead in later allocating mips and copying of the base layer. + * + * GrImageTexGenPolicy determines whether or not a new texture must be created (and its budget + * status) or whether this may (but is not required to) return a pre-existing texture that is + * retained by the generator (kDraw). + */ + GrSurfaceProxyView generateTexture(GrRecordingContext*, + const SkImageInfo& info, + skgpu::Mipmapped mipmapped, + GrImageTexGenPolicy); + + virtual GrSurfaceProxyView onGenerateTexture(GrRecordingContext*, const SkImageInfo&, + skgpu::Mipmapped, GrImageTexGenPolicy) = 0; + + // Most internal SkImageGenerators produce textures and views that use kTopLeft_GrSurfaceOrigin. + // If the generator may produce textures with different origins (e.g. + // GrAHardwareBufferImageGenerator) it should override this function to return the correct + // origin. Implementations should be thread-safe. + virtual GrSurfaceOrigin origin() const { return kTopLeft_GrSurfaceOrigin; } + +protected: + GrTextureGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID); +}; + +namespace SkImages { +/** + * Like SkImages::DeferredFromGenerator except allows for the use of SkGaneshTextureGenerator. + * + * @param gen producer of textures + * @return created SkImage, or nullptr + */ +SK_API sk_sp DeferredFromTextureGenerator(std::unique_ptr gen); +} + +#endif // GrTextureGenerator_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h new file mode 100644 index 0000000000000..296d90d17e3f9 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/ganesh/SkImageGanesh.h @@ -0,0 +1,385 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkImageGanesh_DEFINED +#define SkImageGanesh_DEFINED + +#include "include/core/SkImage.h" +#include "include/core/SkRefCnt.h" +#include "include/gpu/GpuTypes.h" +#include "include/gpu/GrTypes.h" +#include "include/private/base/SkAPI.h" + +#include +#include + +class GrBackendFormat; +class GrBackendTexture; +class GrContextThreadSafeProxy; +class GrDirectContext; +class GrRecordingContext; +class GrYUVABackendTextureInfo; +class GrYUVABackendTextures; +class SkColorSpace; +class SkData; +class SkPixmap; +class SkPromiseImageTexture; +class SkYUVAPixmaps; +enum SkAlphaType : int; +enum SkColorType : int; +enum class SkTextureCompressionType; +struct SkISize; + +/** + * All factories in this file refer to the Ganesh GPU backend when they say GPU. + */ + +namespace SkImages { +/** Defines a callback function, taking one parameter of type GrBackendTexture with + no return value. Function is called when backend texture is to be released. +*/ +using BackendTextureReleaseProc = std::function; +/** User function called when supplied texture may be deleted. */ +using TextureReleaseProc = void (*)(ReleaseContext); + +/** Creates GPU-backed SkImage from backendTexture associated with context. + Skia will assume ownership of the resource and will release it when no longer needed. + A non-null SkImage is returned if format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @param context GPU context + @param backendTexture texture residing on GPU + @param textureOrigin origin of backendTexture + @param colorType color type of the resulting image + @param alphaType alpha type of the resulting image + @param colorSpace range of colors; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType); +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType, + SkAlphaType alphaType); +SK_API sk_sp AdoptTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin textureOrigin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace); + +/** Creates GPU-backed SkImage from the provided GPU texture associated with context. + GPU texture must stay valid and unchanged until textureReleaseProc is called by Skia. + Skia will call textureReleaseProc with the passed-in releaseContext when SkImage + is deleted or no longer refers to the texture. + A non-null SkImage is returned if format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @note When using a DDL recording context, textureReleaseProc will be called on the + GPU thread after the DDL is played back on the direct context. + @param context GPU context + @param backendTexture texture residing on GPU + @param colorSpace This describes the color space of this image's contents, as + seen after sampling. In general, if the format of the backend + texture is SRGB, some linear colorSpace should be supplied + (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the + backend texture is linear, then the colorSpace should include + a description of the transfer function as + well (e.g., SkColorSpace::MakeSRGB()). + @param textureReleaseProc function called when texture can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp BorrowTextureFrom(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); + +/** Creates a GPU-backed SkImage from pixmap. It is uploaded to GPU backend using context. + Created SkImage is available to other GPU contexts, and is available across thread + boundaries. All contexts must be in the same GPU share group, or otherwise + share resources. + When SkImage is no longer referenced, context releases texture memory + asynchronously. + SkColorSpace of SkImage is determined by pixmap.colorSpace(). + SkImage is returned referring to GPU backend if context is not nullptr, + format of data is recognized and supported, and if context supports moving + resources between contexts. Otherwise, pixmap pixel data is copied and SkImage + as returned in raster format if possible; nullptr may be returned. + Recognized GPU formats vary by platform and GPU backend. + @param context GPU context + @param pixmap SkImageInfo, pixel address, and row bytes + @param buildMips create SkImage as mip map if true + @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary + @return created SkImage, or nullptr +*/ +SK_API sk_sp CrossContextTextureFromPixmap(GrDirectContext* context, + const SkPixmap& pixmap, + bool buildMips, + bool limitToMaxTextureSize = false); + +/** Creates a GPU-backed SkImage from a GPU backend texture. The backend texture must stay + valid and unchanged until textureReleaseProc is called. The textureReleaseProc is + called when the SkImage is deleted or no longer refers to the texture and will be + passed the releaseContext. + An SkImage is returned if the format of backendTexture is recognized and supported. + Recognized formats vary by GPU backend. + @note When using a DDL recording context, textureReleaseProc will be called on the + GPU thread after the DDL is played back on the direct context. + @param context the GPU context + @param backendTexture a texture already allocated by the GPU + @param alphaType This characterizes the nature of the alpha values in the + backend texture. For opaque compressed formats (e.g., ETC1) + this should usually be set to kOpaq + ue_SkAlphaType. + @param colorSpace This describes the color space of this image's contents, as + seen after sampling. In general, if the format of the backend + texture is SRGB, some linear colorSpace should be supplied + (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the + backend texture is linear, then the colorSpace should include + a description of the transfer function as + well (e.g., SkColorSpace::MakeSRGB()). + @param textureReleaseProc function called when the backend texture can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromCompressedTexture(GrRecordingContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, + SkAlphaType alphaType, + sk_sp colorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); + +/** Creates a GPU-backed SkImage from compressed data. + This method will return an SkImage representing the compressed data. + If the GPU doesn't support the specified compression method, the data + will be decompressed and then wrapped in a GPU-backed image. + Note: one can query the supported compression formats via + GrRecordingContext::compressedBackendFormat. + @param context GPU context + @param data compressed data to store in SkImage + @param width width of full SkImage + @param height height of full SkImage + @param type type of compression used + @param mipmapped does 'data' contain data for all the mipmap levels? + @param isProtected do the contents of 'data' require DRM protection (on Vulkan)? + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromCompressedTextureData(GrDirectContext* direct, + sk_sp data, + int width, + int height, + SkTextureCompressionType type, + GrMipmapped mipmapped = GrMipmapped::kNo, + GrProtected isProtected = GrProtected::kNo); + +/** Returns SkImage backed by GPU texture associated with context. Returned SkImage is + compatible with SkSurface created with dstColorSpace. The returned SkImage respects + mipmapped setting; if mipmapped equals skgpu::Mipmapped::kYes, the backing texture + allocates mip map levels. + The mipmapped parameter is effectively treated as kNo if MIP maps are not supported by the + GPU. + Returns original SkImage if the image is already texture-backed, the context matches, and + mipmapped is compatible with the backing GPU texture. skgpu::Budgeted is ignored in this + case. + Returns nullptr if context is nullptr, or if SkImage was created with another + GrDirectContext. + @param GrDirectContext the GrDirectContext in play, if it exists + @param SkImage a non-null pointer to an SkImage. + @param skgpu::Mipmapped Whether created SkImage texture must allocate mip map levels. + Defaults to no. + @param skgpu::Budgeted Whether to count a newly created texture for the returned image + counts against the context's budget. Defaults to yes. + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromImage(GrDirectContext*, + const SkImage*, + skgpu::Mipmapped = skgpu::Mipmapped::kNo, + skgpu::Budgeted = skgpu::Budgeted::kYes); +inline sk_sp TextureFromImage(GrDirectContext* ctx, + sk_sp img, + skgpu::Mipmapped m = skgpu::Mipmapped::kNo, + skgpu::Budgeted b = skgpu::Budgeted::kYes) { + return TextureFromImage(ctx, img.get(), m, b); +} + +/** Creates a GPU-backed SkImage from SkYUVAPixmaps. + The image will remain planar with each plane converted to a texture using the passed + GrRecordingContext. + SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. + The SkColorSpace of the resulting RGB values is specified by imageColorSpace. This will + be the SkColorSpace reported by the image and when drawn the RGB values will be converted + from this space into the destination space (if the destination is tagged). + Currently, this is only supported using the GPU backend and will fail if context is nullptr. + SkYUVAPixmaps does not need to remain valid after this returns. + @param context GPU context + @param pixmaps The planes as pixmaps with supported SkYUVAInfo that + specifies conversion to RGB. + @param buildMips create internal YUVA textures as mip map if kYes. This is + silently ignored if the context does not support mip maps. + @param limitToMaxTextureSize downscale image to GPU maximum texture size, if necessary + @param imageColorSpace range of colors of the resulting image; may be nullptr + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromYUVAPixmaps(GrRecordingContext* context, + const SkYUVAPixmaps& pixmaps, + GrMipmapped buildMips, + bool limitToMaxTextureSize, + sk_sp imageColorSpace); +SK_API sk_sp TextureFromYUVAPixmaps(GrRecordingContext* context, + const SkYUVAPixmaps& pixmaps, + GrMipmapped buildMips = GrMipmapped::kNo, + bool limitToMaxTextureSize = false); + +/** Creates a GPU-backed SkImage from YUV[A] planar textures. This requires that the textures + * stay valid for the lifetime of the image. The ReleaseContext can be used to know when it is + * safe to either delete or overwrite the textures. If ReleaseProc is provided it is also called + * before return on failure. + @param context GPU context + @param yuvaTextures A set of textures containing YUVA data and a description of the + data and transformation to RGBA. + @param imageColorSpace range of colors of the resulting image after conversion to RGB; + may be nullptr + @param textureReleaseProc called when the backend textures can be released + @param releaseContext state passed to textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp TextureFromYUVATextures(GrRecordingContext* context, + const GrYUVABackendTextures& yuvaTextures, + sk_sp imageColorSpace, + TextureReleaseProc textureReleaseProc = nullptr, + ReleaseContext releaseContext = nullptr); +SK_API sk_sp TextureFromYUVATextures(GrRecordingContext* context, + const GrYUVABackendTextures& yuvaTextures); + +using PromiseImageTextureContext = void*; +using PromiseImageTextureFulfillProc = sk_sp (*)(PromiseImageTextureContext); +using PromiseImageTextureReleaseProc = void (*)(PromiseImageTextureContext); + +/** Create a new GPU-backed SkImage that is very similar to an SkImage created by BorrowTextureFrom. + The difference is that the caller need not have created the texture nor populated it with the + image pixel data. Moreover, the SkImage may be created on a thread as the creation of the + image does not require access to the backend API or GrDirectContext. Instead of passing a + GrBackendTexture the client supplies a description of the texture consisting of + GrBackendFormat, width, height, and GrMipmapped state. The resulting SkImage can be drawn + to a SkDeferredDisplayListRecorder or directly to a GPU-backed SkSurface. + When the actual texture is required to perform a backend API draw, textureFulfillProc will + be called to receive a GrBackendTexture. The properties of the GrBackendTexture must match + those set during the SkImage creation, and it must refer to a valid existing texture in the + backend API context/device, and be populated with the image pixel data. The texture cannot + be deleted until textureReleaseProc is called. + There is at most one call to each of textureFulfillProc and textureReleaseProc. + textureReleaseProc is always called even if image creation fails or if the + image is never fulfilled (e.g. it is never drawn or all draws are clipped out) + @param gpuContextProxy the thread-safe proxy of the gpu context. required. + @param backendFormat format of promised gpu texture + @param dimensions width & height of promised gpu texture + @param mipmapped mip mapped state of promised gpu texture + @param origin surface origin of promised gpu texture + @param colorType color type of promised gpu texture + @param alphaType alpha type of promised gpu texture + @param colorSpace range of colors; may be nullptr + @param textureFulfillProc function called to get actual gpu texture + @param textureReleaseProc function called when texture can be deleted + @param textureContext state passed to textureFulfillProc and textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp PromiseTextureFrom(sk_sp gpuContextProxy, + const GrBackendFormat& backendFormat, + SkISize dimensions, + GrMipmapped mipmapped, + GrSurfaceOrigin origin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace, + PromiseImageTextureFulfillProc textureFulfillProc, + PromiseImageTextureReleaseProc textureReleaseProc, + PromiseImageTextureContext textureContext); + +/** This is similar to 'PromiseTextureFrom' but it creates a GPU-backed SkImage from YUV[A] data. + The source data may be planar (i.e. spread across multiple textures). In + the extreme Y, U, V, and A are all in different planes and thus the image is specified by + four textures. 'backendTextureInfo' describes the planar arrangement, texture formats, + conversion to RGB, and origin of the textures. Separate 'textureFulfillProc' and + 'textureReleaseProc' calls are made for each texture. Each texture has its own + PromiseImageTextureContext. If 'backendTextureInfo' is not valid then no release proc + calls are made. Otherwise, the calls will be made even on failure. 'textureContexts' has one + entry for each of the up to four textures, as indicated by 'backendTextureInfo'. + Currently the mip mapped property of 'backendTextureInfo' is ignored. However, in the + near future it will be required that if it is kYes then textureFulfillProc must return + a mip mapped texture for each plane in order to successfully draw the image. + @param gpuContextProxy the thread-safe proxy of the gpu context. required. + @param backendTextureInfo info about the promised yuva gpu texture + @param imageColorSpace range of colors; may be nullptr + @param textureFulfillProc function called to get actual gpu texture + @param textureReleaseProc function called when texture can be deleted + @param textureContexts state passed to textureFulfillProc and textureReleaseProc + @return created SkImage, or nullptr +*/ +SK_API sk_sp PromiseTextureFromYUVA(sk_sp gpuContextProxy, + const GrYUVABackendTextureInfo& backendTextureInfo, + sk_sp imageColorSpace, + PromiseImageTextureFulfillProc textureFulfillProc, + PromiseImageTextureReleaseProc textureReleaseProc, + PromiseImageTextureContext textureContexts[]); + +/** Retrieves the existing backend texture. If SkImage is not a Ganesh-backend texture image + or otherwise does not have such a texture, false is returned. Otherwise, outTexture will + be set to the image's texture. + + If flushPendingGrContextIO is true, completes deferred I/O operations. + If origin in not nullptr, copies location of content drawn into SkImage. + @param outTexture Will be set to the underlying texture of the image if non-null. + @param flushPendingGrContextIO flag to flush outstanding requests + @param origin Will be set to the origin orientation of the image if non-null. + @return false if a Ganesh backend texture cannot be retrieved. +*/ +SK_API bool GetBackendTextureFromImage(const SkImage* img, + GrBackendTexture* outTexture, + bool flushPendingGrContextIO, + GrSurfaceOrigin* origin = nullptr); +inline bool GetBackendTextureFromImage(sk_sp img, + GrBackendTexture* outTexture, + bool flushPendingGrContextIO, + GrSurfaceOrigin* origin = nullptr) { + return GetBackendTextureFromImage(img.get(), outTexture, flushPendingGrContextIO, origin); +} + +/** Extracts the backendTexture from an existing SkImage. + If the image is not already GPU-backed, the raster data will be uploaded as a texture + and returned. + If this is the only reference to the image, the old image's texture will be + moved out of the passed in image. + If the image is shared (has a refcount > 1), the texture will be copied and then returned. + @param context GPU context + @param image image, either CPU-backed or GPU-backed + @param backendTexture Will be set to the underlying texture of the image. + @param backendTextureReleaseProc Called when the texture is released + @return false if image cannot be uploaded. +*/ +SK_API bool MakeBackendTextureFromImage(GrDirectContext* context, + sk_sp image, + GrBackendTexture* backendTexture, + BackendTextureReleaseProc* backendTextureReleaseProc); +// Legacy name +inline bool GetBackendTextureFromImage(GrDirectContext* context, + sk_sp image, + GrBackendTexture* backendTexture, + BackendTextureReleaseProc* backendTextureReleaseProc) { + return MakeBackendTextureFromImage(context, std::move(image), backendTexture, + backendTextureReleaseProc); +} + +} // namespace SkImages + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h index 1e2823f71a95b..0ae85f07a0349 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLExtensions.h @@ -10,7 +10,7 @@ #include "include/core/SkString.h" #include "include/gpu/gl/GrGLFunctions.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include @@ -66,13 +66,13 @@ class SK_API GrGLExtensions { */ void add(const char[]); - void reset() { fStrings.reset(); } + void reset() { fStrings.clear(); } void dumpJSON(SkJSONWriter*) const; private: bool fInitialized = false; - SkTArray fStrings; + skia_private::TArray fStrings; }; #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h index 59b9cd9e18d55..4e488abcad432 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLFunctions.h @@ -11,7 +11,7 @@ #include #include "include/gpu/gl/GrGLTypes.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkTLogic.h" extern "C" { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h index 5d6e3bb2d5f3d..64ca419b9b16a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLInterface.h @@ -304,9 +304,6 @@ struct SK_API GrGLInterface : public SkRefCnt { GrGLFunction fVertexAttribPointer; GrGLFunction fViewport; - /* NV_framebuffer_mixed_samples */ - GrGLFunction fCoverageModulation; - /* ARB_sync */ GrGLFunction fFenceSync; GrGLFunction fIsSync; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h index d5167787c1e05..3af4802eaacc2 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/gl/GrGLTypes.h @@ -10,6 +10,7 @@ #define GrGLTypes_DEFINED #include "include/core/SkRefCnt.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/gl/GrGLConfig.h" /** @@ -198,7 +199,7 @@ struct GrGLFramebufferInfo { struct GrGLSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrGLenum fTarget = 0; GrGLenum fFormat = 0; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h index f12d22ebb4f04..82a662ab13fdf 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/BackendTexture.h @@ -8,29 +8,71 @@ #ifndef skgpu_graphite_BackendTexture_DEFINED #define skgpu_graphite_BackendTexture_DEFINED +#include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/graphite/TextureInfo.h" +#ifdef SK_DAWN +#include "include/gpu/graphite/dawn/DawnTypes.h" +#endif + #ifdef SK_METAL -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" #endif #ifdef SK_VULKAN #include "include/private/gpu/vk/SkiaVulkan.h" #endif +namespace skgpu { +class MutableTextureState; +class MutableTextureStateRef; +} + namespace skgpu::graphite { -class BackendTexture { +class SK_API BackendTexture { public: - BackendTexture() {} + BackendTexture(); +#ifdef SK_DAWN + // Create a BackendTexture from a WGPUTexture. Texture info will be + // queried from the texture. Comparing to WGPUTextureView, + // SkImage::readPixels(), SkSurface::readPixels() and + // SkSurface::writePixels() are implemented by direct buffer copy. They + // should be more efficient. For WGPUTextureView, those methods will use + // create an intermediate WGPUTexture, and use it to transfer pixels. + // Note: + // - for better performance, using WGPUTexture IS RECOMMENDED. + // - The BackendTexture will not call retain or release on the passed in + // WGPUTexture. Thus the client must keep the WGPUTexture valid until + // they are no longer using the BackendTexture. + BackendTexture(WGPUTexture texture); + // Create a BackendTexture from a WGPUTextureView. Texture dimensions and + // info have to be provided. + // Note: + // - this method is for importing WGPUTextureView from wgpu::SwapChain only. + // - The BackendTexture will not call retain or release on the passed in + // WGPUTextureView. Thus the client must keep the WGPUTextureView valid + // until they are no longer using the BackendTexture. + BackendTexture(SkISize dimensions, + const DawnTextureInfo& info, + WGPUTextureView textureView); +#endif #ifdef SK_METAL // The BackendTexture will not call retain or release on the passed in MtlHandle. Thus the // client must keep the MtlHandle valid until they are no longer using the BackendTexture. BackendTexture(SkISize dimensions, MtlHandle mtlTexture); #endif +#ifdef SK_VULKAN + BackendTexture(SkISize dimensions, + const VulkanTextureInfo&, + VkImageLayout, + uint32_t queueFamilyIndex, + VkImage); +#endif + BackendTexture(const BackendTexture&); ~BackendTexture(); @@ -47,15 +89,42 @@ class BackendTexture { const TextureInfo& info() const { return fInfo; } + // If the client changes any of the mutable backend of the GrBackendTexture they should call + // this function to inform Skia that those values have changed. The backend API specific state + // that can be set from this function are: + // + // Vulkan: VkImageLayout and QueueFamilyIndex + void setMutableState(const skgpu::MutableTextureState&); + +#ifdef SK_DAWN + WGPUTexture getDawnTexturePtr() const; + WGPUTextureView getDawnTextureViewPtr() const; +#endif #ifdef SK_METAL MtlHandle getMtlTexture() const; #endif +#ifdef SK_VULKAN + VkImage getVkImage() const; + VkImageLayout getVkImageLayout() const; + uint32_t getVkQueueFamilyIndex() const; +#endif + private: + sk_sp mutableState() const; + SkISize fDimensions; TextureInfo fInfo; + sk_sp fMutableState; + union { +#ifdef SK_DAWN + struct { + WGPUTexture fDawnTexture; + WGPUTextureView fDawnTextureView; + }; +#endif #ifdef SK_METAL MtlHandle fMtlTexture; #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h deleted file mode 100644 index a0c977b283bf5..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/CombinationBuilder.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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 skgpu_graphite_CombinationBuilder_DEFINED -#define skgpu_graphite_CombinationBuilder_DEFINED - -#include "include/core/SkTypes.h" - -#ifdef SK_ENABLE_PRECOMPILE - -#include -#include -#include -#include "include/core/SkBlendMode.h" -#include "include/core/SkSpan.h" -#include "include/core/SkTileMode.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTHash.h" - -class SkArenaAllocWithReset; -class SkKeyContext; -class SkPaintParamsKeyBuilder; -class SkShaderCodeDictionary; -class SkUniquePaintParamsID; - -namespace skgpu::graphite { - -class CombinationBuilder; -class CombinationBuilderTestAccess; -class Context; -class Option; - -enum class ShaderType : uint32_t { - kSolidColor, - - kLinearGradient, - kRadialGradient, - kSweepGradient, - kConicalGradient, - - kLocalMatrix, - kImage, - kPorterDuffBlendShader, - kBlendShader, - - kLast = kBlendShader -}; - -static constexpr int kShaderTypeCount = static_cast(ShaderType::kLast) + 1; - -struct TileModePair { - SkTileMode fX; - SkTileMode fY; - - bool operator==(const TileModePair& other) const { return fX == other.fX && fY == other.fY; } - bool operator!=(const TileModePair& other) const { return !(*this == other); } -}; - -// TODO: add ShaderID and ColorFilterID too -class BlenderID { -public: - BlenderID() : fID(0) {} // 0 is an invalid blender ID - BlenderID(const BlenderID& src) : fID(src.fID) {} - - bool isValid() const { return fID > 0; } - - bool operator==(const BlenderID& other) const { return fID == other.fID; } - - BlenderID& operator=(const BlenderID& src) { - fID = src.fID; - return *this; - } - -private: - friend class ::SkShaderCodeDictionary; // for ctor and asUInt access - friend class CombinationBuilder; // for asUInt access - - BlenderID(uint32_t id) : fID(id) {} - - uint32_t asUInt() const { return fID; } - - uint32_t fID; -}; - -// When combination options are added to the combination builder an CombinationOption -// object is frequently returned. This allows options to be added, recursively, to the -// previously added options. -// Note: CombinationOptions are stable memory-wise so, once returned, they are valid -// until CombinationBuilder::reset is called. -class CombinationOption { -public: - CombinationOption addChildOption(int childIndex, ShaderType); - - CombinationOption addChildOption(int childIndex, ShaderType, - int minNumStops, int maxNumStops); - - CombinationOption addChildOption(int childIndex, ShaderType, - SkSpan tileModes); - - bool isValid() const { return fDataInArena; } - -private: - friend class CombinationBuilder; // for ctor - friend class CombinationBuilderTestAccess; - - CombinationOption(CombinationBuilder* builder, Option* dataInArena) - : fBuilder(builder) - , fDataInArena(dataInArena) {} - - ShaderType type() const; - int numChildSlots() const; - SkDEBUGCODE(int epoch() const;) - - CombinationBuilder* fBuilder; - Option* fDataInArena; -}; - -class CombinationBuilder { -public: - enum class BlendModeGroup { - kPorterDuff, // [ kClear .. kScreen ] - kAdvanced, // [ kOverlay .. kMultiply ] - kColorAware, // [ kHue .. kLuminosity ] - kAll - }; - - CombinationBuilder(SkShaderCodeDictionary*); - ~CombinationBuilder(); - - // Blend Modes - void addOption(SkBlendMode); - void addOption(SkBlendMode rangeStart, SkBlendMode rangeEnd); // inclusive - void addOption(BlendModeGroup); - - // TODO: have this variant return an CombinationOption object - void addOption(BlenderID); - - // Shaders - CombinationOption addOption(ShaderType); - CombinationOption addOption(ShaderType, int minNumStops, int maxNumStops); // inclusive - CombinationOption addOption(ShaderType, SkSpan tileModes); - - void reset(); - -private: - friend class Context; // for access to 'buildCombinations' - friend class CombinationOption; // for 'addOptionInternal' and 'arena' - friend class CombinationBuilderTestAccess; // for 'num*Combinations' and 'epoch' - - int numShaderCombinations() const; - int numBlendModeCombinations() const; - int numCombinations() { - return this->numShaderCombinations() * this->numBlendModeCombinations(); - } - - // 'desiredCombination' must be less than numCombinations - void createKey(const SkKeyContext&, int desiredCombination, SkPaintParamsKeyBuilder*); - -#ifdef SK_DEBUG - void dump() const; - int epoch() const { return fEpoch; } -#endif - - SkArenaAllocWithReset* arena() { return fArena.get(); } - - template - Option* allocInArena(Args&&... args); - - Option* addOptionInternal(ShaderType); - Option* addOptionInternal(ShaderType, int minNumStops, int maxNumStops); - Option* addOptionInternal(ShaderType, SkSpan tileModes); - - void buildCombinations(SkShaderCodeDictionary*, - const std::function&); - - SkShaderCodeDictionary* fDictionary; - std::unique_ptr fArena; - SkTArray fShaderOptions; - - uint32_t fBlendModes; - // TODO: store the SkBlender-based blenders in the arena - SkTHashSet fBlenders; - - SkDEBUGCODE(int fEpoch = 0;) -}; - -} // namespace skgpu::graphite - -#endif // SK_ENABLE_PRECOMPILE - -#endif // skgpu_graphite_CombinationBuilder_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h index c5ff91e6cb7e0..0fb6eee418687 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Context.h @@ -8,36 +8,34 @@ #ifndef skgpu_graphite_Context_DEFINED #define skgpu_graphite_Context_DEFINED +#include "include/core/SkImage.h" #include "include/core/SkRefCnt.h" #include "include/core/SkShader.h" #include "include/gpu/graphite/ContextOptions.h" #include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/graphite/Recorder.h" -#include "include/private/SingleOwner.h" +#include "include/private/base/SingleOwner.h" +#include #include class SkRuntimeEffect; -namespace skgpu { struct VulkanBackendContext; } - namespace skgpu::graphite { class BackendTexture; +class Buffer; +class ClientMappedBufferManager; class Context; class ContextPriv; -struct DawnBackendContext; class GlobalCache; -struct MtlBackendContext; +class PaintOptions; +class PlotUploadTracker; class QueueManager; class Recording; class ResourceProvider; class SharedContext; - -#ifdef SK_ENABLE_PRECOMPILE -class BlenderID; -class CombinationBuilder; -#endif +class TextureProxy; class SK_API Context final { public: @@ -48,37 +46,30 @@ class SK_API Context final { ~Context(); -#ifdef SK_DAWN - static std::unique_ptr MakeDawn(const DawnBackendContext&, const ContextOptions&); -#endif -#ifdef SK_METAL - static std::unique_ptr MakeMetal(const MtlBackendContext&, const ContextOptions&); -#endif - -#ifdef SK_VULKAN - static std::unique_ptr MakeVulkan(const VulkanBackendContext&, const ContextOptions&); -#endif - BackendApi backend() const; std::unique_ptr makeRecorder(const RecorderOptions& = {}); - void insertRecording(const InsertRecordingInfo&); - void submit(SyncToCpu = SyncToCpu::kNo); + bool insertRecording(const InsertRecordingInfo&); + bool submit(SyncToCpu = SyncToCpu::kNo); + + void asyncReadPixels(const SkImage* image, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); + + void asyncReadPixels(const SkSurface* surface, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); /** * Checks whether any asynchronous work is complete and if so calls related callbacks. */ void checkAsyncWorkCompletion(); -#ifdef SK_ENABLE_PRECOMPILE - // TODO: add "ShaderID addUserDefinedShader(sk_sp)" here - // TODO: add "ColorFilterID addUserDefinedColorFilter(sk_sp)" here - BlenderID addUserDefinedBlender(sk_sp); - - void precompile(CombinationBuilder*); -#endif - /** * Called to delete the passed in BackendTexture. This should only be called if the * BackendTexture was created by calling Recorder::createBackendTexture on a Recorder created @@ -94,21 +85,83 @@ class SK_API Context final { ContextPriv priv(); const ContextPriv priv() const; // NOLINT(readability-const-return-type) + class ContextID { + public: + static Context::ContextID Next(); + + ContextID() : fID(SK_InvalidUniqueID) {} + + bool operator==(const ContextID& that) const { return fID == that.fID; } + bool operator!=(const ContextID& that) const { return !(*this == that); } + + void makeInvalid() { fID = SK_InvalidUniqueID; } + bool isValid() const { return fID != SK_InvalidUniqueID; } + + private: + constexpr ContextID(uint32_t id) : fID(id) {} + uint32_t fID; + }; + + ContextID contextID() const { return fContextID; } + protected: - Context(sk_sp, std::unique_ptr); + Context(sk_sp, std::unique_ptr, const ContextOptions&); private: friend class ContextPriv; + friend class ContextCtorAccessor; SingleOwner* singleOwner() const { return &fSingleOwner; } + // Must be called in Make() to handle one-time GPU setup operations that can possibly fail and + // require Context::Make() to return a nullptr. + bool finishInitialization(); + + void asyncReadPixels(const TextureProxy* textureProxy, + const SkImageInfo& srcImageInfo, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect, + SkImage::ReadPixelsCallback callback, + SkImage::ReadPixelsContext context); + + // Inserts a texture to buffer transfer task, used by asyncReadPixels methods + struct PixelTransferResult { + using ConversionFn = void(void* dst, const void* mappedBuffer); + // If null then the transfer could not be performed. Otherwise this buffer will contain + // the pixel data when the transfer is complete. + sk_sp fTransferBuffer; + // RowBytes for transfer buffer data + size_t fRowBytes; + // If this is null then the transfer buffer will contain the data in the requested + // color type. Otherwise, when the transfer is done this must be called to convert + // from the transfer buffer's color type to the requested color type. + std::function fPixelConverter; + }; + PixelTransferResult transferPixels(const TextureProxy*, + const SkImageInfo& srcImageInfo, + const SkColorInfo& dstColorInfo, + const SkIRect& srcRect); + sk_sp fSharedContext; std::unique_ptr fResourceProvider; std::unique_ptr fQueueManager; + std::unique_ptr fMappedBufferManager; + std::unique_ptr fPlotUploadTracker; // In debug builds we guard against improper thread handling. This guard is passed to the // ResourceCache for the Context. mutable SingleOwner fSingleOwner; + +#if GRAPHITE_TEST_UTILS + // In test builds a Recorder may track the Context that was used to create it. + bool fStoreContextRefInRecorder = false; + // If this tracking is on, to allow the client to safely delete this Context or its Recorders + // in any order we must also track the Recorders created here. + std::vector fTrackedRecorders; +#endif + + // Needed for MessageBox handling + const ContextID fContextID; }; } // namespace skgpu::graphite diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h index d55351a774c1d..b9ac1b09d1619 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ContextOptions.h @@ -8,6 +8,8 @@ #ifndef skgpu_graphite_ContextOptions_DEFINED #define skgpu_graphite_ContextOptions_DEFINED +#include "include/private/base/SkAPI.h" + namespace skgpu { class ShaderErrorHandler; } namespace skgpu::graphite { @@ -15,6 +17,13 @@ namespace skgpu::graphite { struct SK_API ContextOptions { ContextOptions() {} + /** + * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. + * This does not affect code path choices that are made for perfomance reasons nor does it + * override other ContextOption settings. + */ + bool fDisableDriverCorrectnessWorkarounds = false; + /** * If present, use this object to report shader compilation failures. If not, report failures * via SkDebugf and assert. @@ -55,18 +64,7 @@ struct SK_API ContextOptions { * fGlypheCacheTextureMaximumBytes. */ bool fAllowMultipleGlyphCacheTextures = true; - - /** - * If true, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp - * rendering of all glyphs. This must be set to true to use Slugs. - */ - #if defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE) || \ - defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_STRIKE_SERIALIZE) - bool fSupportBilerpFromGlyphAtlas = true; - #else bool fSupportBilerpFromGlyphAtlas = false; - #endif #if GRAPHITE_TEST_UTILS /** @@ -77,6 +75,12 @@ struct SK_API ContextOptions { * Maximum width and height of internal texture atlases. */ int fMaxTextureAtlasSize = 2048; + + /** + * If true, will store a pointer in Recorder that points back to the Context + * that created it. Used by readPixels() and other methods that normally require a Context. + */ + bool fStoreContextRefInRecorder = false; #endif }; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h index 474e5089fcf2a..231f2a5e1454d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/GraphiteTypes.h @@ -8,14 +8,18 @@ #ifndef skgpu_graphite_GraphiteTypes_DEFINED #define skgpu_graphite_GraphiteTypes_DEFINED +#include "include/core/SkPoint.h" #include "include/core/SkTypes.h" #include "include/gpu/GpuTypes.h" #include +class SkSurface; + namespace skgpu::graphite { class Recording; +class Task; using GpuFinishedContext = void*; using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackResult); @@ -27,9 +31,33 @@ using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackRes * the Recording that they may be holding onto. If the Recording is successfully submitted to the * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All * other cases where some failure occured it will be called with CallbackResult::kFailed. + * + * The fTargetSurface, if provided, is used as a target for any draws recorded onto a deferred + * canvas returned from Recorder::makeDeferredCanvas. This target surface must be provided iff + * the Recording contains any such draws. It must be Graphite-backed and its backing texture's + * TextureInfo must match the info provided to the Recorder when making the deferred canvas. + * + * fTargetTranslation is an additional translation applied to draws targeting fTargetSurface. */ struct InsertRecordingInfo { Recording* fRecording = nullptr; + + SkSurface* fTargetSurface = nullptr; + SkIVector fTargetTranslation = {0, 0}; + + GpuFinishedContext fFinishedContext = nullptr; + GpuFinishedProc fFinishedProc = nullptr; +}; + +/** + * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or + * when there is a failure that caused it not to be submitted. The callback will always be called + * and the caller can use the callback to know it is safe to free any resources associated with + * the Recording that they may be holding onto. If the Recording is successfully submitted to the + * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All + * other cases where some failure occured it will be called with CallbackResult::kFailed. + */ +struct InsertFinishInfo { GpuFinishedContext fFinishedContext = nullptr; GpuFinishedProc fFinishedProc = nullptr; }; @@ -42,12 +70,34 @@ enum class SyncToCpu : bool { kNo = false }; -/** - * Is the texture mipmapped or not +/* + * For Promise Images - should the Promise Image be fulfilled every time a Recording that references + * it is inserted into the Context. */ -enum class Mipmapped : bool { - kNo = false, - kYes = true, +enum class Volatile : bool { + kNo = false, // only fulfilled once + kYes = true // fulfilled on every insertion call +}; + +/* + * Graphite's different rendering methods each only apply to certain types of draws. This + * enum supports decision-making regarding the different renderers and what is being drawn. + */ +enum DrawTypeFlags : uint8_t { + + kNone = 0b000, + + // SkCanvas:: drawSimpleText, drawString, drawGlyphs, drawTextBlob, drawSlug + kText = 0b001, + + // SkCanvas::drawVertices + kDrawVertices = 0b010, + + // All other canvas draw calls + kShape = 0b100, + + kMostCommon = kText | kShape, + kAll = kText | kDrawVertices | kShape }; } // namespace skgpu::graphite diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h index 748b678c5ffa9..3c071fe9ea3e7 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/ImageProvider.h @@ -13,7 +13,6 @@ namespace skgpu::graphite { -enum class Mipmapped : bool; class Recorder; /* @@ -23,9 +22,12 @@ class Recorder; * return a Graphite-backed version of the provided SkImage that meets the specified * requirements. * - * Skia requires that 'findOrCreate' return a Graphite-backed image that preserves the dimensions, - * number of channels and alpha type of the original image. The bit depth of the - * individual channels can change (e.g., 4444 -> 8888 is allowed). + * Skia requires that 'findOrCreate' return a Graphite-backed image that preserves the + * dimensions and alpha type of the original image. The bit depth of the + * individual channels can change (e.g., 4444 -> 8888 is allowed) as well as the channels - as + * long as the returned image has a superset of the original image's channels + * (e.g., 565 -> 8888 opaque is allowed). + * * Wrt mipmapping, the returned image can have different mipmap settings than requested. If * mipmapping was requested but not returned, the sampling level will be reduced to linear. * If the requirements are not met by the returned image (modulo the flexibility wrt mipmapping) diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h index 82cbd0f1698cf..6e911a4e72c72 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recorder.h @@ -11,17 +11,20 @@ #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" #include "include/gpu/graphite/GraphiteTypes.h" -#include "include/private/SingleOwner.h" -#include "include/private/SkTHash.h" +#include "include/gpu/graphite/Recording.h" +#include "include/private/base/SingleOwner.h" +#include "include/private/base/SkTArray.h" #include +class SkCanvas; +struct SkImageInfo; class SkPixmap; -class SkRuntimeEffectDictionary; -class SkTextureDataBlock; -class SkUniformDataBlock; -namespace skgpu { class TokenTracker; } +namespace skgpu { +class RefCntedCallback; +class TokenTracker; +} namespace sktext::gpu { class StrikeCache; @@ -33,22 +36,26 @@ namespace skgpu::graphite { class AtlasManager; class BackendTexture; class Caps; +class Context; class Device; class DrawBufferManager; class GlobalCache; class ImageProvider; +class ProxyCache; class RecorderPriv; -class Recording; class ResourceProvider; +class RuntimeEffectDictionary; class SharedContext; class Task; class TaskGraph; +class TextureDataBlock; class TextureInfo; +class UniformDataBlock; class UploadBufferManager; template class PipelineDataCache; -using UniformDataCache = PipelineDataCache; -using TextureDataCache = PipelineDataCache; +using UniformDataCache = PipelineDataCache; +using TextureDataCache = PipelineDataCache; struct SK_API RecorderOptions final { RecorderOptions(); @@ -115,11 +122,23 @@ class SK_API Recorder final { */ void deleteBackendTexture(BackendTexture&); + // Adds a proc that will be moved to the Recording upon snap, subsequently attached to the + // CommandBuffer when the Recording is added, and called when that CommandBuffer is submitted + // and finishes. If the Recorder or Recording is deleted before the proc is added to the + // CommandBuffer, it will be called with result Failure. + void addFinishInfo(const InsertFinishInfo&); + + // Returns a canvas that will record to a proxy surface, which must be instantiated on replay. + // This can only be called once per Recording; subsequent calls will return null until a + // Recording is snapped. Additionally, the returned SkCanvas is only valid until the next + // Recording snap, at which point it is deleted. + SkCanvas* makeDeferredCanvas(const SkImageInfo&, const TextureInfo&); + // Provides access to functions that aren't part of the public API. RecorderPriv priv(); const RecorderPriv priv() const; // NOLINT(readability-const-return-type) -#if GR_TEST_UTILS +#if GRAPHITE_TEST_UTILS bool deviceIsRegistered(Device*); #endif @@ -156,7 +175,7 @@ class SK_API Recorder final { sk_sp fSharedContext; std::unique_ptr fResourceProvider; - std::unique_ptr fRuntimeEffectDict; + std::unique_ptr fRuntimeEffectDict; std::unique_ptr fGraph; std::unique_ptr fUniformDataCache; @@ -176,6 +195,17 @@ class SK_API Recorder final { // This guard is passed to the ResourceCache. // TODO: Should we also pass this to Device, DrawContext, and similar classes? mutable SingleOwner fSingleOwner; + + sk_sp fTargetProxyDevice; + std::unique_ptr fTargetProxyCanvas; + std::unique_ptr fTargetProxyData; + + skia_private::TArray> fFinishedProcs; + +#if GRAPHITE_TEST_UTILS + // For testing use only -- the Context used to create this Recorder + Context* fContext = nullptr; +#endif }; } // namespace skgpu::graphite diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h index b1cb770bf0667..4a60e5b936626 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/Recording.h @@ -9,10 +9,17 @@ #define skgpu_graphite_Recording_DEFINED #include "include/core/SkRefCnt.h" +#include "include/private/SkChecksum.h" +#include "include/private/base/SkTArray.h" #include +#include #include +namespace skgpu { +class RefCntedCallback; +} + namespace skgpu::graphite { class CommandBuffer; @@ -20,18 +27,51 @@ class RecordingPriv; class Resource; class ResourceProvider; class TaskGraph; +class Texture; +class TextureInfo; +class TextureProxy; -class Recording final { +class SK_API Recording final { public: ~Recording(); RecordingPriv priv(); +#if GRAPHITE_TEST_UTILS + bool isTargetProxyInstantiated() const; +#endif + private: - friend class Recorder; // for ctor + friend class Recorder; // for ctor and LazyProxyData friend class RecordingPriv; - Recording(std::unique_ptr); + // LazyProxyData is used if this recording should be replayed to a target that is provided on + // replay, and it handles the target proxy's instantiation with the provided target. + class LazyProxyData { + public: + LazyProxyData(const TextureInfo&); + + TextureProxy* lazyProxy(); + sk_sp refLazyProxy(); + + bool lazyInstantiate(ResourceProvider*, sk_sp); + + private: + sk_sp fTarget; + sk_sp fTargetProxy; + }; + + struct ProxyHash { + std::size_t operator()(const sk_sp& proxy) const { + return SkGoodHash()(proxy.get()); + } + }; + + Recording(std::unique_ptr, + std::unordered_set, ProxyHash>&& nonVolatileLazyProxies, + std::unordered_set, ProxyHash>&& volatileLazyProxies, + std::unique_ptr targetProxyData, + skia_private::TArray>&& finishedProcs); bool addCommands(CommandBuffer*, ResourceProvider*); void addResourceRef(sk_sp); @@ -42,6 +82,13 @@ class Recording final { // Those refs are stored in the array here and will eventually be passed onto a CommandBuffer // when the Recording adds its commands. std::vector> fExtraResourceRefs; + + std::unordered_set, ProxyHash> fNonVolatileLazyProxies; + std::unordered_set, ProxyHash> fVolatileLazyProxies; + + std::unique_ptr fTargetProxyData; + + skia_private::TArray> fFinishedProcs; }; } // namespace skgpu::graphite diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h index 15f3081e55f73..9a30839ab43e8 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/TextureInfo.h @@ -10,8 +10,12 @@ #include "include/gpu/graphite/GraphiteTypes.h" +#ifdef SK_DAWN +#include "include/private/gpu/graphite/DawnTypesPriv.h" +#endif + #ifdef SK_METAL -#include "include/private/gpu/graphite/MtlTypesPriv.h" +#include "include/private/gpu/graphite/MtlGraphiteTypesPriv.h" #endif #ifdef SK_VULKAN @@ -20,15 +24,25 @@ namespace skgpu::graphite { -class TextureInfo { +class SK_API TextureInfo { public: TextureInfo() {} +#ifdef SK_DAWN + TextureInfo(const DawnTextureInfo& dawnInfo) + : fBackend(BackendApi::kDawn) + , fValid(true) + , fSampleCount(dawnInfo.fSampleCount) + , fMipmapped(dawnInfo.fMipmapped) + , fProtected(Protected::kNo) + , fDawnSpec(dawnInfo) {} +#endif + #ifdef SK_METAL TextureInfo(const MtlTextureInfo& mtlInfo) : fBackend(BackendApi::kMetal) , fValid(true) , fSampleCount(mtlInfo.fSampleCount) - , fLevelCount(mtlInfo.fLevelCount) + , fMipmapped(mtlInfo.fMipmapped) , fProtected(Protected::kNo) , fMtlSpec(mtlInfo) {} #endif @@ -38,7 +52,7 @@ class TextureInfo { : fBackend(BackendApi::kVulkan) , fValid(true) , fSampleCount(vkInfo.fSampleCount) - , fLevelCount(vkInfo.fLevelCount) + , fMipmapped(vkInfo.fMipmapped) , fProtected(Protected::kNo) , fVkSpec(vkInfo) { if (vkInfo.fFlags & VK_IMAGE_CREATE_PROTECTED_BIT) { @@ -58,15 +72,25 @@ class TextureInfo { BackendApi backend() const { return fBackend; } uint32_t numSamples() const { return fSampleCount; } - uint32_t numMipLevels() const { return fLevelCount; } + Mipmapped mipmapped() const { return fMipmapped; } Protected isProtected() const { return fProtected; } +#ifdef SK_DAWN + bool getDawnTextureInfo(DawnTextureInfo* info) const { + if (!this->isValid() || fBackend != BackendApi::kDawn) { + return false; + } + *info = DawnTextureSpecToTextureInfo(fDawnSpec, fSampleCount, fMipmapped); + return true; + } +#endif + #ifdef SK_METAL bool getMtlTextureInfo(MtlTextureInfo* info) const { if (!this->isValid() || fBackend != BackendApi::kMetal) { return false; } - *info = MtlTextureSpecToTextureInfo(fMtlSpec, fSampleCount, fLevelCount); + *info = MtlTextureSpecToTextureInfo(fMtlSpec, fSampleCount, fMipmapped); return true; } #endif @@ -76,12 +100,24 @@ class TextureInfo { if (!this->isValid() || fBackend != BackendApi::kVulkan) { return false; } - *info = VulkanTextureSpecToTextureInfo(fVkSpec, fSampleCount, fLevelCount); + *info = VulkanTextureSpecToTextureInfo(fVkSpec, fSampleCount, fMipmapped); return true; } #endif private: +#ifdef SK_DAWN + friend class DawnCaps; + friend class DawnCommandBuffer; + friend class DawnGraphicsPipeline; + friend class DawnResourceProvider; + friend class DawnTexture; + const DawnTextureSpec& dawnTextureSpec() const { + SkASSERT(fValid && fBackend == BackendApi::kDawn); + return fDawnSpec; + } +#endif + #ifdef SK_METAL friend class MtlCaps; friend class MtlGraphicsPipeline; @@ -105,10 +141,13 @@ class TextureInfo { bool fValid = false; uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + Mipmapped fMipmapped = Mipmapped::kNo; Protected fProtected = Protected::kNo; union { +#ifdef SK_DAWN + DawnTextureSpec fDawnSpec; +#endif #ifdef SK_METAL MtlTextureSpec fMtlSpec; #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h new file mode 100644 index 0000000000000..c3b80ae196e32 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/YUVABackendTextures.h @@ -0,0 +1,139 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef skgpu_graphite_YUVABackendTextures_DEFINED +#define skgpu_graphite_YUVABackendTextures_DEFINED + +#include "include/core/SkSpan.h" +#include "include/core/SkYUVAInfo.h" +#include "include/gpu/graphite/BackendTexture.h" + +#include + +namespace skgpu::graphite { +class Recorder; + +/** + * A description of a set of BackendTextures that hold the planar data described by a SkYUVAInfo. + */ +class SK_API YUVABackendTextureInfo { +public: + static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; + + /** Default YUVABackendTextureInfo is invalid. */ + YUVABackendTextureInfo() = default; + YUVABackendTextureInfo(const YUVABackendTextureInfo&) = default; + YUVABackendTextureInfo& operator=(const YUVABackendTextureInfo&) = default; + + /** + * Initializes a YUVABackendTextureInfo to describe a set of textures that can store the + * planes indicated by the SkYUVAInfo. The texture dimensions are taken from the SkYUVAInfo's + * plane dimensions. All the described textures share a common origin. The planar image this + * describes will be mip mapped if all the textures are individually mip mapped as indicated + * by Mipmapped. This will produce an invalid result (return false from isValid()) if the + * passed formats' channels don't agree with SkYUVAInfo. + */ + YUVABackendTextureInfo(const Recorder*, + const SkYUVAInfo&, + const TextureInfo[kMaxPlanes], + Mipmapped); + + bool operator==(const YUVABackendTextureInfo&) const; + bool operator!=(const YUVABackendTextureInfo& that) const { return !(*this == that); } + + /** TextureInfo for the ith plane, or invalid if i >= numPlanes() */ + const TextureInfo& planeTextureInfo(int i) const { + SkASSERT(i >= 0); + return fPlaneTextureInfos[static_cast(i)]; + } + + const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } + + SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } + + Mipmapped mipmapped() const { return fMipmapped; } + + /** The number of planes, 0 if this YUVABackendTextureInfo is invalid. */ + int numPlanes() const { return fYUVAInfo.numPlanes(); } + + /** + * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture + * formats. + */ + bool isValid() const { return fYUVAInfo.isValid(); } + + /** + * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be + * valid if this->isValid(). + */ + SkYUVAInfo::YUVALocations toYUVALocations() const; + +private: + SkYUVAInfo fYUVAInfo; + std::array fPlaneTextureInfos; + std::array fPlaneChannelMasks; + Mipmapped fMipmapped = Mipmapped::kNo; +}; + +/** + * A set of BackendTextures that hold the planar data for an image described a SkYUVAInfo. + */ +class SK_API YUVABackendTextures { +public: + static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; + + YUVABackendTextures() = default; + YUVABackendTextures(const YUVABackendTextures&) = delete; + YUVABackendTextures& operator=(const YUVABackendTextures&) = delete; + + /** + * Initializes a YUVABackendTextures object from a set of textures that store the planes + * indicated by the SkYUVAInfo. This will produce an invalid result (return false from + * isValid()) if the passed texture formats' channels don't agree with SkYUVAInfo. + */ + YUVABackendTextures(const Recorder*, + const SkYUVAInfo&, + const BackendTexture[kMaxPlanes]); + + SkSpan planeTextures() const { + return SkSpan(fPlaneTextures); + } + + /** BackendTexture for the ith plane, or invalid if i >= numPlanes() */ + BackendTexture planeTexture(int i) const { + SkASSERT(i >= 0); + return fPlaneTextures[static_cast(i)]; + } + + const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } + + SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } + + /** The number of planes, 0 if this YUVABackendTextureInfo is invalid. */ + int numPlanes() const { return fYUVAInfo.numPlanes(); } + + /** + * Returns true if this has been configured with a valid SkYUVAInfo with compatible texture + * formats. + */ + bool isValid() const { return fYUVAInfo.isValid(); } + + /** + * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be + * valid if this->isValid(). + */ + SkYUVAInfo::YUVALocations toYUVALocations() const; + +private: + SkYUVAInfo fYUVAInfo; + std::array fPlaneTextures; + std::array fPlaneChannelMasks; +}; + +} // End of namespace skgpu::graphite + +#endif // skgpu_graphite_YUVABackendTextures_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h new file mode 100644 index 0000000000000..291be756306e7 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h @@ -0,0 +1,40 @@ +/* + * 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 skgpu_graphite_DawnTypes_DEFINED +#define skgpu_graphite_DawnTypes_DEFINED + +#include "include/gpu/graphite/GraphiteTypes.h" +#include "webgpu/webgpu_cpp.h" + +namespace skgpu::graphite { + +struct DawnTextureInfo { + uint32_t fSampleCount = 1; + Mipmapped fMipmapped = Mipmapped::kNo; + + // wgpu::TextureDescriptor properties + wgpu::TextureFormat fFormat = wgpu::TextureFormat::Undefined; + wgpu::TextureUsage fUsage = wgpu::TextureUsage::None; + + DawnTextureInfo() = default; + DawnTextureInfo(const wgpu::Texture& texture); + DawnTextureInfo(uint32_t sampleCount, + Mipmapped mipmapped, + wgpu::TextureFormat format, + wgpu::TextureUsage usage) + : fSampleCount(sampleCount) + , fMipmapped(mipmapped) + , fFormat(format) + , fUsage(usage) {} +}; + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_DawnTypes_DEFINED + + diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h new file mode 100644 index 0000000000000..059d128ef59d6 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h @@ -0,0 +1,28 @@ +/* + * 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 skgpu_graphite_DawnUtils_DEFINED +#define skgpu_graphite_DawnUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; +struct DawnBackendContext; + +namespace ContextFactory { +SK_API std::unique_ptr MakeDawn(const DawnBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + + +#endif // skgpu_graphite_DawnUtils_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h index de5f917a9aa04..9d6d0192d170d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h @@ -8,7 +8,7 @@ #ifndef skgpu_graphite_MtlBackendContext_DEFINED #define skgpu_graphite_MtlBackendContext_DEFINED -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" namespace skgpu::graphite { diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h similarity index 85% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h index 5f4c4c8dccff6..bc04421643db2 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h @@ -5,9 +5,10 @@ * found in the LICENSE file. */ -#ifndef skgpu_graphite_MtlTypes_DEFINED -#define skgpu_graphite_MtlTypes_DEFINED +#ifndef skgpu_graphite_MtlGraphiteTypes_DEFINED +#define skgpu_graphite_MtlGraphiteTypes_DEFINED +#include "include/gpu/graphite/GraphiteTypes.h" #include "include/ports/SkCFObject.h" /////////////////////////////////////////////////////////////////////////////// @@ -38,7 +39,7 @@ using MtlHandle = const void*; struct MtlTextureInfo { uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + skgpu::Mipmapped fMipmapped = skgpu::Mipmapped::kNo; // Since we aren't in an Obj-C header we can't directly use Mtl types here. Each of these can // cast to their mapped Mtl types list below. @@ -50,13 +51,13 @@ struct MtlTextureInfo { MtlTextureInfo() = default; MtlTextureInfo(MtlHandle mtlTexture); MtlTextureInfo(uint32_t sampleCount, - uint32_t levelCount, + skgpu::Mipmapped mipmapped, MtlPixelFormat format, MtlTextureUsage usage, MtlStorageMode storageMode, bool framebufferOnly) : fSampleCount(sampleCount) - , fLevelCount(levelCount) + , fMipmapped(mipmapped) , fFormat(format) , fUsage(usage) , fStorageMode(storageMode) @@ -65,4 +66,4 @@ struct MtlTextureInfo { } // namespace skgpu::graphite -#endif // skgpu_graphite_MtlTypes_DEFINED +#endif // skgpu_graphite_MtlGraphiteTypes_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h new file mode 100644 index 0000000000000..cd7837f86c238 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.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 skgpu_graphite_MtlGraphiteUtils_DEFINED +#define skgpu_graphite_MtlGraphiteUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; +struct MtlBackendContext; + +namespace ContextFactory { +SK_API std::unique_ptr MakeMetal(const MtlBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_MtlGraphiteUtils_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h index 4e9802dbca9dc..bd448d2ca6c1e 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h @@ -8,13 +8,14 @@ #ifndef skgpu_graphite_VulkanGraphiteTypes_DEFINED #define skgpu_graphite_VulkanGraphiteTypes_DEFINED +#include "include/gpu/graphite/GraphiteTypes.h" #include "include/gpu/vk/VulkanTypes.h" namespace skgpu::graphite { struct VulkanTextureInfo { uint32_t fSampleCount = 1; - uint32_t fLevelCount = 0; + Mipmapped fMipmapped = Mipmapped::kNo; // VkImageCreateInfo properties // Currently the only supported flag is VK_IMAGE_CREATE_PROTECTED_BIT. Any other flag will not @@ -24,8 +25,6 @@ struct VulkanTextureInfo { VkImageTiling fImageTiling = VK_IMAGE_TILING_OPTIMAL; VkImageUsageFlags fImageUsageFlags = 0; VkSharingMode fSharingMode = VK_SHARING_MODE_EXCLUSIVE; - uint32_t fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED; - VkImageLayout fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; // Properties related to the image view and sampling. These are less inherent properties of the // VkImage but describe how the VkImage should be used within Skia. @@ -41,24 +40,20 @@ struct VulkanTextureInfo { VulkanTextureInfo() = default; VulkanTextureInfo(uint32_t sampleCount, - uint32_t levelCount, + Mipmapped mipmapped, VkImageCreateFlags flags, VkFormat format, VkImageTiling imageTiling, VkImageUsageFlags imageUsageFlags, VkSharingMode sharingMode, - uint32_t currentQueueFamily, - VkImageLayout imageLayout, VkImageAspectFlags aspectMask) : fSampleCount(sampleCount) - , fLevelCount(levelCount) + , fMipmapped(mipmapped) , fFlags(flags) , fFormat(format) , fImageTiling(imageTiling) , fImageUsageFlags(imageUsageFlags) , fSharingMode(sharingMode) - , fCurrentQueueFamily(currentQueueFamily) - , fImageLayout(imageLayout) , fAspectMask(aspectMask) {} }; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h new file mode 100644 index 0000000000000..0cfa0e9bf0a40 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h @@ -0,0 +1,28 @@ +/* + * 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 skgpu_graphite_VulkanGraphiteUtils_DEFINED +#define skgpu_graphite_VulkanGraphiteUtils_DEFINED + +#include + +#include "include/private/base/SkAPI.h" + +namespace skgpu { struct VulkanBackendContext; } + +namespace skgpu::graphite { + +class Context; +struct ContextOptions; + +namespace ContextFactory { +SK_API std::unique_ptr MakeVulkan(const VulkanBackendContext&, const ContextOptions&); +} // namespace ContextFactory + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_VulkanGraphiteUtils_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h index ac866167bc679..b3e4b7b84268d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mock/GrMockTypes.h @@ -8,7 +8,8 @@ #ifndef GrMockOptions_DEFINED #define GrMockOptions_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/core/SkTextureCompressionType.h" +#include "include/gpu/GpuTypes.h" #include "include/private/gpu/ganesh/GrTypesPriv.h" class GrBackendFormat; @@ -16,17 +17,17 @@ class GrBackendFormat; struct GrMockTextureInfo { GrMockTextureInfo() : fColorType(GrColorType::kUnknown) - , fCompressionType(SkImage::CompressionType::kNone) + , fCompressionType(SkTextureCompressionType::kNone) , fID(0) {} GrMockTextureInfo(GrColorType colorType, - SkImage::CompressionType compressionType, + SkTextureCompressionType compressionType, int id) : fColorType(colorType) , fCompressionType(compressionType) , fID(id) { SkASSERT(fID); - if (fCompressionType != SkImage::CompressionType::kNone) { + if (fCompressionType != SkTextureCompressionType::kNone) { SkASSERT(colorType == GrColorType::kUnknown); } } @@ -39,10 +40,10 @@ struct GrMockTextureInfo { GrBackendFormat getBackendFormat() const; - SkImage::CompressionType compressionType() const { return fCompressionType; } + SkTextureCompressionType compressionType() const { return fCompressionType; } GrColorType colorType() const { - SkASSERT(fCompressionType == SkImage::CompressionType::kNone); + SkASSERT(fCompressionType == SkTextureCompressionType::kNone); return fColorType; } @@ -50,7 +51,7 @@ struct GrMockTextureInfo { private: GrColorType fColorType; - SkImage::CompressionType fCompressionType; + SkTextureCompressionType fCompressionType; int fID; }; @@ -82,12 +83,15 @@ struct GrMockRenderTargetInfo { struct GrMockSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrColorType fColorType = GrColorType::kUnknown; - SkImage::CompressionType fCompressionType = SkImage::CompressionType::kNone; + SkTextureCompressionType fCompressionType = SkTextureCompressionType::kNone; }; +static constexpr int kSkTextureCompressionTypeCount = + static_cast(SkTextureCompressionType::kLast) + 1; + /** * A pointer to this type is used as the GrBackendContext when creating a Mock GrContext. It can be * used to specify capability options for the mock context. If nullptr is used a default constructed @@ -105,9 +109,9 @@ struct GrMockOptions { fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888]; - fCompressedOptions[(int)SkImage::CompressionType::kETC2_RGB8_UNORM].fTexturable = true; - fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGB8_UNORM].fTexturable = true; - fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGBA8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kETC2_RGB8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kBC1_RGB8_UNORM].fTexturable = true; + fCompressedOptions[(int)SkTextureCompressionType::kBC1_RGBA8_UNORM].fTexturable = true; } struct ConfigOptions { @@ -126,7 +130,7 @@ struct GrMockOptions { int fMaxWindowRectangles = 0; int fMaxVertexAttributes = 16; ConfigOptions fConfigOptions[kGrColorTypeCnt]; - ConfigOptions fCompressedOptions[SkImage::kCompressionTypeCount]; + ConfigOptions fCompressedOptions[kSkTextureCompressionTypeCount]; // GrShaderCaps options. bool fIntegerSupport = false; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h index f7a232e3c6cea..7c0d620e06412 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/mtl/GrMtlTypes.h @@ -8,7 +8,7 @@ #ifndef GrMtlTypes_DEFINED #define GrMtlTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include "include/ports/SkCFObject.h" /** @@ -49,7 +49,7 @@ struct GrMtlTextureInfo { struct GrMtlSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; // Since we aren't in an Obj-C header we can't directly use Mtl types here. Each of these can // cast to their mapped Mtl types list below. diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h index b166e59920676..23c1b0deaf4a5 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkBackendContext.h @@ -72,7 +72,7 @@ struct SK_API GrVkBackendContext { bool fOwnsInstanceAndDevice = false; // Indicates that we are working with protected content and all CommandPool and Queue operations // should be done in a protected context. - GrProtected fProtectedContext = GrProtected::kNo; + skgpu::Protected fProtectedContext = skgpu::Protected::kNo; }; #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h index 9d0a4c2c60133..ae680a8af5521 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/GrVkTypes.h @@ -9,7 +9,7 @@ #ifndef GrVkTypes_DEFINED #define GrVkTypes_DEFINED -#include "include/gpu/GrTypes.h" +#include "include/gpu/GpuTypes.h" #include "include/gpu/vk/VulkanTypes.h" using GrVkBackendMemory = skgpu::VulkanBackendMemory; @@ -72,7 +72,7 @@ struct GrVkImageInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; uint32_t fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; GrVkYcbcrConversionInfo fYcbcrConversionInfo; VkSharingMode fSharingMode = VK_SHARING_MODE_EXCLUSIVE; #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK @@ -137,7 +137,7 @@ struct GrVkDrawableInfo { struct GrVkSurfaceInfo { uint32_t fSampleCount = 1; uint32_t fLevelCount = 0; - GrProtected fProtected = GrProtected::kNo; + skgpu::Protected fProtected = skgpu::Protected::kNo; VkImageTiling fImageTiling = VK_IMAGE_TILING_OPTIMAL; VkFormat fFormat = VK_FORMAT_UNDEFINED; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h index 445fd53908333..90a40c0e674d8 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanExtensions.h @@ -10,7 +10,7 @@ #include "include/core/SkString.h" #include "include/gpu/vk/VulkanTypes.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" namespace skgpu { @@ -48,7 +48,7 @@ class SK_API VulkanExtensions { #ifdef SK_DEBUG void dump() const { SkDebugf("**Vulkan Extensions**\n"); - for (int i = 0; i < fExtensions.count(); ++i) { + for (int i = 0; i < fExtensions.size(); ++i) { SkDebugf("%s. Version: %d\n", fExtensions[i].fName.c_str(), fExtensions[i].fSpecVersion); } @@ -59,7 +59,7 @@ class SK_API VulkanExtensions { private: void getSpecVersions(VulkanGetProc getProc, VkInstance, VkPhysicalDevice); - SkTArray fExtensions; + skia_private::TArray fExtensions; }; } // namespace skgpu diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h index 9d73fdf4bdf65..ebaa28ed1b4b0 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h @@ -35,7 +35,7 @@ class VulkanMemoryAllocator : public SkRefCnt { }; enum class BufferUsage { - // Buffers that will only be accessed from the device (large const buffers). Will always be + // Buffers that will only be accessed from the device (large const buffers) will always be // in device local memory. kGpuOnly, // Buffers that typically will be updated multiple times by the host and read on the gpu @@ -103,12 +103,10 @@ class VulkanMemoryAllocator : public SkRefCnt { virtual void freeMemory(const skgpu::VulkanBackendMemory&) = 0; - // Returns the total amount of memory that is allocated and in use by an allocation for this - // allocator. - virtual uint64_t totalUsedMemory() const = 0; - - // Returns the total amount of memory that is allocated by this allocator. - virtual uint64_t totalAllocatedMemory() const = 0; + // Returns the total amount of memory that is allocated as well as total + // amount of memory in use by an allocation from this allocator. + // Return 1st param is total allocated memory, 2nd is total used memory. + virtual std::pair totalAllocatedAndUsedMemory() const = 0; }; } // namespace skgpu diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h index 18c71562e08c0..47d2b3118fbf6 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/pathops/SkPathOps.h @@ -9,8 +9,8 @@ #include "include/core/SkPath.h" #include "include/core/SkTypes.h" -#include "include/private/SkTArray.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkTDArray.h" struct SkRect; @@ -102,7 +102,7 @@ class SK_API SkOpBuilder { bool resolve(SkPath* result); private: - SkTArray fPathRefs; + skia_private::TArray fPathRefs; SkTDArray fOps; static bool FixWinding(SkPath* path); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h new file mode 100644 index 0000000000000..6a22365af433b --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_data.h @@ -0,0 +1,22 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkFontMgr_data_DEFINED +#define SkFontMgr_data_DEFINED + +#include "include/core/SkData.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkSpan.h" +#include "include/core/SkTypes.h" + +class SkFontMgr; + +/** Create a custom font manager which wraps a collection of SkData-stored fonts. + * This font manager uses FreeType for rendering. + */ +SK_API sk_sp SkFontMgr_New_Custom_Data(SkSpan>); + +#endif // SkFontMgr_data_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h index 73210bc9a546b..99a1813456f09 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkFontMgr_indirect.h @@ -13,9 +13,9 @@ #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" #include "include/ports/SkRemotableFontMgr.h" -#include "include/private/SkMutex.h" -#include "include/private/SkOnce.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkTArray.h" class SkData; class SkFontStyle; @@ -34,18 +34,18 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { protected: int onCountFamilies() const override; void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onCreateStyleSet(int index) const override; + sk_sp onCreateStyleSet(int index) const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkTypeface* onMatchFamilyStyle(const char familyName[], - const SkFontStyle& fontStyle) const override; + sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle& fontStyle) const override; - SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], - const SkFontStyle&, - const char* bcp47[], - int bcp47Count, - SkUnichar character) const override; + sk_sp onMatchFamilyStyleCharacter(const char familyName[], + const SkFontStyle&, + const char* bcp47[], + int bcp47Count, + SkUnichar character) const override; sk_sp onMakeFromStreamIndex(std::unique_ptr, int ttcIndex) const override; sk_sp onMakeFromStreamArgs(std::unique_ptr stream, @@ -55,7 +55,7 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { sk_sp onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override; private: - SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const; + sk_sp createTypefaceFromFontId(const SkFontIdentity& fontId) const; sk_sp fImpl; sk_sp fProxy; @@ -93,7 +93,7 @@ class SK_API SkFontMgr_Indirect : public SkFontMgr { * typefaces with that data id. By storing the index next to the typeface, * this data cache also acts as a typeface cache. */ - mutable SkTArray fDataCache; + mutable skia_private::TArray fDataCache; mutable SkMutex fDataCacheMutex; friend class SkStyleSet_Indirect; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h index 8017b77cd9a76..eacb6bde9c540 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkRemotableFontMgr.h @@ -11,7 +11,7 @@ #include "include/core/SkFontStyle.h" #include "include/core/SkRefCnt.h" #include "include/core/SkTypes.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" class SkDataTable; class SkStreamAsset; @@ -48,7 +48,7 @@ class SK_API SkRemotableFontIdentitySet : public SkRefCnt { friend SkRemotableFontIdentitySet* sk_remotable_font_identity_set_new(); int fCount; - SkAutoTArray fData; + skia_private::AutoTArray fData; using INHERITED = SkRefCnt; }; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h index 8437e7a5143ac..0f0d21ad2a67c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/ports/SkTypeface_win.h @@ -8,6 +8,7 @@ #ifndef SkTypeface_win_DEFINED #define SkTypeface_win_DEFINED +#include "include/core/SkRefCnt.h" #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" @@ -26,7 +27,7 @@ typedef LOGFONTA LOGFONT; * corresponding typeface for the specified logfont. The caller is responsible * for calling unref() when it is finished. */ -SK_API SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT&); +SK_API sk_sp SkCreateTypefaceFromLOGFONT(const LOGFONT&); /** * Copy the LOGFONT associated with this typeface into the lf parameter. Note diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h index 235649feec3e3..e703b622bf363 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkChecksum.h @@ -10,17 +10,22 @@ #include "include/core/SkString.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" #include "include/private/SkOpts_spi.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkTLogic.h" #include #include +#include -class SkChecksum : SkNoncopyable { +class SkChecksum { public: + SkChecksum() = default; + // Make noncopyable + SkChecksum(const SkChecksum&) = delete; + SkChecksum& operator=(const SkChecksum&) = delete; + /** - * uint32_t -> uint32_t hash, useful for when you're about to trucate this hash but you + * uint32_t -> uint32_t hash, useful for when you're about to truncate this hash but you * suspect its low bits aren't well mixed. * * This is the Murmur3 finalizer. @@ -35,7 +40,7 @@ class SkChecksum : SkNoncopyable { } /** - * uint32_t -> uint32_t hash, useful for when you're about to trucate this hash but you + * uint32_t -> uint32_t hash, useful for when you're about to truncate this hash but you * suspect its low bits aren't well mixed. * * This version is 2-lines cheaper than Mix, but seems to be sufficient for the font cache. @@ -52,12 +57,14 @@ class SkChecksum : SkNoncopyable { // It should be both reasonably fast and high quality. struct SkGoodHash { template - std::enable_if_t operator()(const K& k) const { + std::enable_if_t::value && sizeof(K) == 4, uint32_t> + operator()(const K& k) const { return SkChecksum::Mix(*(const uint32_t*)&k); } template - std::enable_if_t operator()(const K& k) const { + std::enable_if_t::value && sizeof(K) != 4, uint32_t> + operator()(const K& k) const { return SkOpts::hash_fn(&k, sizeof(K), 0); } @@ -74,4 +81,22 @@ struct SkGoodHash { } }; +// The default hashing behavior in SkGoodHash requires the type to have a unique object +// representation (i.e. all bits in contribute to its identity so can be hashed directly). This is +// false when a struct has padding for alignment (which can be avoided by using +// SK_BEGIN|END_REQUIRE_DENSE) or if the struct has floating point members since there are multiple +// bit representations for NaN. +// +// Often Skia code has externally removed the possibility of NaN so the bit representation of a +// non-NaN float will still hash correctly. SkForceDirectHash produces the same as SkGoodHash +// for K's that do not satisfy std::has_unique_object_representation. It should be used sparingly +// and it's use may highlight design issues with the key's data that might warrant an explicitly +// implemented hash function. +template +struct SkForceDirectHash { + uint32_t operator()(const K& k) const { + return SkOpts::hash_fn(&k, sizeof(K), 0); + } +}; + #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h index 5761df2c0b5d4..1bef596a3628f 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkColorData.h @@ -10,8 +10,7 @@ #include "include/core/SkColor.h" #include "include/core/SkColorPriv.h" -#include "include/private/SkTo.h" -#include "include/private/SkVx.h" +#include "include/private/base/SkTo.h" //////////////////////////////////////////////////////////////////////////////////////////// // Convert a 16bit pixel to a 32bit pixel @@ -374,30 +373,6 @@ static inline SkPMColor SkPixel4444ToPixel32(U16CPU c) { return d | (d << 4); } -static inline skvx::float4 swizzle_rb(const skvx::float4& x) { - return skvx::shuffle<2, 1, 0, 3>(x); -} - -static inline skvx::float4 swizzle_rb_if_bgra(const skvx::float4& x) { -#ifdef SK_PMCOLOR_IS_BGRA - return swizzle_rb(x); -#else - return x; -#endif -} - -static inline skvx::float4 Sk4f_fromL32(uint32_t px) { - return skvx::cast(skvx::byte4::Load(&px)) * (1 / 255.0f); -} - -static inline uint32_t Sk4f_toL32(const skvx::float4& px) { - uint32_t l32; - // For the expected positive color values, the +0.5 before the pin and cast effectively rounds - // to the nearest int without having to call round() or lrint(). - skvx::cast(pin(px * 255.f + 0.5f, skvx::float4(0.f), skvx::float4(255.f))).store(&l32); - return l32; -} - using SkPMColor4f = SkRGBA4f; constexpr SkPMColor4f SK_PMColor4fTRANSPARENT = { 0, 0, 0, 0 }; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h new file mode 100644 index 0000000000000..8cf511a10c265 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapInfo.h @@ -0,0 +1,97 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkGainmapInfo_DEFINED +#define SkGainmapInfo_DEFINED + +#include "include/core/SkColor.h" + +/** + * Gainmap rendering parameters. Suppose our display has HDR to SDR ratio of H and we wish to + * display an image with gainmap on this display. Let B be the pixel value from the base image + * in a color space that has the primaries of the base image and a linear transfer function. Let + * G be the pixel value from the gainmap. Let D be the output pixel in the same color space as B. + * The value of D is computed as follows: + * + * First, let W be a weight parameter determing how much the gainmap will be applied. + * W = clamp((log(H) - log(fDisplayRatioSdr)) / + * (log(fDisplayRatioHdr) - log(fDisplayRatioSdr), 0, 1) + * + * Next, let L be the gainmap value in log space. We compute this from the value G that was + * sampled from the texture as follows: + * L = mix(log(fGainmapRatioMin), log(fGainmapRatioMax), pow(G, fGainmapGamma)) + * + * Finally, apply the gainmap to compute D, the displayed pixel. If the base image is SDR then + * compute: + * D = (B + fEpsilonSdr) * exp(L * W) - fEpsilonHdr + * If the base image is HDR then compute: + * D = (B + fEpsilonHdr) * exp(L * (W - 1)) - fEpsilonSdr + * + * In the above math, log() is a natural logarithm and exp() is natural exponentiation. Note, + * however, that the base used for the log() and exp() functions does not affect the results of + * the computation (it cancels out, as long as the same base is used throughout). + */ +struct SkGainmapInfo { + /** + * Parameters for converting the gainmap from its image encoding to log space. These are + * specified per color channel. The alpha value is unused. + */ + SkColor4f fGainmapRatioMin = {1.f, 1.f, 1.f, 1.0}; + SkColor4f fGainmapRatioMax = {2.f, 2.f, 2.f, 1.0}; + SkColor4f fGainmapGamma = {1.f, 1.f, 1.f, 1.f}; + + /** + * Parameters sometimes used in gainmap computation to avoid numerical instability. + */ + SkColor4f fEpsilonSdr = {0.f, 0.f, 0.f, 1.0}; + SkColor4f fEpsilonHdr = {0.f, 0.f, 0.f, 1.0}; + + /** + * If the output display's HDR to SDR ratio is less or equal than fDisplayRatioSdr then the SDR + * rendition is displayed. If the output display's HDR to SDR ratio is greater or equal than + * fDisplayRatioHdr then the HDR rendition is displayed. If the output display's HDR to SDR + * ratio is between these values then an interpolation between the two is displayed using the + * math above. + */ + float fDisplayRatioSdr = 1.f; + float fDisplayRatioHdr = 2.f; + + /** + * Whether the base image is the SDR image or the HDR image. + */ + enum class BaseImageType { + kSDR, + kHDR, + }; + BaseImageType fBaseImageType = BaseImageType::kSDR; + + inline bool operator==(const SkGainmapInfo& other) { + return fGainmapRatioMin == other.fGainmapRatioMin && + fGainmapRatioMax == other.fGainmapRatioMax && fGainmapGamma == other.fGainmapGamma && + fEpsilonSdr == other.fEpsilonSdr && fEpsilonHdr == other.fEpsilonHdr && + fDisplayRatioSdr == other.fDisplayRatioSdr && + fDisplayRatioHdr == other.fDisplayRatioHdr && fBaseImageType == other.fBaseImageType; + } + inline bool operator!=(const SkGainmapInfo& other) { return !(*this == other); } + + // TODO(ccameron): Remove these parameters once we are certain they are not used in Android. + enum class Type { + kUnknown, + kMultiPicture, + kJpegR_Linear, + kJpegR_HLG, + kJpegR_PQ, + kHDRGM, + }; + SkColor4f fLogRatioMin = {0.f, 0.f, 0.f, 1.0}; + SkColor4f fLogRatioMax = {1.f, 1.f, 1.f, 1.0}; + float fHdrRatioMin = 1.f; + float fHdrRatioMax = 50.f; + Type fType = Type::kUnknown; +}; + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h new file mode 100644 index 0000000000000..f490ab96a4cfc --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkGainmapShader.h @@ -0,0 +1,53 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkGainmapShader_DEFINED +#define SkGainmapShader_DEFINED + +#include "include/core/SkRefCnt.h" + +class SkColorSpace; +class SkShader; +class SkImage; +struct SkGainmapInfo; +struct SkRect; +struct SkSamplingOptions; + +/** + * A gainmap shader will apply a gainmap to an base image using the math described alongside the + * definition of SkGainmapInfo. + */ +class SK_API SkGainmapShader { +public: + /** + * Make a gainmap shader. + * + * When sampling the base image baseImage, the rectangle baseRect will be sampled to map to + * the rectangle dstRect. Sampling will be done according to baseSamplingOptions. + * + * When sampling the gainmap image gainmapImage, the rectangle gainmapRect will be sampled to + * map to the rectangle dstRect. Sampling will be done according to gainmapSamplingOptions. + * + * The gainmap will be applied according to the HDR to SDR ratio specified in dstHdrRatio. + * + * This shader must know the color space of the canvas that it will be rendered to. This color + * space must be specified in dstColorSpace. + * TODO(ccameron): Remove the need for dstColorSpace. + */ + static sk_sp Make(const sk_sp& baseImage, + const SkRect& baseRect, + const SkSamplingOptions& baseSamplingOptions, + const sk_sp& gainmapImage, + const SkRect& gainmapRect, + const SkSamplingOptions& gainmapSamplingOptions, + const SkGainmapInfo& gainmapInfo, + const SkRect& dstRect, + float dstHdrRatio, + sk_sp dstColorSpace); +}; + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h deleted file mode 100644 index 0888869607db7..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkHalf.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkHalf_DEFINED -#define SkHalf_DEFINED - -#include "include/core/SkTypes.h" -#include "include/private/SkVx.h" - -// 16-bit floating point value -// format is 1 bit sign, 5 bits exponent, 10 bits mantissa -// only used for storage -typedef uint16_t SkHalf; - -static constexpr uint16_t SK_HalfMin = 0x0400; // 2^-14 (minimum positive normal value) -static constexpr uint16_t SK_HalfMax = 0x7bff; // 65504 -static constexpr uint16_t SK_HalfEpsilon = 0x1400; // 2^-10 -static constexpr uint16_t SK_Half1 = 0x3C00; // 1 - -// convert between half and single precision floating point -float SkHalfToFloat(SkHalf h); -SkHalf SkFloatToHalf(float f); - -// Convert between half and single precision floating point, -// assuming inputs and outputs are both finite, and may -// flush values which would be denormal half floats to zero. -static inline skvx::float4 SkHalfToFloat_finite_ftz(uint64_t rgba) { - return skvx::from_half(skvx::half4::Load(&rgba)); -} -static inline skvx::half4 SkFloatToHalf_finite_ftz(const skvx::float4& c) { - return skvx::to_half(c); -} - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h index f7a5900e0e1ff..8ebb6ca18e53f 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkIDChangeListener.h @@ -9,8 +9,9 @@ #define SkIDChangeListener_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkThreadAnnotations.h" #include @@ -65,7 +66,7 @@ class SkIDChangeListener : public SkRefCnt { private: mutable SkMutex fMutex; - SkTDArray fListeners SK_GUARDED_BY(fMutex); // pointers are reffed + skia_private::STArray<1, sk_sp> fListeners SK_GUARDED_BY(fMutex); }; private: diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h deleted file mode 100644 index 70b9d715f06b6..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkImageInfoPriv.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkImageInfoPriv_DEFINED -#define SkImageInfoPriv_DEFINED - -#include "include/core/SkColor.h" -#include "include/core/SkImageInfo.h" - -static inline uint32_t SkColorTypeChannelFlags(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: return 0; - case kAlpha_8_SkColorType: return kAlpha_SkColorChannelFlag; - case kRGB_565_SkColorType: return kRGB_SkColorChannelFlags; - case kARGB_4444_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGB_888x_SkColorType: return kRGB_SkColorChannelFlags; - case kBGRA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_1010102_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGB_101010x_SkColorType: return kRGB_SkColorChannelFlags; - case kBGRA_1010102_SkColorType: return kRGBA_SkColorChannelFlags; - case kBGR_101010x_SkColorType: return kRGB_SkColorChannelFlags; - case kGray_8_SkColorType: return kGray_SkColorChannelFlag; - case kRGBA_F16Norm_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_F16_SkColorType: return kRGBA_SkColorChannelFlags; - case kRGBA_F32_SkColorType: return kRGBA_SkColorChannelFlags; - case kR8G8_unorm_SkColorType: return kRG_SkColorChannelFlags; - case kA16_unorm_SkColorType: return kAlpha_SkColorChannelFlag; - case kR16G16_unorm_SkColorType: return kRG_SkColorChannelFlags; - case kA16_float_SkColorType: return kAlpha_SkColorChannelFlag; - case kR16G16_float_SkColorType: return kRG_SkColorChannelFlags; - case kR16G16B16A16_unorm_SkColorType: return kRGBA_SkColorChannelFlags; - case kSRGBA_8888_SkColorType: return kRGBA_SkColorChannelFlags; - case kR8_unorm_SkColorType: return kRed_SkColorChannelFlag; - } - SkUNREACHABLE; -} - -static inline bool SkColorTypeIsAlphaOnly(SkColorType ct) { - return SkColorTypeChannelFlags(ct) == kAlpha_SkColorChannelFlag; -} - -static inline bool SkAlphaTypeIsValid(unsigned value) { - return value <= kLastEnum_SkAlphaType; -} - -static int SkColorTypeShiftPerPixel(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: return 0; - case kAlpha_8_SkColorType: return 0; - case kRGB_565_SkColorType: return 1; - case kARGB_4444_SkColorType: return 1; - case kRGBA_8888_SkColorType: return 2; - case kRGB_888x_SkColorType: return 2; - case kBGRA_8888_SkColorType: return 2; - case kRGBA_1010102_SkColorType: return 2; - case kRGB_101010x_SkColorType: return 2; - case kBGRA_1010102_SkColorType: return 2; - case kBGR_101010x_SkColorType: return 2; - case kGray_8_SkColorType: return 0; - case kRGBA_F16Norm_SkColorType: return 3; - case kRGBA_F16_SkColorType: return 3; - case kRGBA_F32_SkColorType: return 4; - case kR8G8_unorm_SkColorType: return 1; - case kA16_unorm_SkColorType: return 1; - case kR16G16_unorm_SkColorType: return 2; - case kA16_float_SkColorType: return 1; - case kR16G16_float_SkColorType: return 2; - case kR16G16B16A16_unorm_SkColorType: return 3; - case kSRGBA_8888_SkColorType: return 2; - case kR8_unorm_SkColorType: return 0; - } - SkUNREACHABLE; -} - -static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { - return (size_t)(width * SkColorTypeBytesPerPixel(ct)); -} - -static inline bool SkColorTypeIsValid(unsigned value) { - return value <= kLastEnum_SkColorType; -} - -static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) { - if (kUnknown_SkColorType == ct) { - return 0; - } - return (size_t)y * rowBytes + ((size_t)x << SkColorTypeShiftPerPixel(ct)); -} - -static inline bool SkColorTypeIsNormalized(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: - case kAlpha_8_SkColorType: - case kRGB_565_SkColorType: - case kARGB_4444_SkColorType: - case kRGBA_8888_SkColorType: - case kRGB_888x_SkColorType: - case kBGRA_8888_SkColorType: - case kRGBA_1010102_SkColorType: - case kRGB_101010x_SkColorType: - case kBGRA_1010102_SkColorType: - case kBGR_101010x_SkColorType: - case kGray_8_SkColorType: - case kRGBA_F16Norm_SkColorType: - case kR8G8_unorm_SkColorType: - case kA16_unorm_SkColorType: - case kA16_float_SkColorType: /*subtle... alpha is always [0,1]*/ - case kR16G16_unorm_SkColorType: - case kR16G16B16A16_unorm_SkColorType: - case kSRGBA_8888_SkColorType: - case kR8_unorm_SkColorType: - return true; - - case kRGBA_F16_SkColorType: - case kRGBA_F32_SkColorType: - case kR16G16_float_SkColorType: - return false; - } - SkUNREACHABLE; -} - -static inline int SkColorTypeMaxBitsPerChannel(SkColorType ct) { - switch (ct) { - case kUnknown_SkColorType: - return 0; - - case kARGB_4444_SkColorType: - return 4; - - case kRGB_565_SkColorType: - return 6; - - case kAlpha_8_SkColorType: - case kRGBA_8888_SkColorType: - case kRGB_888x_SkColorType: - case kBGRA_8888_SkColorType: - case kGray_8_SkColorType: - case kR8G8_unorm_SkColorType: - case kSRGBA_8888_SkColorType: - case kR8_unorm_SkColorType: - return 8; - - case kRGBA_1010102_SkColorType: - case kRGB_101010x_SkColorType: - case kBGRA_1010102_SkColorType: - case kBGR_101010x_SkColorType: - return 10; - - case kRGBA_F16Norm_SkColorType: - case kA16_unorm_SkColorType: - case kA16_float_SkColorType: - case kR16G16_unorm_SkColorType: - case kR16G16B16A16_unorm_SkColorType: - case kRGBA_F16_SkColorType: - case kR16G16_float_SkColorType: - return 16; - - case kRGBA_F32_SkColorType: - return 32; - } - SkUNREACHABLE; -} - -/** - * Returns true if |info| contains a valid colorType and alphaType. - */ -static inline bool SkColorInfoIsValid(const SkColorInfo& info) { - return info.colorType() != kUnknown_SkColorType && info.alphaType() != kUnknown_SkAlphaType; -} - -/** - * Returns true if |info| contains a valid combination of width, height and colorInfo. - */ -static inline bool SkImageInfoIsValid(const SkImageInfo& info) { - if (info.width() <= 0 || info.height() <= 0) { - return false; - } - - const int kMaxDimension = SK_MaxS32 >> 2; - if (info.width() > kMaxDimension || info.height() > kMaxDimension) { - return false; - } - - return SkColorInfoIsValid(info.colorInfo()); -} - -/** - * Returns true if Skia has defined a pixel conversion from the |src| to the |dst|. - * Returns false otherwise. - */ -static inline bool SkImageInfoValidConversion(const SkImageInfo& dst, const SkImageInfo& src) { - return SkImageInfoIsValid(dst) && SkImageInfoIsValid(src); -} -#endif // SkImageInfoPriv_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h new file mode 100644 index 0000000000000..756de78b23101 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegGainmapEncoder.h @@ -0,0 +1,71 @@ +/* + * Copyright 2023 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkJpegGainmapEncoder_DEFINED +#define SkJpegGainmapEncoder_DEFINED + +#include "include/encode/SkJpegEncoder.h" + +class SkPixmap; +class SkWStream; +struct SkGainmapInfo; + +class SK_API SkJpegGainmapEncoder { +public: + /** + * Encode a JpegR image to |dst|. + * + * The base image is specified by |base|, and |baseOptions| controls the encoding behavior for + * the base image. + * + * The gainmap image is specified by |gainmap|, and |gainmapOptions| controls the encoding + * behavior for the gainmap image. + * + * The rendering behavior of the gainmap image is provided in |gainmapInfo|. Not all gainmap + * based images are compatible with JpegR. If the image is not compatible with JpegR, then + * convert the gainmap to a format that is capable with JpegR. This conversion may result in + * less precise quantization of the gainmap image. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ + static bool EncodeJpegR(SkWStream* dst, + const SkPixmap& base, + const SkJpegEncoder::Options& baseOptions, + const SkPixmap& gainmap, + const SkJpegEncoder::Options& gainmapOptions, + const SkGainmapInfo& gainmapInfo); + + /** + * Encode an HDRGM image to |dst|. + * + * The base image is specified by |base|, and |baseOptions| controls the encoding behavior for + * the base image. + * + * The gainmap image is specified by |gainmap|, and |gainmapOptions| controls the encoding + * behavior for the gainmap image. + * + * The rendering behavior of the gainmap image is provided in |gainmapInfo|. + * + * If |baseOptions| or |gainmapOptions| specify XMP metadata, then that metadata will be + * overwritten. + * + * Returns true on success. Returns false on an invalid or unsupported |src|. + */ + static bool EncodeHDRGM(SkWStream* dst, + const SkPixmap& base, + const SkJpegEncoder::Options& baseOptions, + const SkPixmap& gainmap, + const SkJpegEncoder::Options& gainmapOptions, + const SkGainmapInfo& gainmapInfo); + + /** + * Write a Multi Picture Format containing the |imageCount| images specified by |images|. + */ + static bool MakeMPF(SkWStream* dst, const SkData** images, size_t imageCount); +}; + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h new file mode 100644 index 0000000000000..0b8f6ce1f7577 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkJpegMetadataDecoder.h @@ -0,0 +1,61 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkJpegMetadataDecoder_DEFINED +#define SkJpegMetadataDecoder_DEFINED + +#include "include/core/SkData.h" +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +#include +#include + +struct SkGainmapInfo; + +/** + * An interface that can be used to extract metadata from an encoded JPEG file. + * TODO(https://crbug.com/1404000): Add interface for ICC profile and EXIF extraction. + */ +class SK_API SkJpegMetadataDecoder { +public: + SkJpegMetadataDecoder() {} + virtual ~SkJpegMetadataDecoder() {} + + SkJpegMetadataDecoder(const SkJpegMetadataDecoder&) = delete; + SkJpegMetadataDecoder& operator=(const SkJpegMetadataDecoder&) = delete; + + /** + * A segment from a JPEG file. This is usually populated from a jpeg_marker_struct. + */ + struct SK_API Segment { + Segment(uint8_t marker, sk_sp data) : fMarker(marker), fData(std::move(data)) {} + + // The segment's marker. + uint8_t fMarker = 0; + + // The segment's parameters (not including the marker and parameter length). + sk_sp fData; + }; + + /** + * Create metadata for the specified segments from a JPEG file's header (defined as all segments + * before the first StartOfScan). This may return nullptr. + */ + static std::unique_ptr Make(std::vector headerSegments); + + /** + * Given a JPEG encoded image |baseImageData|, return in |outGainmapImageData| the JPEG encoded + * gainmap image and return in |outGainmapInfo| its gainmap rendering parameters. Return true if + * both output variables were successfully populated, otherwise return false. + */ + virtual bool findGainmapImage(sk_sp baseImageData, + sk_sp& outGainmapImagedata, + SkGainmapInfo& outGainmapInfo) = 0; +}; + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h index e57dc1433ff50..6e888b77c84c3 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOpts_spi.h @@ -8,7 +8,9 @@ #ifndef SkOpts_spi_DEFINED #define SkOpts_spi_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" + +#include // These are exposed as SK_SPI (e.g. SkParagraph), the rest of SkOpts is // declared in src/core diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h index e72651dce7842..c0e0f08aa1bd9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkPathRef.h @@ -8,36 +8,25 @@ #ifndef SkPathRef_DEFINED #define SkPathRef_DEFINED -#include "include/core/SkMatrix.h" #include "include/core/SkPoint.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkScalar.h" +#include "include/core/SkTypes.h" #include "include/private/SkIDChangeListener.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTDArray.h" -#include "include/private/SkTemplates.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkTArray.h" +#include "include/private/base/SkTo.h" #include -#include +#include +#include #include +#include -class SkRBuffer; -class SkWBuffer; +class SkMatrix; class SkRRect; -enum class SkPathConvexity { - kConvex, - kConcave, - kUnknown, -}; - -enum class SkPathFirstDirection { - kCW, // == SkPathDirection::kCW - kCCW, // == SkPathDirection::kCCW - kUnknown, -}; - // These are computed from a stream of verbs struct SkPathVerbAnalysis { bool valid; @@ -64,7 +53,13 @@ SkPathVerbAnalysis sk_path_analyze_verbs(const uint8_t verbs[], int count); class SK_API SkPathRef final : public SkNVRefCnt { public: - SkPathRef(SkTDArray points, SkTDArray verbs, SkTDArray weights, + // See https://bugs.chromium.org/p/skia/issues/detail?id=13817 for how these sizes were + // determined. + using PointsArray = skia_private::STArray<4, SkPoint>; + using VerbsArray = skia_private::STArray<4, uint8_t>; + using ConicWeightsArray = skia_private::STArray<2, SkScalar>; + + SkPathRef(PointsArray points, VerbsArray verbs, ConicWeightsArray weights, unsigned segmentMask) : fPoints(std::move(points)) , fVerbs(std::move(verbs)) @@ -320,24 +315,15 @@ class SK_API SkPathRef final : public SkNVRefCnt { bool operator== (const SkPathRef& ref) const; - /** - * Writes the path points and verbs to a buffer. - */ - void writeToBuffer(SkWBuffer* buffer) const; - - /** - * Gets the number of bytes that would be written in writeBuffer() - */ - uint32_t writeSize() const; - void interpolate(const SkPathRef& ending, SkScalar weight, SkPathRef* out) const; /** * Gets an ID that uniquely identifies the contents of the path ref. If two path refs have the * same ID then they have the same verbs and points. However, two path refs may have the same * contents but different genIDs. + * skbug.com/1762 for background on why fillType is necessary (for now). */ - uint32_t genID() const; + uint32_t genID(uint8_t fillType) const; void addGenIDChangeListener(sk_sp); // Threadsafe. int genIDChangeListenerCount(); // Threadsafe @@ -346,6 +332,15 @@ class SK_API SkPathRef final : public SkNVRefCnt { bool isValid() const; SkDEBUGCODE(void validate() const { SkASSERT(this->isValid()); } ) + /** + * Resets this SkPathRef to a clean state. + */ + void reset(); + + bool isInitialEmptyPathRef() const { + return fGenerationID == kEmptyGenID; + } + private: enum SerializationOffsets { kLegacyRRectOrOvalStartIdx_SerializationShift = 28, // requires 3 bits, ignored. @@ -356,7 +351,7 @@ class SK_API SkPathRef final : public SkNVRefCnt { kSegmentMask_SerializationShift = 0 // requires 4 bits (deprecated) }; - SkPathRef() { + SkPathRef(int numVerbs = 0, int numPoints = 0) { fBoundsIsDirty = true; // this also invalidates fIsFinite fGenerationID = kEmptyGenID; fSegmentMask = 0; @@ -365,6 +360,10 @@ class SK_API SkPathRef final : public SkNVRefCnt { // The next two values don't matter unless fIsOval or fIsRRect are true. fRRectOrOvalIsCCW = false; fRRectOrOvalStartIdx = 0xAC; + if (numPoints > 0) + fPoints.reserve_back(numPoints); + if (numVerbs > 0) + fVerbs.reserve_back(numVerbs); SkDEBUGCODE(fEditorsAttached.store(0);) SkDEBUGCODE(this->validate();) } @@ -397,15 +396,20 @@ class SK_API SkPathRef final : public SkNVRefCnt { /** Makes additional room but does not change the counts or change the genID */ void incReserve(int additionalVerbs, int additionalPoints) { SkDEBUGCODE(this->validate();) - fPoints.reserve(fPoints.size() + additionalPoints); - fVerbs.reserve(fVerbs.size() + additionalVerbs); + // Use reserve() so that if there is not enough space, the array will grow with some + // additional space. This ensures repeated calls to grow won't always allocate. + if (additionalPoints > 0) + fPoints.reserve(fPoints.size() + additionalPoints); + if (additionalVerbs > 0) + fVerbs.reserve(fVerbs.size() + additionalVerbs); SkDEBUGCODE(this->validate();) } - /** Resets the path ref with verbCount verbs and pointCount points, all uninitialized. Also - * allocates space for reserveVerb additional verbs and reservePoints additional points.*/ - void resetToSize(int verbCount, int pointCount, int conicCount, - int reserveVerbs = 0, int reservePoints = 0) { + /** + * Resets all state except that of the verbs, points, and conic-weights. + * Intended to be called from other functions that reset state. + */ + void commonReset() { SkDEBUGCODE(this->validate();) this->callGenIDChangeListeners(); fBoundsIsDirty = true; // this also invalidates fIsFinite @@ -414,12 +418,25 @@ class SK_API SkPathRef final : public SkNVRefCnt { fSegmentMask = 0; fIsOval = false; fIsRRect = false; + } - fPoints.reserve(pointCount + reservePoints); - fPoints.resize(pointCount); - fVerbs.reserve(verbCount + reserveVerbs); - fVerbs.resize(verbCount); - fConicWeights.resize(conicCount); + /** Resets the path ref with verbCount verbs and pointCount points, all uninitialized. Also + * allocates space for reserveVerb additional verbs and reservePoints additional points.*/ + void resetToSize(int verbCount, int pointCount, int conicCount, + int reserveVerbs = 0, int reservePoints = 0) { + commonReset(); + // Use reserve_back() so the arrays are sized to exactly fit the data. + const int pointDelta = pointCount + reservePoints - fPoints.size(); + if (pointDelta > 0) { + fPoints.reserve_back(pointDelta); + } + fPoints.resize_back(pointCount); + const int verbDelta = verbCount + reserveVerbs - fVerbs.size(); + if (verbDelta > 0) { + fVerbs.reserve_back(verbDelta); + } + fVerbs.resize_back(verbCount); + fConicWeights.resize_back(conicCount); SkDEBUGCODE(this->validate();) } @@ -489,9 +506,9 @@ class SK_API SkPathRef final : public SkNVRefCnt { mutable SkRect fBounds; - SkTDArray fPoints; - SkTDArray fVerbs; - SkTDArray fConicWeights; + PointsArray fPoints; + VerbsArray fVerbs; + ConicWeightsArray fConicWeights; enum { kEmptyGenID = 1, // GenID reserved for path ref with zero points and zero verbs. diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h index 6e50a5b262594..058b231b138a3 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLDefines.h @@ -11,7 +11,7 @@ #include #include "include/core/SkTypes.h" -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" using SKSL_INT = int64_t; using SKSL_FLOAT = float; @@ -21,17 +21,17 @@ namespace SkSL { class Expression; class Statement; -using ComponentArray = SkSTArray<4, int8_t>; // for Swizzles +using ComponentArray = skia_private::STArray<4, int8_t>; // for Swizzles -class ExpressionArray : public SkSTArray<2, std::unique_ptr> { +class ExpressionArray : public skia_private::STArray<2, std::unique_ptr> { public: - using SkSTArray::SkSTArray; + using STArray::STArray; /** Returns a new ExpressionArray containing a clone of every element. */ ExpressionArray clone() const; }; -using StatementArray = SkSTArray<2, std::unique_ptr>; +using StatementArray = skia_private::STArray<2, std::unique_ptr>; // Functions larger than this (measured in IR nodes) will not be inlined. This growth factor // accounts for the number of calls being inlined--i.e., a function called five times (that is, with diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h deleted file mode 100644 index c11a56614c42b..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLIRNode.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_IRNODE -#define SKSL_IRNODE - -#include "include/private/SkSLString.h" -#include "include/private/SkTArray.h" -#include "include/sksl/SkSLPosition.h" -#include "src/sksl/SkSLLexer.h" -#include "src/sksl/SkSLModifiersPool.h" -#include "src/sksl/SkSLPool.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Expression; -class FunctionDeclaration; -class FunctionDefinition; -class Statement; -class Symbol; -class SymbolTable; -class Type; -class Variable; -class VariableReference; -enum class VariableRefKind : int8_t; -enum class VariableStorage : int8_t; - -/** - * Represents a node in the intermediate representation (IR) tree. The IR is a fully-resolved - * version of the program (all types determined, everything validated), ready for code generation. - */ -class IRNode : public Poolable { -public: - virtual ~IRNode() {} - - virtual std::string description() const = 0; - - // No copy construction or assignment - IRNode(const IRNode&) = delete; - IRNode& operator=(const IRNode&) = delete; - - // position of this element within the program being compiled, for error reporting purposes - Position fPosition; - -protected: - IRNode(Position position, int kind) - : fPosition(position) - , fKind(kind) {} - - int fKind; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h deleted file mode 100644 index 1b00f0e7c67ed..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLLayout.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_LAYOUT -#define SKSL_LAYOUT - -#include "include/private/SkSLString.h" - -namespace SkSL { - -/** - * Represents a layout block appearing before a variable declaration, as in: - * - * layout (location = 0) int x; - */ -struct Layout { - enum Flag { - kOriginUpperLeft_Flag = 1 << 0, - kPushConstant_Flag = 1 << 1, - kBlendSupportAllEquations_Flag = 1 << 2, - kColor_Flag = 1 << 3, - - // These flags indicate if the qualifier appeared, regardless of the accompanying value. - kLocation_Flag = 1 << 4, - kOffset_Flag = 1 << 5, - kBinding_Flag = 1 << 6, - kIndex_Flag = 1 << 7, - kSet_Flag = 1 << 8, - kBuiltin_Flag = 1 << 9, - kInputAttachmentIndex_Flag = 1 << 10, - }; - - Layout(int flags, int location, int offset, int binding, int index, int set, int builtin, - int inputAttachmentIndex) - : fFlags(flags) - , fLocation(location) - , fOffset(offset) - , fBinding(binding) - , fIndex(index) - , fSet(set) - , fBuiltin(builtin) - , fInputAttachmentIndex(inputAttachmentIndex) {} - - Layout() - : fFlags(0) - , fLocation(-1) - , fOffset(-1) - , fBinding(-1) - , fIndex(-1) - , fSet(-1) - , fBuiltin(-1) - , fInputAttachmentIndex(-1) {} - - static Layout builtin(int builtin) { - Layout result; - result.fBuiltin = builtin; - return result; - } - - std::string description() const { - std::string result; - auto separator = [firstSeparator = true]() mutable -> std::string { - if (firstSeparator) { - firstSeparator = false; - return ""; - } else { - return ", "; - }}; - if (fLocation >= 0) { - result += separator() + "location = " + std::to_string(fLocation); - } - if (fOffset >= 0) { - result += separator() + "offset = " + std::to_string(fOffset); - } - if (fBinding >= 0) { - result += separator() + "binding = " + std::to_string(fBinding); - } - if (fIndex >= 0) { - result += separator() + "index = " + std::to_string(fIndex); - } - if (fSet >= 0) { - result += separator() + "set = " + std::to_string(fSet); - } - if (fBuiltin >= 0) { - result += separator() + "builtin = " + std::to_string(fBuiltin); - } - if (fInputAttachmentIndex >= 0) { - result += separator() + "input_attachment_index = " + - std::to_string(fInputAttachmentIndex); - } - if (fFlags & kOriginUpperLeft_Flag) { - result += separator() + "origin_upper_left"; - } - if (fFlags & kBlendSupportAllEquations_Flag) { - result += separator() + "blend_support_all_equations"; - } - if (fFlags & kPushConstant_Flag) { - result += separator() + "push_constant"; - } - if (fFlags & kColor_Flag) { - result += separator() + "color"; - } - if (result.size() > 0) { - result = "layout (" + result + ")"; - } - return result; - } - - bool operator==(const Layout& other) const { - return fFlags == other.fFlags && - fLocation == other.fLocation && - fOffset == other.fOffset && - fBinding == other.fBinding && - fIndex == other.fIndex && - fSet == other.fSet && - fBuiltin == other.fBuiltin && - fInputAttachmentIndex == other.fInputAttachmentIndex; - } - - bool operator!=(const Layout& other) const { - return !(*this == other); - } - - int fFlags; - int fLocation; - int fOffset; - int fBinding; - int fIndex; - int fSet; - // builtin comes from SPIR-V and identifies which particular builtin value this object - // represents. - int fBuiltin; - // input_attachment_index comes from Vulkan/SPIR-V to connect a shader variable to the a - // corresponding attachment on the subpass in which the shader is being used. - int fInputAttachmentIndex; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h deleted file mode 100644 index 732810b7da71c..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLModifiers.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_MODIFIERS -#define SKSL_MODIFIERS - -#include "include/private/SkSLLayout.h" - -#include -#include -#include - -namespace SkSL { - -class Context; -class Position; - -/** - * A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration. - */ -struct Modifiers { - /** - * OpenGL requires modifiers to be in a strict order: - * - invariant-qualifier: (invariant) - * - interpolation-qualifier: flat, noperspective, (smooth) - * - storage-qualifier: const, uniform - * - parameter-qualifier: in, out, inout - * - precision-qualifier: highp, mediump, lowp - * - * SkSL does not have `invariant` or `smooth`. - */ - - enum Flag { - kNo_Flag = 0, - // Real GLSL modifiers - kFlat_Flag = 1 << 0, - kNoPerspective_Flag = 1 << 1, - kConst_Flag = 1 << 2, - kUniform_Flag = 1 << 3, - kIn_Flag = 1 << 4, - kOut_Flag = 1 << 5, - kHighp_Flag = 1 << 6, - kMediump_Flag = 1 << 7, - kLowp_Flag = 1 << 8, - kReadOnly_Flag = 1 << 9, - kWriteOnly_Flag = 1 << 10, - kBuffer_Flag = 1 << 11, - // We use the Metal name for this one (corresponds to the GLSL 'shared' modifier) - kThreadgroup_Flag = 1 << 12, - // SkSL extensions, not present in GLSL - kExport_Flag = 1 << 13, - kES3_Flag = 1 << 14, - kPure_Flag = 1 << 15, - kInline_Flag = 1 << 16, - kNoInline_Flag = 1 << 17, - }; - - Modifiers() - : fLayout(Layout()) - , fFlags(0) {} - - Modifiers(const Layout& layout, int flags) - : fLayout(layout) - , fFlags(flags) {} - - std::string description() const { - return fLayout.description() + DescribeFlags(fFlags) + " "; - } - - static std::string DescribeFlags(int flags) { - // SkSL extensions - std::string result; - if (flags & kExport_Flag) { - result += "$export "; - } - if (flags & kES3_Flag) { - result += "$es3 "; - } - if (flags & kPure_Flag) { - result += "$pure "; - } - if (flags & kInline_Flag) { - result += "inline "; - } - if (flags & kNoInline_Flag) { - result += "noinline "; - } - - // Real GLSL qualifiers (must be specified in order in GLSL 4.1 and below) - if (flags & kFlat_Flag) { - result += "flat "; - } - if (flags & kNoPerspective_Flag) { - result += "noperspective "; - } - if (flags & kConst_Flag) { - result += "const "; - } - if (flags & kUniform_Flag) { - result += "uniform "; - } - if ((flags & kIn_Flag) && (flags & kOut_Flag)) { - result += "inout "; - } else if (flags & kIn_Flag) { - result += "in "; - } else if (flags & kOut_Flag) { - result += "out "; - } - if (flags & kHighp_Flag) { - result += "highp "; - } - if (flags & kMediump_Flag) { - result += "mediump "; - } - if (flags & kLowp_Flag) { - result += "lowp "; - } - if (flags & kReadOnly_Flag) { - result += "readonly "; - } - if (flags & kWriteOnly_Flag) { - result += "writeonly "; - } - if (flags & kBuffer_Flag) { - result += "buffer "; - } - - // We're using a non-GLSL name for this one; the GLSL equivalent is "shared" - if (flags & kThreadgroup_Flag) { - result += "threadgroup "; - } - - if (!result.empty()) { - result.pop_back(); - } - return result; - } - - bool operator==(const Modifiers& other) const { - return fLayout == other.fLayout && fFlags == other.fFlags; - } - - bool operator!=(const Modifiers& other) const { - return !(*this == other); - } - - /** - * Verifies that only permitted modifiers and layout flags are included. Reports errors and - * returns false in the event of a violation. - */ - bool checkPermitted(const Context& context, - Position pos, - int permittedModifierFlags, - int permittedLayoutFlags) const; - - Layout fLayout; - int fFlags; -}; - -} // namespace SkSL - -namespace std { - -template <> -struct hash { - size_t operator()(const SkSL::Modifiers& key) const { - return (size_t) key.fFlags ^ ((size_t) key.fLayout.fFlags << 8) ^ - ((size_t) key.fLayout.fBuiltin << 16); - } -}; - -} // namespace std - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h deleted file mode 100644 index 8eb0a31aadab6..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramElement.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_PROGRAMELEMENT -#define SKSL_PROGRAMELEMENT - -#include "include/private/SkSLIRNode.h" - -#include - -namespace SkSL { - -/** - * Represents a top-level element (e.g. function or global variable) in a program. - */ -class ProgramElement : public IRNode { -public: - enum class Kind { - kExtension = 0, - kFunction, - kFunctionPrototype, - kGlobalVar, - kInterfaceBlock, - kModifiers, - kStructDefinition, - - kFirst = kExtension, - kLast = kStructDefinition - }; - - ProgramElement(Position pos, Kind kind) - : INHERITED(pos, (int) kind) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - Kind kind() const { - return (Kind) fKind; - } - - /** - * Use is to check the type of a program element. - * e.g. replace `el.kind() == ProgramElement::Kind::kExtension` with `el.is()`. - */ - template - bool is() const { - return this->kind() == T::kProgramElementKind; - } - - /** - * Use as to downcast program elements. e.g. replace `(Extension&) el` with - * `el.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - - virtual std::unique_ptr clone() const = 0; - -private: - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h deleted file mode 100644 index c240cb7376e60..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLProgramKind.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSLProgramKind_DEFINED -#define SkSLProgramKind_DEFINED - -#include - -namespace SkSL { - -/** - * SkSL supports several different program kinds. - */ -enum class ProgramKind : int8_t { - kFragment, - kVertex, - kCompute, - kGraphiteFragment, - kGraphiteVertex, - kRuntimeColorFilter, // Runtime effect only suitable as SkColorFilter - kRuntimeShader, // " " " " " SkShader - kRuntimeBlender, // " " " " " SkBlender - kPrivateRuntimeShader, // Runtime shader with public restrictions lifted - kMeshVertex, // Vertex portion of a custom mesh - kMeshFragment, // Fragment " " " " " - kGeneric, -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h index a8d67a025a82d..39d9e258180e8 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSampleUsage.h @@ -10,8 +10,6 @@ #include "include/core/SkTypes.h" -#include - namespace SkSL { /** @@ -77,8 +75,6 @@ class SampleUsage { bool isUniformMatrix() const { return fKind == Kind::kUniformMatrix; } bool isFragCoord() const { return fKind == Kind::kFragCoord; } - std::string constructor() const; - private: Kind fKind = Kind::kNone; bool fHasPerspective = false; // Only valid if fKind is kUniformMatrix diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h deleted file mode 100644 index 43a1fdc8f3757..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLStatement.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_STATEMENT -#define SKSL_STATEMENT - -#include "include/private/SkSLIRNode.h" -#include "include/private/SkSLSymbol.h" - -namespace SkSL { - -/** - * Abstract supertype of all statements. - */ -class Statement : public IRNode { -public: - enum Kind { - kBlock = (int) Symbol::Kind::kLast + 1, - kBreak, - kContinue, - kDiscard, - kDo, - kExpression, - kFor, - kIf, - kNop, - kReturn, - kSwitch, - kSwitchCase, - kVarDeclaration, - - kFirst = kBlock, - kLast = kVarDeclaration, - }; - - Statement(Position pos, Kind kind) - : INHERITED(pos, (int) kind) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - Kind kind() const { - return (Kind) fKind; - } - - /** - * Use is to check the type of a statement. - * e.g. replace `s.kind() == Statement::Kind::kReturn` with `s.is()`. - */ - template - bool is() const { - return this->fKind == T::kStatementKind; - } - - /** - * Use as to downcast statements. - * e.g. replace `(ReturnStatement&) s` with `s.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - - virtual bool isEmpty() const { - return false; - } - - virtual std::unique_ptr clone() const = 0; - -private: - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h deleted file mode 100644 index 4458a2f0f5b45..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLString.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_STRING -#define SKSL_STRING - -#include "include/core/SkTypes.h" -#include "include/private/SkSLDefines.h" - -#include -#include -#include - -namespace SkSL { - -bool stod(std::string_view s, SKSL_FLOAT* value); -bool stoi(std::string_view s, SKSL_INT* value); - -namespace String { - -std::string printf(const char* fmt, ...) SK_PRINTF_LIKE(1, 2); -void appendf(std::string* str, const char* fmt, ...) SK_PRINTF_LIKE(2, 3); -void vappendf(std::string* str, const char* fmt, va_list va) SK_PRINTF_LIKE(2, 0); - -} // namespace String -} // namespace SkSL - -namespace skstd { - -// We use a custom to_string(float|double) which ignores locale settings and writes `1.0` instead -// of `1.00000`. -std::string to_string(float value); -std::string to_string(double value); - -} // namespace skstd - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h deleted file mode 100644 index d7b40c8d11ae7..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSLSymbol.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_SYMBOL -#define SKSL_SYMBOL - -#include "include/private/SkSLIRNode.h" -#include "include/private/SkSLProgramElement.h" - -namespace SkSL { - -/** - * Represents a symboltable entry. - */ -class Symbol : public IRNode { -public: - enum class Kind { - kExternal = (int) ProgramElement::Kind::kLast + 1, - kField, - kFunctionDeclaration, - kType, - kVariable, - - kFirst = kExternal, - kLast = kVariable - }; - - Symbol(Position pos, Kind kind, std::string_view name, const Type* type = nullptr) - : INHERITED(pos, (int) kind) - , fName(name) - , fType(type) { - SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); - } - - ~Symbol() override {} - - const Type& type() const { - SkASSERT(fType); - return *fType; - } - - Kind kind() const { - return (Kind) fKind; - } - - std::string_view name() const { - return fName; - } - - /** - * Don't call this directly--use SymbolTable::renameSymbol instead! - */ - void setName(std::string_view newName) { - fName = newName; - } - - /** - * Use is to check the type of a symbol. - * e.g. replace `sym.kind() == Symbol::Kind::kVariable` with `sym.is()`. - */ - template - bool is() const { - return this->kind() == T::kSymbolKind; - } - - /** - * Use as to downcast symbols. e.g. replace `(Variable&) sym` with `sym.as()`. - */ - template - const T& as() const { - SkASSERT(this->is()); - return static_cast(*this); - } - - template - T& as() { - SkASSERT(this->is()); - return static_cast(*this); - } - -private: - std::string_view fName; - const Type* fType; - - using INHERITED = IRNode; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h deleted file mode 100644 index 144b28a4a3b3a..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSafe_math.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSafe_math_DEFINED -#define SkSafe_math_DEFINED - -// This file protects against known bugs in ucrt\math.h. -// Namely, that header defines inline methods without marking them static, -// which makes it very easy to cause ODR violations and ensuing chaos. -// -// TODO: other headers? Here are some potential problem headers: -// $ grep -R __inline * | grep -v static | cut -f 1 -d: | sort | uniq -// corecrt.h -// corecrt_stdio_config.h -// ctype.h -// fenv.h -// locale.h -// malloc.h -// math.h -// tchar.h -// wchar.h -// I took a quick look through other headers outside math.h. -// Nothing looks anywhere near as likely to be used by Skia as math.h. - -#if defined(_MSC_VER) && !defined(_INC_MATH) - // Our strategy here is to simply inject "static" into the headers - // where it should have been written, just before __inline. - // - // Most inline-but-not-static methods in math.h are 32-bit only, - // but not all of them (see frexpf, hypothf, ldexpf...). So to - // be safe, 32- and 64-bit builds both get this treatment. - - #define __inline static __inline - #include - #undef __inline - - #if !defined(_INC_MATH) - #error Hmm. Looks like math.h has changed its header guards. - #endif - - #define INC_MATH_IS_SAFE_NOW - -#else - #include - -#endif - -#endif//SkSafe_math_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h index e1d5011681e5f..3816dc9dff022 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSpinlock.h @@ -9,7 +9,7 @@ #define SkSpinlock_DEFINED #include "include/core/SkTypes.h" -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkThreadAnnotations.h" #include class SK_CAPABILITY("mutex") SkSpinlock { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h deleted file mode 100644 index bf2f3da25eb60..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkStringView.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkStringView_DEFINED -#define SkStringView_DEFINED - -#include -#include - -namespace skstd { - -// C++20 additions -inline constexpr bool starts_with(std::string_view str, std::string_view prefix) { - if (prefix.length() > str.length()) { - return false; - } - return prefix.length() == 0 || !memcmp(str.data(), prefix.data(), prefix.length()); -} - -inline constexpr bool starts_with(std::string_view str, std::string_view::value_type c) { - return !str.empty() && str.front() == c; -} - -inline constexpr bool ends_with(std::string_view str, std::string_view suffix) { - if (suffix.length() > str.length()) { - return false; - } - return suffix.length() == 0 || !memcmp(str.data() + str.length() - suffix.length(), - suffix.data(), suffix.length()); -} - -inline constexpr bool ends_with(std::string_view str, std::string_view::value_type c) { - return !str.empty() && str.back() == c; -} - -// C++23 additions -inline constexpr bool contains(std::string_view str, std::string_view needle) { - return str.find(needle) != std::string_view::npos; -} - -inline constexpr bool contains(std::string_view str, std::string_view::value_type c) { - return str.find(c) != std::string_view::npos; -} - -} // namespace skstd - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h deleted file mode 100644 index 5082669c4f3d6..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTArray.h +++ /dev/null @@ -1,655 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkTArray_DEFINED -#define SkTArray_DEFINED - -#include "include/core/SkMath.h" -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkSafe32.h" -#include "include/private/SkTLogic.h" -#include "include/private/SkTemplates.h" -#include "include/private/SkTo.h" - -#include -#include -#include -#include -#include -#include - -/** SkTArray implements a typical, mostly std::vector-like array. - Each T will be default-initialized on allocation, and ~T will be called on destruction. - - MEM_MOVE controls the behavior when a T needs to be moved (e.g. when the array is resized) - - true: T will be bit-copied via memcpy. - - false: T will be moved via move-constructors. - - Modern implementations of std::vector will generally provide similar performance - characteristics when used with appropriate care. Consider using std::vector in new code. -*/ -template ::value> class SkTArray { -private: - enum ReallocType { kExactFit, kGrowing, kShrinking }; - -public: - using value_type = T; - - /** - * Creates an empty array with no initial storage - */ - SkTArray() { this->init(0); } - - /** - * Creates an empty array that will preallocate space for reserveCount - * elements. - */ - explicit SkTArray(int reserveCount) : SkTArray() { this->reserve_back(reserveCount); } - - /** - * Copies one array to another. The new array will be heap allocated. - */ - SkTArray(const SkTArray& that) - : SkTArray(that.fItemArray, that.fCount) {} - - SkTArray(SkTArray&& that) { - if (that.fOwnMemory) { - fItemArray = that.fItemArray; - fCount = that.fCount; - fAllocCount = that.fAllocCount; - fOwnMemory = true; - fReserved = that.fReserved; - - that.fItemArray = nullptr; - that.fCount = 0; - that.fAllocCount = 0; - that.fOwnMemory = true; - that.fReserved = false; - } else { - this->init(that.fCount); - that.move(fItemArray); - that.fCount = 0; - } - } - - /** - * Creates a SkTArray by copying contents of a standard C array. The new - * array will be heap allocated. Be careful not to use this constructor - * when you really want the (void*, int) version. - */ - SkTArray(const T* array, int count) { - this->init(count); - this->copy(array); - } - /** - * Creates a SkTArray by copying contents of an initializer list. - */ - SkTArray(std::initializer_list data) - : SkTArray(data.begin(), data.size()) {} - - SkTArray& operator=(const SkTArray& that) { - if (this == &that) { - return *this; - } - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(that.count(), kExactFit); - fCount = that.fCount; - this->copy(that.fItemArray); - return *this; - } - SkTArray& operator=(SkTArray&& that) { - if (this == &that) { - return *this; - } - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(that.count(), kExactFit); - fCount = that.fCount; - that.move(fItemArray); - that.fCount = 0; - return *this; - } - - ~SkTArray() { - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - if (fOwnMemory) { - sk_free(fItemArray); - } - } - - /** - * Resets to count() == 0 and resets any reserve count. - */ - void reset() { - this->pop_back_n(fCount); - fReserved = false; - } - - /** - * Resets to count() = n newly constructed T objects and resets any reserve count. - */ - void reset(int n) { - SkASSERT(n >= 0); - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - // Set fCount to 0 before calling checkRealloc so that no elements are moved. - fCount = 0; - this->checkRealloc(n, kExactFit); - fCount = n; - for (int i = 0; i < this->count(); ++i) { - new (fItemArray + i) T; - } - fReserved = false; - } - - /** - * Resets to a copy of a C array and resets any reserve count. - */ - void reset(const T* array, int count) { - for (int i = 0; i < this->count(); ++i) { - fItemArray[i].~T(); - } - fCount = 0; - this->checkRealloc(count, kExactFit); - fCount = count; - this->copy(array); - fReserved = false; - } - - /** - * Ensures there is enough reserved space for n additional elements. The is guaranteed at least - * until the array size grows above n and subsequently shrinks below n, any version of reset() - * is called, or reserve_back() is called again. - */ - void reserve_back(int n) { - SkASSERT(n >= 0); - if (n > 0) { - this->checkRealloc(n, kExactFit); - fReserved = fOwnMemory; - } else { - fReserved = false; - } - } - - void removeShuffle(int n) { - SkASSERT(n < this->count()); - int newCount = fCount - 1; - fCount = newCount; - fItemArray[n].~T(); - if (n != newCount) { - this->move(n, newCount); - } - } - - /** - * Number of elements in the array. - */ - int count() const { return fCount; } - - /** - * Is the array empty. - */ - bool empty() const { return !fCount; } - - /** - * Adds 1 new default-initialized T value and returns it by reference. Note - * the reference only remains valid until the next call that adds or removes - * elements. - */ - T& push_back() { - void* newT = this->push_back_raw(1); - return *new (newT) T; - } - - /** - * Version of above that uses a copy constructor to initialize the new item - */ - T& push_back(const T& t) { - void* newT = this->push_back_raw(1); - return *new (newT) T(t); - } - - /** - * Version of above that uses a move constructor to initialize the new item - */ - T& push_back(T&& t) { - void* newT = this->push_back_raw(1); - return *new (newT) T(std::move(t)); - } - - /** - * Construct a new T at the back of this array. - */ - template T& emplace_back(Args&&... args) { - void* newT = this->push_back_raw(1); - return *new (newT) T(std::forward(args)...); - } - - /** - * Allocates n more default-initialized T values, and returns the address of - * the start of that new range. Note: this address is only valid until the - * next API call made on the array that might add or remove elements. - */ - T* push_back_n(int n) { - SkASSERT(n >= 0); - void* newTs = this->push_back_raw(n); - for (int i = 0; i < n; ++i) { - new (static_cast(newTs) + i * sizeof(T)) T; - } - return static_cast(newTs); - } - - /** - * Version of above that uses a copy constructor to initialize all n items - * to the same T. - */ - T* push_back_n(int n, const T& t) { - SkASSERT(n >= 0); - void* newTs = this->push_back_raw(n); - for (int i = 0; i < n; ++i) { - new (static_cast(newTs) + i * sizeof(T)) T(t); - } - return static_cast(newTs); - } - - /** - * Version of above that uses a copy constructor to initialize the n items - * to separate T values. - */ - T* push_back_n(int n, const T t[]) { - SkASSERT(n >= 0); - this->checkRealloc(n, kGrowing); - for (int i = 0; i < n; ++i) { - new (fItemArray + fCount + i) T(t[i]); - } - fCount += n; - return fItemArray + fCount - n; - } - - /** - * Version of above that uses the move constructor to set n items. - */ - T* move_back_n(int n, T* t) { - SkASSERT(n >= 0); - this->checkRealloc(n, kGrowing); - for (int i = 0; i < n; ++i) { - new (fItemArray + fCount + i) T(std::move(t[i])); - } - fCount += n; - return fItemArray + fCount - n; - } - - /** - * Removes the last element. Not safe to call when count() == 0. - */ - void pop_back() { - SkASSERT(fCount > 0); - --fCount; - fItemArray[fCount].~T(); - this->checkRealloc(0, kShrinking); - } - - /** - * Removes the last n elements. Not safe to call when count() < n. - */ - void pop_back_n(int n) { - SkASSERT(n >= 0); - SkASSERT(this->count() >= n); - fCount -= n; - for (int i = 0; i < n; ++i) { - fItemArray[fCount + i].~T(); - } - this->checkRealloc(0, kShrinking); - } - - /** - * Pushes or pops from the back to resize. Pushes will be default - * initialized. - */ - void resize_back(int newCount) { - SkASSERT(newCount >= 0); - - if (newCount > this->count()) { - this->push_back_n(newCount - fCount); - } else if (newCount < this->count()) { - this->pop_back_n(fCount - newCount); - } - } - - /** Swaps the contents of this array with that array. Does a pointer swap if possible, - otherwise copies the T values. */ - void swap(SkTArray& that) { - using std::swap; - if (this == &that) { - return; - } - if (fOwnMemory && that.fOwnMemory) { - swap(fItemArray, that.fItemArray); - - auto count = fCount; - fCount = that.fCount; - that.fCount = count; - - auto allocCount = fAllocCount; - fAllocCount = that.fAllocCount; - that.fAllocCount = allocCount; - } else { - // This could be more optimal... - SkTArray copy(std::move(that)); - that = std::move(*this); - *this = std::move(copy); - } - } - - T* begin() { - return fItemArray; - } - const T* begin() const { - return fItemArray; - } - T* end() { - return fItemArray ? fItemArray + fCount : nullptr; - } - const T* end() const { - return fItemArray ? fItemArray + fCount : nullptr; - } - T* data() { return fItemArray; } - const T* data() const { return fItemArray; } - size_t size() const { return (size_t)fCount; } - void resize(size_t count) { this->resize_back((int)count); } - - /** - * Get the i^th element. - */ - T& operator[] (int i) { - SkASSERT(i < this->count()); - SkASSERT(i >= 0); - return fItemArray[i]; - } - - const T& operator[] (int i) const { - SkASSERT(i < this->count()); - SkASSERT(i >= 0); - return fItemArray[i]; - } - - T& at(int i) { return (*this)[i]; } - const T& at(int i) const { return (*this)[i]; } - - /** - * equivalent to operator[](0) - */ - T& front() { SkASSERT(fCount > 0); return fItemArray[0];} - - const T& front() const { SkASSERT(fCount > 0); return fItemArray[0];} - - /** - * equivalent to operator[](count() - 1) - */ - T& back() { SkASSERT(fCount); return fItemArray[fCount - 1];} - - const T& back() const { SkASSERT(fCount > 0); return fItemArray[fCount - 1];} - - /** - * equivalent to operator[](count()-1-i) - */ - T& fromBack(int i) { - SkASSERT(i >= 0); - SkASSERT(i < this->count()); - return fItemArray[fCount - i - 1]; - } - - const T& fromBack(int i) const { - SkASSERT(i >= 0); - SkASSERT(i < this->count()); - return fItemArray[fCount - i - 1]; - } - - bool operator==(const SkTArray& right) const { - int leftCount = this->count(); - if (leftCount != right.count()) { - return false; - } - for (int index = 0; index < leftCount; ++index) { - if (fItemArray[index] != right.fItemArray[index]) { - return false; - } - } - return true; - } - - bool operator!=(const SkTArray& right) const { - return !(*this == right); - } - - int capacity() const { - return fAllocCount; - } - -protected: - /** - * Creates an empty array that will use the passed storage block until it - * is insufficiently large to hold the entire array. - */ - template - SkTArray(SkAlignedSTStorage* storage) { - this->initWithPreallocatedStorage(0, storage->get(), N); - } - - /** - * Copy a C array, using preallocated storage if preAllocCount >= - * count. Otherwise storage will only be used when array shrinks - * to fit. - */ - template - SkTArray(const T* array, int count, SkAlignedSTStorage* storage) { - this->initWithPreallocatedStorage(count, storage->get(), N); - this->copy(array); - } - -private: - // We disable Control-Flow Integrity sanitization (go/cfi) when casting item-array buffers. - // CFI flags this code as dangerous because we are casting `buffer` to a T* while the buffer's - // contents might still be uninitialized memory. When T has a vtable, this is especially risky - // because we could hypothetically access a virtual method on fItemArray and jump to an - // unpredictable location in memory. Of course, SkTArray won't actually use fItemArray in this - // way, and we don't want to construct a T before the user requests one. There's no real risk - // here, so disable CFI when doing these casts. - SK_ATTRIBUTE(no_sanitize("cfi")) - static T* TCast(void* buffer) { - return (T*)buffer; - } - - void init(int count) { - fCount = SkToU32(count); - if (!count) { - fAllocCount = 0; - fItemArray = nullptr; - } else { - fAllocCount = SkToU32(std::max(count, kMinHeapAllocCount)); - fItemArray = TCast(sk_malloc_throw((size_t)fAllocCount, sizeof(T))); - } - fOwnMemory = true; - fReserved = false; - } - - void initWithPreallocatedStorage(int count, void* preallocStorage, int preallocCount) { - SkASSERT(count >= 0); - SkASSERT(preallocCount > 0); - SkASSERT(preallocStorage); - fCount = SkToU32(count); - fItemArray = nullptr; - fReserved = false; - if (count > preallocCount) { - fAllocCount = SkToU32(std::max(count, kMinHeapAllocCount)); - fItemArray = TCast(sk_malloc_throw(fAllocCount, sizeof(T))); - fOwnMemory = true; - } else { - fAllocCount = SkToU32(preallocCount); - fItemArray = TCast(preallocStorage); - fOwnMemory = false; - } - } - - /** In the following move and copy methods, 'dst' is assumed to be uninitialized raw storage. - * In the following move methods, 'src' is destroyed leaving behind uninitialized raw storage. - */ - void copy(const T* src) { - // Some types may be trivially copyable, in which case we *could* use memcopy; but - // MEM_MOVE == true implies that the type is trivially movable, and not necessarily - // trivially copyable (think sk_sp<>). So short of adding another template arg, we - // must be conservative and use copy construction. - for (int i = 0; i < this->count(); ++i) { - new (fItemArray + i) T(src[i]); - } - } - - template std::enable_if_t move(int dst, int src) { - memcpy(static_cast(&fItemArray[dst]), - static_cast(&fItemArray[src]), - sizeof(T)); - } - template std::enable_if_t move(void* dst) { - sk_careful_memcpy(dst, fItemArray, fCount * sizeof(T)); - } - - template std::enable_if_t move(int dst, int src) { - new (&fItemArray[dst]) T(std::move(fItemArray[src])); - fItemArray[src].~T(); - } - template std::enable_if_t move(void* dst) { - for (int i = 0; i < this->count(); ++i) { - new (static_cast(dst) + sizeof(T) * (size_t)i) T(std::move(fItemArray[i])); - fItemArray[i].~T(); - } - } - - static constexpr int kMinHeapAllocCount = 8; - - // Helper function that makes space for n objects, adjusts the count, but does not initialize - // the new objects. - void* push_back_raw(int n) { - this->checkRealloc(n, kGrowing); - void* ptr = fItemArray + fCount; - fCount += n; - return ptr; - } - - void checkRealloc(int delta, ReallocType reallocType) { - SkASSERT(fCount >= 0); - SkASSERT(fAllocCount >= 0); - SkASSERT(-delta <= this->count()); - - // Move into 64bit math temporarily, to avoid local overflows - int64_t newCount = fCount + delta; - - // We allow fAllocCount to be in the range [newCount, 3*newCount]. We also never shrink - // when we're currently using preallocated memory, would allocate less than - // kMinHeapAllocCount, or a reserve count was specified that has yet to be exceeded. - bool mustGrow = newCount > fAllocCount; - bool shouldShrink = fAllocCount > 3 * newCount && fOwnMemory && !fReserved; - if (!mustGrow && !shouldShrink) { - return; - } - - int64_t newAllocCount = newCount; - if (reallocType != kExactFit) { - // Whether we're growing or shrinking, leave at least 50% extra space for future growth. - newAllocCount += ((newCount + 1) >> 1); - // Align the new allocation count to kMinHeapAllocCount. - static_assert(SkIsPow2(kMinHeapAllocCount), "min alloc count not power of two."); - newAllocCount = (newAllocCount + (kMinHeapAllocCount - 1)) & ~(kMinHeapAllocCount - 1); - } - - // At small sizes the old and new alloc count can both be kMinHeapAllocCount. - if (newAllocCount == fAllocCount) { - return; - } - - fAllocCount = SkToU32(Sk64_pin_to_s32(newAllocCount)); - SkASSERT(fAllocCount >= newCount); - T* newItemArray = TCast(sk_malloc_throw((size_t)fAllocCount, sizeof(T))); - this->move(newItemArray); - if (fOwnMemory) { - sk_free(fItemArray); - } - fItemArray = newItemArray; - fOwnMemory = true; - fReserved = false; - } - - T* fItemArray; - uint32_t fOwnMemory : 1; - uint32_t fCount : 31; - uint32_t fReserved : 1; - uint32_t fAllocCount : 31; -}; - -template static inline void swap(SkTArray& a, SkTArray& b) { - a.swap(b); -} - -template constexpr int SkTArray::kMinHeapAllocCount; - -/** - * Subclass of SkTArray that contains a preallocated memory block for the array. - */ -template ::value> -class SkSTArray : private SkAlignedSTStorage, public SkTArray { -private: - using STORAGE = SkAlignedSTStorage; - using INHERITED = SkTArray; - -public: - SkSTArray() - : STORAGE{}, INHERITED(static_cast(this)) {} - - SkSTArray(const T* array, int count) - : STORAGE{}, INHERITED(array, count, static_cast(this)) {} - - SkSTArray(std::initializer_list data) - : SkSTArray(data.begin(), data.size()) {} - - explicit SkSTArray(int reserveCount) - : SkSTArray() { - this->reserve_back(reserveCount); - } - - SkSTArray (const SkSTArray& that) : SkSTArray() { *this = that; } - explicit SkSTArray(const INHERITED& that) : SkSTArray() { *this = that; } - SkSTArray ( SkSTArray&& that) : SkSTArray() { *this = std::move(that); } - explicit SkSTArray( INHERITED&& that) : SkSTArray() { *this = std::move(that); } - - SkSTArray& operator=(const SkSTArray& that) { - INHERITED::operator=(that); - return *this; - } - SkSTArray& operator=(const INHERITED& that) { - INHERITED::operator=(that); - return *this; - } - - SkSTArray& operator=(SkSTArray&& that) { - INHERITED::operator=(std::move(that)); - return *this; - } - SkSTArray& operator=(INHERITED&& that) { - INHERITED::operator=(std::move(that)); - return *this; - } -}; - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h deleted file mode 100644 index 2cd89fd2f4df5..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkUniquePaintParamsID.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 SkUniquePaintParamsID_DEFINED -#define SkUniquePaintParamsID_DEFINED - -#include "include/core/SkTypes.h" - -// This class boils down to a unique uint that can be used instead of a variable length -// key derived from a PaintParams. -class SkUniquePaintParamsID { -public: - explicit SkUniquePaintParamsID(uint32_t id) : fID(id) { - SkASSERT(id != SK_InvalidUniqueID); - } - - static SkUniquePaintParamsID InvalidID() { return SkUniquePaintParamsID(); } - - SkUniquePaintParamsID() : fID(SK_InvalidUniqueID) {} - - bool operator==(const SkUniquePaintParamsID &that) const { return fID == that.fID; } - bool operator!=(const SkUniquePaintParamsID &that) const { return !(*this == that); } - - bool isValid() const { return fID != SK_InvalidUniqueID; } - uint32_t asUInt() const { return fID; } - -private: - uint32_t fID; -}; - -#endif // SkUniquePaintParamsID_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h deleted file mode 100644 index 74cdabffe2d0c..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkVx.h +++ /dev/null @@ -1,1026 +0,0 @@ -/* - * Copyright 2019 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKVX_DEFINED -#define SKVX_DEFINED - -// skvx::Vec are SIMD vectors of N T's, a v1.5 successor to SkNx. -// -// This time we're leaning a bit less on platform-specific intrinsics and a bit -// more on Clang/GCC vector extensions, but still keeping the option open to -// drop in platform-specific intrinsics, actually more easily than before. -// -// We've also fixed a few of the caveats that used to make SkNx awkward to work -// with across translation units. skvx::Vec always has N*sizeof(T) size -// and alignment and is safe to use across translation units freely. -// (Ideally we'd only align to T, but that tanks ARMv7 NEON codegen.) - -// Please try to keep this file independent of Skia headers. -#include // std::min, std::max -#include // assert() -#include // ceilf, floorf, truncf, roundf, sqrtf, etc. -#include // intXX_t -#include // memcpy() -#include // std::initializer_list -#include // std::index_sequence - -// Users may disable SIMD with SKNX_NO_SIMD, which may be set via compiler flags. -// The gn build has no option which sets SKNX_NO_SIMD. -// Use SKVX_USE_SIMD internally to avoid confusing double negation. -// Do not use 'defined' in a macro expansion. -#if !defined(SKNX_NO_SIMD) - #define SKVX_USE_SIMD 1 -#else - #define SKVX_USE_SIMD 0 -#endif - -#if SKVX_USE_SIMD - #if defined(__SSE__) || defined(__AVX__) || defined(__AVX2__) - #include - #elif defined(__ARM_NEON) - #include - #elif defined(__wasm_simd128__) - #include - #endif -#endif - -// To avoid ODR violations, all methods must be force-inlined... -#if defined(_MSC_VER) - #define SKVX_ALWAYS_INLINE __forceinline -#else - #define SKVX_ALWAYS_INLINE __attribute__((always_inline)) -#endif - -// ... and all standalone functions must be static. Please use these helpers: -#define SI static inline -#define SIT template < typename T> SI -#define SIN template SI -#define SINT template SI -#define SINTU template ::value>> SI - -namespace skvx { - -template -struct alignas(N*sizeof(T)) Vec; - -template -SI Vec shuffle(const Vec&); - -template -SI D bit_pun(const S&); - -// All Vec have the same simple memory layout, the same as `T vec[N]`. -template -struct alignas(N*sizeof(T)) VecStorage { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - - Vec lo, hi; -}; - -template -struct VecStorage<4,T> { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y, T z, T w) : lo(x,y), hi(z, w) {} - SKVX_ALWAYS_INLINE VecStorage(Vec<2,T> xy, T z, T w) : lo(xy), hi(z,w) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y, Vec<2,T> zw) : lo(x,y), hi(zw) {} - SKVX_ALWAYS_INLINE VecStorage(Vec<2,T> xy, Vec<2,T> zw) : lo(xy), hi(zw) {} - - SKVX_ALWAYS_INLINE Vec<2,T>& xy() { return lo; } - SKVX_ALWAYS_INLINE Vec<2,T>& zw() { return hi; } - SKVX_ALWAYS_INLINE T& x() { return lo.lo.val; } - SKVX_ALWAYS_INLINE T& y() { return lo.hi.val; } - SKVX_ALWAYS_INLINE T& z() { return hi.lo.val; } - SKVX_ALWAYS_INLINE T& w() { return hi.hi.val; } - - SKVX_ALWAYS_INLINE Vec<2,T> xy() const { return lo; } - SKVX_ALWAYS_INLINE Vec<2,T> zw() const { return hi; } - SKVX_ALWAYS_INLINE T x() const { return lo.lo.val; } - SKVX_ALWAYS_INLINE T y() const { return lo.hi.val; } - SKVX_ALWAYS_INLINE T z() const { return hi.lo.val; } - SKVX_ALWAYS_INLINE T w() const { return hi.hi.val; } - - // Exchange-based swizzles. These should take 1 cycle on NEON and 3 (pipelined) cycles on SSE. - SKVX_ALWAYS_INLINE Vec<4,T> yxwz() const { return shuffle<1,0,3,2>(bit_pun>(*this)); } - SKVX_ALWAYS_INLINE Vec<4,T> zwxy() const { return shuffle<2,3,0,1>(bit_pun>(*this)); } - - Vec<2,T> lo, hi; -}; - -template -struct VecStorage<2,T> { - SKVX_ALWAYS_INLINE VecStorage() = default; - SKVX_ALWAYS_INLINE VecStorage(T s) : lo(s), hi(s) {} - SKVX_ALWAYS_INLINE VecStorage(T x, T y) : lo(x), hi(y) {} - - SKVX_ALWAYS_INLINE T& x() { return lo.val; } - SKVX_ALWAYS_INLINE T& y() { return hi.val; } - - SKVX_ALWAYS_INLINE T x() const { return lo.val; } - SKVX_ALWAYS_INLINE T y() const { return hi.val; } - - // This exchange-based swizzle should take 1 cycle on NEON and 3 (pipelined) cycles on SSE. - SKVX_ALWAYS_INLINE Vec<2,T> yx() const { return shuffle<1,0>(bit_pun>(*this)); } - - SKVX_ALWAYS_INLINE Vec<4,T> xyxy() const { - return Vec<4,T>(bit_pun>(*this), bit_pun>(*this)); - } - - Vec<1,T> lo, hi; -}; - -template -struct alignas(N*sizeof(T)) Vec : public VecStorage { - static_assert((N & (N-1)) == 0, "N must be a power of 2."); - static_assert(sizeof(T) >= alignof(T), "What kind of unusual T is this?"); - - // Methods belong here in the class declaration of Vec only if: - // - they must be here, like constructors or operator[]; - // - they'll definitely never want a specialized implementation. - // Other operations on Vec should be defined outside the type. - - SKVX_ALWAYS_INLINE Vec() = default; - - using VecStorage::VecStorage; - - // NOTE: Vec{x} produces x000..., whereas Vec(x) produces xxxx.... since this constructor fills - // unspecified lanes with 0s, whereas the single T constructor fills all lanes with the value. - SKVX_ALWAYS_INLINE Vec(std::initializer_list xs) { - T vals[N] = {0}; - memcpy(vals, xs.begin(), std::min(xs.size(), (size_t)N)*sizeof(T)); - - this->lo = Vec::Load(vals + 0); - this->hi = Vec::Load(vals + N/2); - } - - SKVX_ALWAYS_INLINE T operator[](int i) const { return ilo[i] : this->hi[i-N/2]; } - SKVX_ALWAYS_INLINE T& operator[](int i) { return ilo[i] : this->hi[i-N/2]; } - - SKVX_ALWAYS_INLINE static Vec Load(const void* ptr) { - Vec v; - memcpy(&v, ptr, sizeof(Vec)); - return v; - } - SKVX_ALWAYS_INLINE void store(void* ptr) const { - memcpy(ptr, this, sizeof(Vec)); - } -}; - -template -struct Vec<1,T> { - T val; - - SKVX_ALWAYS_INLINE Vec() = default; - - Vec(T s) : val(s) {} - - SKVX_ALWAYS_INLINE Vec(std::initializer_list xs) : val(xs.size() ? *xs.begin() : 0) {} - - SKVX_ALWAYS_INLINE T operator[](int) const { return val; } - SKVX_ALWAYS_INLINE T& operator[](int) { return val; } - - SKVX_ALWAYS_INLINE static Vec Load(const void* ptr) { - Vec v; - memcpy(&v, ptr, sizeof(Vec)); - return v; - } - SKVX_ALWAYS_INLINE void store(void* ptr) const { - memcpy(ptr, this, sizeof(Vec)); - } -}; - -template -SI D bit_pun(const S& s) { - static_assert(sizeof(D) == sizeof(S)); - D d; - memcpy(&d, &s, sizeof(D)); - return d; -} - -// Translate from a value type T to its corresponding Mask, the result of a comparison. -template struct Mask { using type = T; }; -template <> struct Mask { using type = int32_t; }; -template <> struct Mask { using type = int64_t; }; -template using M = typename Mask::type; - -// Join two Vec into one Vec<2N,T>. -SINT Vec<2*N,T> join(const Vec& lo, const Vec& hi) { - Vec<2*N,T> v; - v.lo = lo; - v.hi = hi; - return v; -} - -// We have three strategies for implementing Vec operations: -// 1) lean on Clang/GCC vector extensions when available; -// 2) use map() to apply a scalar function lane-wise; -// 3) recurse on lo/hi to scalar portable implementations. -// We can slot in platform-specific implementations as overloads for particular Vec, -// or often integrate them directly into the recursion of style 3), allowing fine control. - -#if SKVX_USE_SIMD && (defined(__clang__) || defined(__GNUC__)) - - // VExt types have the same size as Vec and support most operations directly. - #if defined(__clang__) - template - using VExt = T __attribute__((ext_vector_type(N))); - - #elif defined(__GNUC__) - template - struct VExtHelper { - typedef T __attribute__((vector_size(N*sizeof(T)))) type; - }; - - template - using VExt = typename VExtHelper::type; - - // For some reason some (new!) versions of GCC cannot seem to deduce N in the generic - // to_vec() below for N=4 and T=float. This workaround seems to help... - SI Vec<4,float> to_vec(VExt<4,float> v) { return bit_pun>(v); } - #endif - - SINT VExt to_vext(const Vec& v) { return bit_pun>(v); } - SINT Vec to_vec(const VExt& v) { return bit_pun>(v); } - - SINT Vec operator+(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) + to_vext(y)); - } - SINT Vec operator-(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) - to_vext(y)); - } - SINT Vec operator*(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) * to_vext(y)); - } - SINT Vec operator/(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) / to_vext(y)); - } - - SINT Vec operator^(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) ^ to_vext(y)); - } - SINT Vec operator&(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) & to_vext(y)); - } - SINT Vec operator|(const Vec& x, const Vec& y) { - return to_vec(to_vext(x) | to_vext(y)); - } - - SINT Vec operator!(const Vec& x) { return to_vec(!to_vext(x)); } - SINT Vec operator-(const Vec& x) { return to_vec(-to_vext(x)); } - SINT Vec operator~(const Vec& x) { return to_vec(~to_vext(x)); } - - SINT Vec operator<<(const Vec& x, int k) { return to_vec(to_vext(x) << k); } - SINT Vec operator>>(const Vec& x, int k) { return to_vec(to_vext(x) >> k); } - - SINT Vec> operator==(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) == to_vext(y)); - } - SINT Vec> operator!=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) != to_vext(y)); - } - SINT Vec> operator<=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) <= to_vext(y)); - } - SINT Vec> operator>=(const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) >= to_vext(y)); - } - SINT Vec> operator< (const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) < to_vext(y)); - } - SINT Vec> operator> (const Vec& x, const Vec& y) { - return bit_pun>>(to_vext(x) > to_vext(y)); - } - -#else - - // Either SKNX_NO_SIMD is defined, or Clang/GCC vector extensions are not available. - // We'll implement things portably with N==1 scalar implementations and recursion onto them. - - // N == 1 scalar implementations. - SIT Vec<1,T> operator+(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val + y.val; } - SIT Vec<1,T> operator-(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val - y.val; } - SIT Vec<1,T> operator*(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val * y.val; } - SIT Vec<1,T> operator/(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val / y.val; } - - SIT Vec<1,T> operator^(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val ^ y.val; } - SIT Vec<1,T> operator&(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val & y.val; } - SIT Vec<1,T> operator|(const Vec<1,T>& x, const Vec<1,T>& y) { return x.val | y.val; } - - SIT Vec<1,T> operator!(const Vec<1,T>& x) { return !x.val; } - SIT Vec<1,T> operator-(const Vec<1,T>& x) { return -x.val; } - SIT Vec<1,T> operator~(const Vec<1,T>& x) { return ~x.val; } - - SIT Vec<1,T> operator<<(const Vec<1,T>& x, int k) { return x.val << k; } - SIT Vec<1,T> operator>>(const Vec<1,T>& x, int k) { return x.val >> k; } - - SIT Vec<1,M> operator==(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val == y.val ? ~0 : 0; - } - SIT Vec<1,M> operator!=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val != y.val ? ~0 : 0; - } - SIT Vec<1,M> operator<=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val <= y.val ? ~0 : 0; - } - SIT Vec<1,M> operator>=(const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val >= y.val ? ~0 : 0; - } - SIT Vec<1,M> operator< (const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val < y.val ? ~0 : 0; - } - SIT Vec<1,M> operator> (const Vec<1,T>& x, const Vec<1,T>& y) { - return x.val > y.val ? ~0 : 0; - } - - // Recurse on lo/hi down to N==1 scalar implementations. - SINT Vec operator+(const Vec& x, const Vec& y) { - return join(x.lo + y.lo, x.hi + y.hi); - } - SINT Vec operator-(const Vec& x, const Vec& y) { - return join(x.lo - y.lo, x.hi - y.hi); - } - SINT Vec operator*(const Vec& x, const Vec& y) { - return join(x.lo * y.lo, x.hi * y.hi); - } - SINT Vec operator/(const Vec& x, const Vec& y) { - return join(x.lo / y.lo, x.hi / y.hi); - } - - SINT Vec operator^(const Vec& x, const Vec& y) { - return join(x.lo ^ y.lo, x.hi ^ y.hi); - } - SINT Vec operator&(const Vec& x, const Vec& y) { - return join(x.lo & y.lo, x.hi & y.hi); - } - SINT Vec operator|(const Vec& x, const Vec& y) { - return join(x.lo | y.lo, x.hi | y.hi); - } - - SINT Vec operator!(const Vec& x) { return join(!x.lo, !x.hi); } - SINT Vec operator-(const Vec& x) { return join(-x.lo, -x.hi); } - SINT Vec operator~(const Vec& x) { return join(~x.lo, ~x.hi); } - - SINT Vec operator<<(const Vec& x, int k) { return join(x.lo << k, x.hi << k); } - SINT Vec operator>>(const Vec& x, int k) { return join(x.lo >> k, x.hi >> k); } - - SINT Vec> operator==(const Vec& x, const Vec& y) { - return join(x.lo == y.lo, x.hi == y.hi); - } - SINT Vec> operator!=(const Vec& x, const Vec& y) { - return join(x.lo != y.lo, x.hi != y.hi); - } - SINT Vec> operator<=(const Vec& x, const Vec& y) { - return join(x.lo <= y.lo, x.hi <= y.hi); - } - SINT Vec> operator>=(const Vec& x, const Vec& y) { - return join(x.lo >= y.lo, x.hi >= y.hi); - } - SINT Vec> operator< (const Vec& x, const Vec& y) { - return join(x.lo < y.lo, x.hi < y.hi); - } - SINT Vec> operator> (const Vec& x, const Vec& y) { - return join(x.lo > y.lo, x.hi > y.hi); - } -#endif - -// Scalar/vector operations splat the scalar to a vector. -SINTU Vec operator+ (U x, const Vec& y) { return Vec(x) + y; } -SINTU Vec operator- (U x, const Vec& y) { return Vec(x) - y; } -SINTU Vec operator* (U x, const Vec& y) { return Vec(x) * y; } -SINTU Vec operator/ (U x, const Vec& y) { return Vec(x) / y; } -SINTU Vec operator^ (U x, const Vec& y) { return Vec(x) ^ y; } -SINTU Vec operator& (U x, const Vec& y) { return Vec(x) & y; } -SINTU Vec operator| (U x, const Vec& y) { return Vec(x) | y; } -SINTU Vec> operator==(U x, const Vec& y) { return Vec(x) == y; } -SINTU Vec> operator!=(U x, const Vec& y) { return Vec(x) != y; } -SINTU Vec> operator<=(U x, const Vec& y) { return Vec(x) <= y; } -SINTU Vec> operator>=(U x, const Vec& y) { return Vec(x) >= y; } -SINTU Vec> operator< (U x, const Vec& y) { return Vec(x) < y; } -SINTU Vec> operator> (U x, const Vec& y) { return Vec(x) > y; } - -SINTU Vec operator+ (const Vec& x, U y) { return x + Vec(y); } -SINTU Vec operator- (const Vec& x, U y) { return x - Vec(y); } -SINTU Vec operator* (const Vec& x, U y) { return x * Vec(y); } -SINTU Vec operator/ (const Vec& x, U y) { return x / Vec(y); } -SINTU Vec operator^ (const Vec& x, U y) { return x ^ Vec(y); } -SINTU Vec operator& (const Vec& x, U y) { return x & Vec(y); } -SINTU Vec operator| (const Vec& x, U y) { return x | Vec(y); } -SINTU Vec> operator==(const Vec& x, U y) { return x == Vec(y); } -SINTU Vec> operator!=(const Vec& x, U y) { return x != Vec(y); } -SINTU Vec> operator<=(const Vec& x, U y) { return x <= Vec(y); } -SINTU Vec> operator>=(const Vec& x, U y) { return x >= Vec(y); } -SINTU Vec> operator< (const Vec& x, U y) { return x < Vec(y); } -SINTU Vec> operator> (const Vec& x, U y) { return x > Vec(y); } - -SINT Vec& operator+=(Vec& x, const Vec& y) { return (x = x + y); } -SINT Vec& operator-=(Vec& x, const Vec& y) { return (x = x - y); } -SINT Vec& operator*=(Vec& x, const Vec& y) { return (x = x * y); } -SINT Vec& operator/=(Vec& x, const Vec& y) { return (x = x / y); } -SINT Vec& operator^=(Vec& x, const Vec& y) { return (x = x ^ y); } -SINT Vec& operator&=(Vec& x, const Vec& y) { return (x = x & y); } -SINT Vec& operator|=(Vec& x, const Vec& y) { return (x = x | y); } - -SINTU Vec& operator+=(Vec& x, U y) { return (x = x + Vec(y)); } -SINTU Vec& operator-=(Vec& x, U y) { return (x = x - Vec(y)); } -SINTU Vec& operator*=(Vec& x, U y) { return (x = x * Vec(y)); } -SINTU Vec& operator/=(Vec& x, U y) { return (x = x / Vec(y)); } -SINTU Vec& operator^=(Vec& x, U y) { return (x = x ^ Vec(y)); } -SINTU Vec& operator&=(Vec& x, U y) { return (x = x & Vec(y)); } -SINTU Vec& operator|=(Vec& x, U y) { return (x = x | Vec(y)); } - -SINT Vec& operator<<=(Vec& x, int bits) { return (x = x << bits); } -SINT Vec& operator>>=(Vec& x, int bits) { return (x = x >> bits); } - -// Some operations we want are not expressible with Clang/GCC vector extensions. - -// Clang can reason about naive_if_then_else() and optimize through it better -// than if_then_else(), so it's sometimes useful to call it directly when we -// think an entire expression should optimize away, e.g. min()/max(). -SINT Vec naive_if_then_else(const Vec>& cond, const Vec& t, const Vec& e) { - return bit_pun>(( cond & bit_pun>>(t)) | - (~cond & bit_pun>>(e)) ); -} - -SIT Vec<1,T> if_then_else(const Vec<1,M>& cond, const Vec<1,T>& t, const Vec<1,T>& e) { - // In practice this scalar implementation is unlikely to be used. See next if_then_else(). - return bit_pun>(( cond & bit_pun>>(t)) | - (~cond & bit_pun>>(e)) ); -} -SINT Vec if_then_else(const Vec>& cond, const Vec& t, const Vec& e) { - // Specializations inline here so they can generalize what types the apply to. -#if SKVX_USE_SIMD && defined(__AVX2__) - if constexpr (N*sizeof(T) == 32) { - return bit_pun>(_mm256_blendv_epi8(bit_pun<__m256i>(e), - bit_pun<__m256i>(t), - bit_pun<__m256i>(cond))); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE4_1__) - if constexpr (N*sizeof(T) == 16) { - return bit_pun>(_mm_blendv_epi8(bit_pun<__m128i>(e), - bit_pun<__m128i>(t), - bit_pun<__m128i>(cond))); - } -#endif -#if SKVX_USE_SIMD && defined(__ARM_NEON) - if constexpr (N*sizeof(T) == 16) { - return bit_pun>(vbslq_u8(bit_pun(cond), - bit_pun(t), - bit_pun(e))); - } -#endif - // Recurse for large vectors to try to hit the specializations above. - if constexpr (N*sizeof(T) > 16) { - return join(if_then_else(cond.lo, t.lo, e.lo), - if_then_else(cond.hi, t.hi, e.hi)); - } - // This default can lead to better code than the recursing onto scalars. - return naive_if_then_else(cond, t, e); -} - -SIT bool any(const Vec<1,T>& x) { return x.val != 0; } -SINT bool any(const Vec& x) { - // For any(), the _mm_testz intrinsics are correct and don't require comparing 'x' to 0, so it's - // lower latency compared to _mm_movemask + _mm_compneq on plain SSE. -#if SKVX_USE_SIMD && defined(__AVX2__) - if constexpr (N*sizeof(T) == 32) { - return !_mm256_testz_si256(bit_pun<__m256i>(x), _mm256_set1_epi32(-1)); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE_4_1__) - if constexpr (N*sizeof(T) == 16) { - return !_mm_testz_si128(bit_pun<__m128i>(x), _mm_set1_epi32(-1)); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE__) - if constexpr (N*sizeof(T) == 16) { - // On SSE, movemask checks only the MSB in each lane, which is fine if the lanes were set - // directly from a comparison op (which sets all bits to 1 when true), but skvx::Vec<> - // treats any non-zero value as true, so we have to compare 'x' to 0 before calling movemask - return _mm_movemask_ps(_mm_cmpneq_ps(bit_pun<__m128>(x), _mm_set1_ps(0))) != 0b0000; - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - // On 64-bit NEON, take the max across lanes, which will be non-zero if any lane was true. - // The specific lane-size doesn't really matter in this case since it's really any set bit - // that we're looking for. - if constexpr (N*sizeof(T) == 8 ) { return vmaxv_u8 (bit_pun (x)) > 0; } - if constexpr (N*sizeof(T) == 16) { return vmaxvq_u8(bit_pun(x)) > 0; } -#endif -#if SKVX_USE_SIMD && defined(__wasm_simd128__) - if constexpr (N == 4 && sizeof(T) == 4) { - return wasm_i32x4_any_true(bit_pun>(x)); - } -#endif - return any(x.lo) - || any(x.hi); -} - -SIT bool all(const Vec<1,T>& x) { return x.val != 0; } -SINT bool all(const Vec& x) { -// Unlike any(), we have to respect the lane layout, or we'll miss cases where a -// true lane has a mix of 0 and 1 bits. -#if SKVX_USE_SIMD && defined(__SSE__) - // Unfortunately, the _mm_testc intrinsics don't let us avoid the comparison to 0 for all()'s - // correctness, so always just use the plain SSE version. - if constexpr (N == 4 && sizeof(T) == 4) { - return _mm_movemask_ps(_mm_cmpneq_ps(bit_pun<__m128>(x), _mm_set1_ps(0))) == 0b1111; - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - // On 64-bit NEON, take the min across the lanes, which will be non-zero if all lanes are != 0. - if constexpr (sizeof(T)==1 && N==8) {return vminv_u8 (bit_pun (x)) > 0;} - if constexpr (sizeof(T)==1 && N==16) {return vminvq_u8 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==2 && N==4) {return vminv_u16 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==2 && N==8) {return vminvq_u16(bit_pun(x)) > 0;} - if constexpr (sizeof(T)==4 && N==2) {return vminv_u32 (bit_pun(x)) > 0;} - if constexpr (sizeof(T)==4 && N==4) {return vminvq_u32(bit_pun(x)) > 0;} -#endif -#if SKVX_USE_SIMD && defined(__wasm_simd128__) - if constexpr (N == 4 && sizeof(T) == 4) { - return wasm_i32x4_all_true(bit_pun>(x)); - } -#endif - return all(x.lo) - && all(x.hi); -} - -// cast() Vec to Vec, as if applying a C-cast to each lane. -// TODO: implement with map()? -template -SI Vec<1,D> cast(const Vec<1,S>& src) { return (D)src.val; } - -template -SI Vec cast(const Vec& src) { -#if SKVX_USE_SIMD && defined(__clang__) - return to_vec(__builtin_convertvector(to_vext(src), VExt)); -#else - return join(cast(src.lo), cast(src.hi)); -#endif -} - -// min/max match logic of std::min/std::max, which is important when NaN is involved. -SIT T min(const Vec<1,T>& x) { return x.val; } -SIT T max(const Vec<1,T>& x) { return x.val; } -SINT T min(const Vec& x) { return std::min(min(x.lo), min(x.hi)); } -SINT T max(const Vec& x) { return std::max(max(x.lo), max(x.hi)); } - -SINT Vec min(const Vec& x, const Vec& y) { return naive_if_then_else(y < x, y, x); } -SINT Vec max(const Vec& x, const Vec& y) { return naive_if_then_else(x < y, y, x); } - -SINTU Vec min(const Vec& x, U y) { return min(x, Vec(y)); } -SINTU Vec max(const Vec& x, U y) { return max(x, Vec(y)); } -SINTU Vec min(U x, const Vec& y) { return min(Vec(x), y); } -SINTU Vec max(U x, const Vec& y) { return max(Vec(x), y); } - -// pin matches the logic of SkTPin, which is important when NaN is involved. It always returns -// values in the range lo..hi, and if x is NaN, it returns lo. -SINT Vec pin(const Vec& x, const Vec& lo, const Vec& hi) { - return max(lo, min(x, hi)); -} - -// Shuffle values from a vector pretty arbitrarily: -// skvx::Vec<4,float> rgba = {R,G,B,A}; -// shuffle<2,1,0,3> (rgba) ~> {B,G,R,A} -// shuffle<2,1> (rgba) ~> {B,G} -// shuffle<2,1,2,1,2,1,2,1>(rgba) ~> {B,G,B,G,B,G,B,G} -// shuffle<3,3,3,3> (rgba) ~> {A,A,A,A} -// The only real restriction is that the output also be a legal N=power-of-two sknx::Vec. -template -SI Vec shuffle(const Vec& x) { -#if SKVX_USE_SIMD && defined(__clang__) - // TODO: can we just always use { x[Ix]... }? - return to_vec(__builtin_shufflevector(to_vext(x), to_vext(x), Ix...)); -#else - return { x[Ix]... }; -#endif -} - -// Call map(fn, x) for a vector with fn() applied to each lane of x, { fn(x[0]), fn(x[1]), ... }, -// or map(fn, x,y) for a vector of fn(x[i], y[i]), etc. - -template -SI auto map(std::index_sequence, - Fn&& fn, const Args&... args) -> skvx::Vec { - auto lane = [&](size_t i) -#if defined(__clang__) - // CFI, specifically -fsanitize=cfi-icall, seems to give a false positive here, - // with errors like "control flow integrity check for type 'float (float) - // noexcept' failed during indirect function call... note: sqrtf.cfi_jt defined - // here". But we can be quite sure fn is the right type: it's all inferred! - // So, stifle CFI in this function. - __attribute__((no_sanitize("cfi"))) -#endif - { return fn(args[i]...); }; - - return { lane(I)... }; -} - -template -auto map(Fn&& fn, const Vec& first, const Rest&... rest) { - // Derive an {0...N-1} index_sequence from the size of the first arg: N lanes in, N lanes out. - return map(std::make_index_sequence{}, fn, first,rest...); -} - -SIN Vec ceil(const Vec& x) { return map( ceilf, x); } -SIN Vec floor(const Vec& x) { return map(floorf, x); } -SIN Vec trunc(const Vec& x) { return map(truncf, x); } -SIN Vec round(const Vec& x) { return map(roundf, x); } -SIN Vec sqrt(const Vec& x) { return map( sqrtf, x); } -SIN Vec abs(const Vec& x) { return map( fabsf, x); } -SIN Vec fma(const Vec& x, - const Vec& y, - const Vec& z) { - // I don't understand why Clang's codegen is terrible if we write map(fmaf, x,y,z) directly. - auto fn = [](float x, float y, float z) { return fmaf(x,y,z); }; - return map(fn, x,y,z); -} - -SI Vec<1,int> lrint(const Vec<1,float>& x) { - return (int)lrintf(x.val); -} -SIN Vec lrint(const Vec& x) { -#if SKVX_USE_SIMD && defined(__AVX__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtps_epi32(bit_pun<__m256>(x))); - } -#endif -#if SKVX_USE_SIMD && defined(__SSE__) - if constexpr (N == 4) { - return bit_pun>(_mm_cvtps_epi32(bit_pun<__m128>(x))); - } -#endif - return join(lrint(x.lo), - lrint(x.hi)); -} - -SIN Vec fract(const Vec& x) { return x - floor(x); } - -// Assumes inputs are finite and treat/flush denorm half floats as/to zero. -// Key constants to watch for: -// - a float is 32-bit, 1-8-23 sign-exponent-mantissa, with 127 exponent bias; -// - a half is 16-bit, 1-5-10 sign-exponent-mantissa, with 15 exponent bias. -SIN Vec to_half_finite_ftz(const Vec& x) { - Vec sem = bit_pun>(x), - s = sem & 0x8000'0000, - em = sem ^ s, - is_norm = em > 0x387f'd000, // halfway between largest f16 denorm and smallest norm - norm = (em>>13) - ((127-15)<<10); - return cast((s>>16) | (is_norm & norm)); -} -SIN Vec from_half_finite_ftz(const Vec& x) { - Vec wide = cast(x), - s = wide & 0x8000, - em = wide ^ s, - is_norm = em > 0x3ff, - norm = (em<<13) + ((127-15)<<23); - return bit_pun>((s<<16) | (is_norm & norm)); -} - -// Like if_then_else(), these N=1 base cases won't actually be used unless explicitly called. -SI Vec<1,uint16_t> to_half(const Vec<1,float>& x) { return to_half_finite_ftz(x); } -SI Vec<1,float> from_half(const Vec<1,uint16_t>& x) { return from_half_finite_ftz(x); } - -SIN Vec to_half(const Vec& x) { -#if SKVX_USE_SIMD && defined(__F16C__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtps_ph(bit_pun<__m256>(x), - _MM_FROUND_TO_NEAREST_INT)); - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - if constexpr (N == 4) { - return bit_pun>(vcvt_f16_f32(bit_pun(x))); - - } -#endif - if constexpr (N > 4) { - return join(to_half(x.lo), - to_half(x.hi)); - } - return to_half_finite_ftz(x); -} - -SIN Vec from_half(const Vec& x) { -#if SKVX_USE_SIMD && defined(__F16C__) - if constexpr (N == 8) { - return bit_pun>(_mm256_cvtph_ps(bit_pun<__m128i>(x))); - } -#endif -#if SKVX_USE_SIMD && defined(__aarch64__) - if constexpr (N == 4) { - return bit_pun>(vcvt_f32_f16(bit_pun(x))); - } -#endif - if constexpr (N > 4) { - return join(from_half(x.lo), - from_half(x.hi)); - } - return from_half_finite_ftz(x); -} - -// div255(x) = (x + 127) / 255 is a bit-exact rounding divide-by-255, packing down to 8-bit. -SIN Vec div255(const Vec& x) { - return cast( (x+127)/255 ); -} - -// approx_scale(x,y) approximates div255(cast(x)*cast(y)) within a bit, -// and is always perfect when x or y is 0 or 255. -SIN Vec approx_scale(const Vec& x, const Vec& y) { - // All of (x*y+x)/256, (x*y+y)/256, and (x*y+255)/256 meet the criteria above. - // We happen to have historically picked (x*y+x)/256. - auto X = cast(x), - Y = cast(y); - return cast( (X*Y+X)/256 ); -} - -// saturated_add(x,y) sums values and clamps to the maximum value instead of overflowing. -SINT std::enable_if_t, Vec> saturated_add(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && (defined(__SSE__) || defined(__ARM_NEON)) - // Both SSE and ARM have 16-lane saturated adds, so use intrinsics for those and recurse down - // or join up to take advantage. - if constexpr (N == 16 && sizeof(T) == 1) { - #if defined(__SSE__) - return bit_pun>(_mm_adds_epu8(bit_pun<__m128i>(x), bit_pun<__m128i>(y))); - #else // __ARM_NEON - return bit_pun>(vqaddq_u8(bit_pun(x), bit_pun(y))); - #endif - } else if constexpr (N < 16 && sizeof(T) == 1) { - return saturated_add(join(x,x), join(y,y)).lo; - } else if constexpr (sizeof(T) == 1) { - return join(saturated_add(x.lo, y.lo), saturated_add(x.hi, y.hi)); - } -#endif - // Otherwise saturate manually - auto sum = x + y; - return if_then_else(sum < x, Vec(std::numeric_limits::max()), sum); -} - -// The ScaledDividerU32 takes a divisor > 1, and creates a function divide(numerator) that -// calculates a numerator / denominator. For this to be rounded properly, numerator should have -// half added in: -// divide(numerator + half) == floor(numerator/denominator + 1/2). -// -// This gives an answer within +/- 1 from the true value. -// -// Derivation of half: -// numerator/denominator + 1/2 = (numerator + half) / d -// numerator + denominator / 2 = numerator + half -// half = denominator / 2. -// -// Because half is divided by 2, that division must also be rounded. -// half == denominator / 2 = (denominator + 1) / 2. -// -// The divisorFactor is just a scaled value: -// divisorFactor = (1 / divisor) * 2 ^ 32. -// The maximum that can be divided and rounded is UINT_MAX - half. -class ScaledDividerU32 { -public: - explicit ScaledDividerU32(uint32_t divisor) - : fDivisorFactor{(uint32_t)(std::round((1.0 / divisor) * (1ull << 32)))} - , fHalf{(divisor + 1) >> 1} { - assert(divisor > 1); - } - - Vec<4, uint32_t> divide(const Vec<4, uint32_t>& numerator) const { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - uint64x2_t hi = vmull_n_u32(vget_high_u32(to_vext(numerator)), fDivisorFactor); - uint64x2_t lo = vmull_n_u32(vget_low_u32(to_vext(numerator)), fDivisorFactor); - - return to_vec<4, uint32_t>(vcombine_u32(vshrn_n_u64(lo,32), vshrn_n_u64(hi,32))); -#else - return cast((cast(numerator) * fDivisorFactor) >> 32); -#endif - } - - uint32_t half() const { return fHalf; } - -private: - const uint32_t fDivisorFactor; - const uint32_t fHalf; -}; - - -SIN Vec mull(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - // With NEON we can do eight u8*u8 -> u16 in one instruction, vmull_u8 (read, mul-long). - if constexpr (N == 8) { - return to_vec<8,uint16_t>(vmull_u8(to_vext(x), to_vext(y))); - } else if constexpr (N < 8) { - return mull(join(x,x), join(y,y)).lo; - } else { // N > 8 - return join(mull(x.lo, y.lo), mull(x.hi, y.hi)); - } -#else - return cast(x) * cast(y); -#endif -} - -SIN Vec mull(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__ARM_NEON) - // NEON can do four u16*u16 -> u32 in one instruction, vmull_u16 - if constexpr (N == 4) { - return to_vec<4,uint32_t>(vmull_u16(to_vext(x), to_vext(y))); - } else if constexpr (N < 4) { - return mull(join(x,x), join(y,y)).lo; - } else { // N > 4 - return join(mull(x.lo, y.lo), mull(x.hi, y.hi)); - } -#else - return cast(x) * cast(y); -#endif -} - -SIN Vec mulhi(const Vec& x, - const Vec& y) { -#if SKVX_USE_SIMD && defined(__SSE__) - // Use _mm_mulhi_epu16 for 8xuint16_t and join or split to get there. - if constexpr (N == 8) { - return bit_pun>(_mm_mulhi_epu16(bit_pun<__m128i>(x), bit_pun<__m128i>(y))); - } else if constexpr (N < 8) { - return mulhi(join(x,x), join(y,y)).lo; - } else { // N > 8 - return join(mulhi(x.lo, y.lo), mulhi(x.hi, y.hi)); - } -#else - return skvx::cast(mull(x, y) >> 16); -#endif -} - -SINT T dot(const Vec& a, const Vec& b) { - auto ab = a*b; - if constexpr (N == 2) { - return ab[0] + ab[1]; - } else if constexpr (N == 4) { - return ab[0] + ab[1] + ab[2] + ab[3]; - } else { - T sum = ab[0]; - for (int i = 1; i < N; ++i) { - sum += ab[i]; - } - return sum; - } -} - -SI float cross(const Vec<2, float>& a, const Vec<2, float>& b) { - auto x = a * shuffle<1,0>(b); - return x[0] - x[1]; -} - -// De-interleaving load of 4 vectors. -// -// WARNING: These are really only supported well on NEON. Consider restructuring your data before -// resorting to these methods. -SIT void strided_load4(const T* v, - Vec<1,T>& a, - Vec<1,T>& b, - Vec<1,T>& c, - Vec<1,T>& d) { - a.val = v[0]; - b.val = v[1]; - c.val = v[2]; - d.val = v[3]; -} -SINT void strided_load4(const T* v, - Vec& a, - Vec& b, - Vec& c, - Vec& d) { - strided_load4(v, a.lo, b.lo, c.lo, d.lo); - strided_load4(v + 4*(N/2), a.hi, b.hi, c.hi, d.hi); -} -#if SKVX_USE_SIMD && defined(__ARM_NEON) -#define IMPL_LOAD4_TRANSPOSED(N, T, VLD) \ -SI void strided_load4(const T* v, \ - Vec& a, \ - Vec& b, \ - Vec& c, \ - Vec& d) { \ - auto mat = VLD(v); \ - a = bit_pun>(mat.val[0]); \ - b = bit_pun>(mat.val[1]); \ - c = bit_pun>(mat.val[2]); \ - d = bit_pun>(mat.val[3]); \ -} -IMPL_LOAD4_TRANSPOSED(2, uint32_t, vld4_u32) -IMPL_LOAD4_TRANSPOSED(4, uint16_t, vld4_u16) -IMPL_LOAD4_TRANSPOSED(8, uint8_t, vld4_u8) -IMPL_LOAD4_TRANSPOSED(2, int32_t, vld4_s32) -IMPL_LOAD4_TRANSPOSED(4, int16_t, vld4_s16) -IMPL_LOAD4_TRANSPOSED(8, int8_t, vld4_s8) -IMPL_LOAD4_TRANSPOSED(2, float, vld4_f32) -IMPL_LOAD4_TRANSPOSED(4, uint32_t, vld4q_u32) -IMPL_LOAD4_TRANSPOSED(8, uint16_t, vld4q_u16) -IMPL_LOAD4_TRANSPOSED(16, uint8_t, vld4q_u8) -IMPL_LOAD4_TRANSPOSED(4, int32_t, vld4q_s32) -IMPL_LOAD4_TRANSPOSED(8, int16_t, vld4q_s16) -IMPL_LOAD4_TRANSPOSED(16, int8_t, vld4q_s8) -IMPL_LOAD4_TRANSPOSED(4, float, vld4q_f32) -#undef IMPL_LOAD4_TRANSPOSED - -#elif SKVX_USE_SIMD && defined(__SSE__) - -SI void strided_load4(const float* v, - Vec<4,float>& a, - Vec<4,float>& b, - Vec<4,float>& c, - Vec<4,float>& d) { - __m128 a_ = _mm_loadu_ps(v); - __m128 b_ = _mm_loadu_ps(v+4); - __m128 c_ = _mm_loadu_ps(v+8); - __m128 d_ = _mm_loadu_ps(v+12); - _MM_TRANSPOSE4_PS(a_, b_, c_, d_); - a = bit_pun>(a_); - b = bit_pun>(b_); - c = bit_pun>(c_); - d = bit_pun>(d_); -} -#endif - -// De-interleaving load of 2 vectors. -// -// WARNING: These are really only supported well on NEON. Consider restructuring your data before -// resorting to these methods. -SIT void strided_load2(const T* v, Vec<1,T>& a, Vec<1,T>& b) { - a.val = v[0]; - b.val = v[1]; -} -SINT void strided_load2(const T* v, Vec& a, Vec& b) { - strided_load2(v, a.lo, b.lo); - strided_load2(v + 2*(N/2), a.hi, b.hi); -} -#if SKVX_USE_SIMD && defined(__ARM_NEON) -#define IMPL_LOAD2_TRANSPOSED(N, T, VLD) \ -SI void strided_load2(const T* v, Vec& a, Vec& b) { \ - auto mat = VLD(v); \ - a = bit_pun>(mat.val[0]); \ - b = bit_pun>(mat.val[1]); \ -} -IMPL_LOAD2_TRANSPOSED(2, uint32_t, vld2_u32) -IMPL_LOAD2_TRANSPOSED(4, uint16_t, vld2_u16) -IMPL_LOAD2_TRANSPOSED(8, uint8_t, vld2_u8) -IMPL_LOAD2_TRANSPOSED(2, int32_t, vld2_s32) -IMPL_LOAD2_TRANSPOSED(4, int16_t, vld2_s16) -IMPL_LOAD2_TRANSPOSED(8, int8_t, vld2_s8) -IMPL_LOAD2_TRANSPOSED(2, float, vld2_f32) -IMPL_LOAD2_TRANSPOSED(4, uint32_t, vld2q_u32) -IMPL_LOAD2_TRANSPOSED(8, uint16_t, vld2q_u16) -IMPL_LOAD2_TRANSPOSED(16, uint8_t, vld2q_u8) -IMPL_LOAD2_TRANSPOSED(4, int32_t, vld2q_s32) -IMPL_LOAD2_TRANSPOSED(8, int16_t, vld2q_s16) -IMPL_LOAD2_TRANSPOSED(16, int8_t, vld2q_s8) -IMPL_LOAD2_TRANSPOSED(4, float, vld2q_f32) -#undef IMPL_LOAD2_TRANSPOSED -#endif - -// Define commonly used aliases -using float2 = Vec< 2, float>; -using float4 = Vec< 4, float>; -using float8 = Vec< 8, float>; - -using double2 = Vec< 2, double>; -using double4 = Vec< 4, double>; -using double8 = Vec< 8, double>; - -using byte2 = Vec< 2, uint8_t>; -using byte4 = Vec< 4, uint8_t>; -using byte8 = Vec< 8, uint8_t>; -using byte16 = Vec<16, uint8_t>; - -using int2 = Vec< 2, int32_t>; -using int4 = Vec< 4, int32_t>; -using int8 = Vec< 8, int32_t>; - -using uint2 = Vec< 2, uint32_t>; -using uint4 = Vec< 4, uint32_t>; -using uint8 = Vec< 8, uint32_t>; - -using long2 = Vec< 2, int64_t>; -using long4 = Vec< 4, int64_t>; -using long8 = Vec< 8, int64_t>; - -// Use with from_half and to_half to convert between floatX, and use these for storage. -using half2 = Vec< 2, uint16_t>; -using half4 = Vec< 4, uint16_t>; -using half8 = Vec< 8, uint16_t>; - -} // namespace skvx - -#undef SINTU -#undef SINT -#undef SIN -#undef SIT -#undef SI -#undef SKVX_ALWAYS_INLINE -#undef SKVX_USE_SIMD - -#endif//SKVX_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h index 2b577342f4cd2..058a18652ba51 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkWeakRefCnt.h @@ -9,7 +9,10 @@ #define SkWeakRefCnt_DEFINED #include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + #include +#include /** \class SkWeakRefCnt diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h similarity index 86% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h index f60f7c83b969c..473981e1fb83f 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SingleOwner.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SingleOwner.h @@ -8,16 +8,19 @@ #ifndef skgpu_SingleOwner_DEFINED #define skgpu_SingleOwner_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkDebug.h" // IWYU pragma: keep + +#if defined(SK_DEBUG) +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkMutex.h" +#include "include/private/base/SkThreadAnnotations.h" +#include "include/private/base/SkThreadID.h" -#ifdef SK_DEBUG -#include "include/private/SkMutex.h" -#include "include/private/SkThreadID.h" #endif namespace skgpu { -#ifdef SK_DEBUG +#if defined(SK_DEBUG) #define SKGPU_ASSERT_SINGLE_OWNER(obj) \ skgpu::SingleOwner::AutoEnforce debug_SingleOwner(obj, __FILE__, __LINE__); diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h new file mode 100644 index 0000000000000..4028f95d87d2b --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAPI.h @@ -0,0 +1,52 @@ +/* + * 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 SkAPI_DEFINED +#define SkAPI_DEFINED + +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +// If SKIA_IMPLEMENTATION is defined as 1, that signals we are building Skia and should +// export our symbols. If it is not set (or set to 0), then Skia is being used by a client +// and we should not export our symbols. +#if !defined(SKIA_IMPLEMENTATION) + #define SKIA_IMPLEMENTATION 0 +#endif + +// If we are compiling Skia is being as a DLL, we need to be sure to export all of our public +// APIs to that DLL. If a client is using Skia which was compiled as a DLL, we need to instruct +// the linker to use the symbols from that DLL. This is the goal of the SK_API define. +#if !defined(SK_API) + #if defined(SKIA_DLL) + #if defined(_MSC_VER) + #if SKIA_IMPLEMENTATION + #define SK_API __declspec(dllexport) + #else + #define SK_API __declspec(dllimport) + #endif + #else + #define SK_API __attribute__((visibility("default"))) + #endif + #else + #define SK_API + #endif +#endif + +// SK_SPI is functionally identical to SK_API, but used within src to clarify that it's less stable +#if !defined(SK_SPI) + #define SK_SPI SK_API +#endif + +// See https://clang.llvm.org/docs/AttributeReference.html#availability +// The API_AVAILABLE macro comes from on MacOS +#if defined(SK_ENABLE_API_AVAILABLE) +# define SK_API_AVAILABLE API_AVAILABLE +#else +# define SK_API_AVAILABLE(...) +#endif + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h new file mode 100644 index 0000000000000..2b2138ddd49c2 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlign.h @@ -0,0 +1,39 @@ +/* + * 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 SkAlign_DEFINED +#define SkAlign_DEFINED + +#include "include/private/base/SkAssert.h" + +#include + +template static constexpr T SkAlign2(T x) { return (x + 1) >> 1 << 1; } +template static constexpr T SkAlign4(T x) { return (x + 3) >> 2 << 2; } +template static constexpr T SkAlign8(T x) { return (x + 7) >> 3 << 3; } + +template static constexpr bool SkIsAlign2(T x) { return 0 == (x & 1); } +template static constexpr bool SkIsAlign4(T x) { return 0 == (x & 3); } +template static constexpr bool SkIsAlign8(T x) { return 0 == (x & 7); } + +template static constexpr T SkAlignPtr(T x) { + return sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x); +} +template static constexpr bool SkIsAlignPtr(T x) { + return sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x); +} + +/** + * align up to a power of 2 + */ +static inline constexpr size_t SkAlignTo(size_t x, size_t alignment) { + // The same as alignment && SkIsPow2(value), w/o a dependency cycle. + SkASSERT(alignment && (alignment & (alignment - 1)) == 0); + return (x + alignment - 1) & ~(alignment - 1); +} + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h new file mode 100644 index 0000000000000..532ad03978fac --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAlignedStorage.h @@ -0,0 +1,32 @@ +// 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 SkAlignedStorage_DEFINED +#define SkAlignedStorage_DEFINED + +#include +#include + +template class SkAlignedSTStorage { +public: + SkAlignedSTStorage() {} + SkAlignedSTStorage(SkAlignedSTStorage&&) = delete; + SkAlignedSTStorage(const SkAlignedSTStorage&) = delete; + SkAlignedSTStorage& operator=(SkAlignedSTStorage&&) = delete; + SkAlignedSTStorage& operator=(const SkAlignedSTStorage&) = delete; + + // Returns void* because this object does not initialize the + // memory. Use placement new for types that require a constructor. + void* get() { return fStorage; } + const void* get() const { return fStorage; } + + // Act as a container of bytes because the storage is uninitialized. + std::byte* data() { return fStorage; } + const std::byte* data() const { return fStorage; } + size_t size() const { return std::size(fStorage); } + +private: + alignas(T) std::byte fStorage[sizeof(T) * N]; +}; + +#endif // SkAlignedStorage_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h new file mode 100644 index 0000000000000..97d43d4f64ff4 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAssert.h @@ -0,0 +1,92 @@ +/* + * 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 SkAssert_DEFINED +#define SkAssert_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" // IWYU pragma: keep + +/** Called internally if we hit an unrecoverable error. + The platform implementation must not return, but should either throw + an exception or otherwise exit. +*/ +[[noreturn]] SK_API extern void sk_abort_no_print(void); + +#if defined(SK_BUILD_FOR_GOOGLE3) + void SkDebugfForDumpStackTrace(const char* data, void* unused); + namespace base { + void DumpStackTrace(int skip_count, void w(const char*, void*), void* arg); + } +# define SK_DUMP_GOOGLE3_STACK() ::base::DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr) +#else +# define SK_DUMP_GOOGLE3_STACK() +#endif + +#if !defined(SK_ABORT) +# if defined(SK_BUILD_FOR_WIN) + // This style lets Visual Studio follow errors back to the source file. +# define SK_DUMP_LINE_FORMAT "%s(%d)" +# else +# define SK_DUMP_LINE_FORMAT "%s:%d" +# endif +# define SK_ABORT(message, ...) \ + do { \ + SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \ + __FILE__, __LINE__, ##__VA_ARGS__); \ + SK_DUMP_GOOGLE3_STACK(); \ + sk_abort_no_print(); \ + } while (false) +#endif + +// SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g. +// uint32_t foo(int x) { +// SkASSERT(x > 4); +// return x - 4; +// } +// and are also written to be compatible with constexpr functions: +// constexpr uint32_t foo(int x) { +// return SkASSERT(x > 4), +// x - 4; +// } +#define SkASSERT_RELEASE(cond) \ + static_cast( (cond) ? (void)0 : []{ SK_ABORT("assert(%s)", #cond); }() ) + +#if defined(SK_DEBUG) + #define SkASSERT(cond) SkASSERT_RELEASE(cond) + #define SkASSERTF(cond, fmt, ...) static_cast( (cond) ? (void)0 : [&]{ \ + SkDebugf(fmt"\n", ##__VA_ARGS__); \ + SK_ABORT("assert(%s)", #cond); \ + }() ) + #define SkDEBUGFAIL(message) SK_ABORT("%s", message) + #define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__) + #define SkAssertResult(cond) SkASSERT(cond) +#else + #define SkASSERT(cond) static_cast(0) + #define SkASSERTF(cond, fmt, ...) static_cast(0) + #define SkDEBUGFAIL(message) + #define SkDEBUGFAILF(fmt, ...) + + // unlike SkASSERT, this macro executes its condition in the non-debug build. + // The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT. + #define SkAssertResult(cond) if (cond) {} do {} while(false) +#endif + +#if !defined(SkUNREACHABLE) +# if defined(_MSC_VER) && !defined(__clang__) +# include +# define FAST_FAIL_INVALID_ARG 5 +// See https://developercommunity.visualstudio.com/content/problem/1128631/code-flow-doesnt-see-noreturn-with-extern-c.html +// for why this is wrapped. Hopefully removable after msvc++ 19.27 is no longer supported. +[[noreturn]] static inline void sk_fast_fail() { __fastfail(FAST_FAIL_INVALID_ARG); } +# define SkUNREACHABLE sk_fast_fail() +# else +# define SkUNREACHABLE __builtin_trap() +# endif +#endif + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h new file mode 100644 index 0000000000000..34fdf0e09c92e --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkAttributes.h @@ -0,0 +1,102 @@ +/* + * 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 SkAttributes_DEFINED +#define SkAttributes_DEFINED + +#include "include/private/base/SkFeatures.h" // IWYU pragma: keep +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +#if defined(__clang__) || defined(__GNUC__) +# define SK_ATTRIBUTE(attr) __attribute__((attr)) +#else +# define SK_ATTRIBUTE(attr) +#endif + +#if !defined(SK_UNUSED) +# if !defined(__clang__) && defined(_MSC_VER) +# define SK_UNUSED __pragma(warning(suppress:4189)) +# else +# define SK_UNUSED SK_ATTRIBUTE(unused) +# endif +#endif + +#if !defined(SK_WARN_UNUSED_RESULT) + #define SK_WARN_UNUSED_RESULT SK_ATTRIBUTE(warn_unused_result) +#endif + +/** + * If your judgment is better than the compiler's (i.e. you've profiled it), + * you can use SK_ALWAYS_INLINE to force inlining. E.g. + * inline void someMethod() { ... } // may not be inlined + * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined + */ +#if !defined(SK_ALWAYS_INLINE) +# if defined(SK_BUILD_FOR_WIN) +# define SK_ALWAYS_INLINE __forceinline +# else +# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline +# endif +#endif + +/** + * If your judgment is better than the compiler's (i.e. you've profiled it), + * you can use SK_NEVER_INLINE to prevent inlining. + */ +#if !defined(SK_NEVER_INLINE) +# if defined(SK_BUILD_FOR_WIN) +# define SK_NEVER_INLINE __declspec(noinline) +# else +# define SK_NEVER_INLINE SK_ATTRIBUTE(noinline) +# endif +#endif + +/** + * Used to annotate a function as taking printf style arguments. + * `A` is the (1 based) index of the format string argument. + * `B` is the (1 based) index of the first argument used by the format string. + */ +#if !defined(SK_PRINTF_LIKE) +# define SK_PRINTF_LIKE(A, B) SK_ATTRIBUTE(format(printf, (A), (B))) +#endif + +/** + * Used to ignore sanitizer warnings. + */ +#if !defined(SK_NO_SANITIZE) +# define SK_NO_SANITIZE(A) SK_ATTRIBUTE(no_sanitize(A)) +#endif + +/** + * Helper macro to define no_sanitize attributes only with clang. + */ +#if defined(__clang__) && defined(__has_attribute) + #if __has_attribute(no_sanitize) + #define SK_CLANG_NO_SANITIZE(A) SK_NO_SANITIZE(A) + #endif +#endif + +#if !defined(SK_CLANG_NO_SANITIZE) + #define SK_CLANG_NO_SANITIZE(A) +#endif + +/** + * Annotates a class' non-trivial special functions as trivial for the purposes of calls. + * Allows a class with a non-trivial destructor to be __is_trivially_relocatable. + * Use of this attribute on a public API breaks platform ABI. + * Annotated classes may not hold pointers derived from `this`. + * Annotated classes must implement move+delete as equivalent to memcpy+free. + * Use may require more complete types, as callee destroys. + * + * https://clang.llvm.org/docs/AttributeReference.html#trivial-abi + * https://libcxx.llvm.org/DesignDocs/UniquePtrTrivialAbi.html + */ +#if !defined(SK_TRIVIAL_ABI) +# define SK_TRIVIAL_ABI +#endif + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h new file mode 100644 index 0000000000000..a5f60fd3ef191 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkCPUTypes.h @@ -0,0 +1,25 @@ +/* + * Copyright 2023 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkCPUTypes_DEFINED +#define SkCPUTypes_DEFINED + +// TODO(bungeman,kjlubick) There are a lot of assumptions throughout the codebase that +// these types are 32 bits, when they could be more or less. Public APIs should stop +// using these. Internally, we could use uint_fast8_t and uint_fast16_t, but not in +// public APIs due to ABI incompatibilities. + +/** Fast type for unsigned 8 bits. Use for parameter passing and local + variables, not for storage +*/ +typedef unsigned U8CPU; + +/** Fast type for unsigned 16 bits. Use for parameter passing and local + variables, not for storage +*/ +typedef unsigned U16CPU; + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h new file mode 100644 index 0000000000000..2ece73e28761b --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkContainers.h @@ -0,0 +1,46 @@ +// 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 SkContainers_DEFINED +#define SkContainers_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkSpan_impl.h" + +#include +#include + +class SK_SPI SkContainerAllocator { +public: + SkContainerAllocator(size_t sizeOfT, int maxCapacity) + : fSizeOfT{sizeOfT} + , fMaxCapacity{maxCapacity} {} + + // allocate will abort on failure. Given a capacity of 0, it will return the empty span. + // The bytes allocated are freed using sk_free(). + SkSpan allocate(int capacity, double growthFactor = 1.0); + +private: + friend struct SkContainerAllocatorTestingPeer; + // All capacity counts will be rounded up to kCapacityMultiple. + // TODO: this is a constant from the original SkTArray code. This should be checked some how. + static constexpr int64_t kCapacityMultiple = 8; + + // Rounds up capacity to next multiple of kCapacityMultiple and pin to fMaxCapacity. + size_t roundUpCapacity(int64_t capacity) const; + + // Grows the capacity by growthFactor being sure to stay with in kMinBytes and fMaxCapacity. + size_t growthFactorCapacity(int capacity, double growthFactor) const; + + const size_t fSizeOfT; + const int64_t fMaxCapacity; +}; + +// sk_allocate_canfail returns the empty span on failure. Parameter size must be > 0. +SkSpan sk_allocate_canfail(size_t size); + +// Returns the empty span if size is 0. sk_allocate_throw aborts on failure. +SkSpan sk_allocate_throw(size_t size); + +SK_SPI void sk_report_container_overflow_and_die(); +#endif // SkContainers_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.h new file mode 100644 index 0000000000000..2e4810fc1c961 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDebug.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 SkDebug_DEFINED +#define SkDebug_DEFINED + +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep + +#if !defined(SkDebugf) + void SK_SPI SkDebugf(const char format[], ...) SK_PRINTF_LIKE(1, 2); +#endif + +#if defined(SK_DEBUG) + #define SkDEBUGCODE(...) __VA_ARGS__ + #define SkDEBUGF(...) SkDebugf(__VA_ARGS__) +#else + #define SkDEBUGCODE(...) + #define SkDEBUGF(...) +#endif + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h similarity index 98% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h index 8adc39c1c71f2..fbc61673131b4 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkDeque.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkDeque.h @@ -10,7 +10,9 @@ #ifndef SkDeque_DEFINED #define SkDeque_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" + +#include /* * The deque class works by blindly creating memory space of a specified element diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h new file mode 100644 index 0000000000000..662bf0321161e --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFeatures.h @@ -0,0 +1,151 @@ +/* + * 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 SkFeatures_DEFINED +#define SkFeatures_DEFINED + +#if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && \ + !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) + + #ifdef __APPLE__ + #include + #endif + + #if defined(_WIN32) || defined(__SYMBIAN32__) + #define SK_BUILD_FOR_WIN + #elif defined(ANDROID) || defined(__ANDROID__) + #define SK_BUILD_FOR_ANDROID + #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || \ + defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || \ + defined(__DragonFly__) || defined(__Fuchsia__) || \ + defined(__GLIBC__) || defined(__GNU__) || defined(__unix__) + #define SK_BUILD_FOR_UNIX + #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR + #define SK_BUILD_FOR_IOS + #else + #define SK_BUILD_FOR_MAC + #endif +#endif // end SK_BUILD_FOR_* + + +#if defined(SK_BUILD_FOR_WIN) && !defined(__clang__) + #if !defined(SK_RESTRICT) + #define SK_RESTRICT __restrict + #endif + #if !defined(SK_WARN_UNUSED_RESULT) + #define SK_WARN_UNUSED_RESULT + #endif +#endif + +#if !defined(SK_RESTRICT) + #define SK_RESTRICT __restrict__ +#endif + +#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) + #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) + #define SK_CPU_BENDIAN + #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) + #define SK_CPU_LENDIAN + #elif defined(__sparc) || defined(__sparc__) || \ + defined(_POWER) || defined(__powerpc__) || \ + defined(__ppc__) || defined(__hppa) || \ + defined(__PPC__) || defined(__PPC64__) || \ + defined(_MIPSEB) || defined(__ARMEB__) || \ + defined(__s390__) || \ + (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ + (defined(__ia64) && defined(__BIG_ENDIAN__)) + #define SK_CPU_BENDIAN + #else + #define SK_CPU_LENDIAN + #endif +#endif + +#if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) + #define SK_CPU_X86 1 +#endif + +/** + * SK_CPU_SSE_LEVEL + * + * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. + * On non-intel CPU this should be undefined. + */ +#define SK_CPU_SSE_LEVEL_SSE1 10 +#define SK_CPU_SSE_LEVEL_SSE2 20 +#define SK_CPU_SSE_LEVEL_SSE3 30 +#define SK_CPU_SSE_LEVEL_SSSE3 31 +#define SK_CPU_SSE_LEVEL_SSE41 41 +#define SK_CPU_SSE_LEVEL_SSE42 42 +#define SK_CPU_SSE_LEVEL_AVX 51 +#define SK_CPU_SSE_LEVEL_AVX2 52 +#define SK_CPU_SSE_LEVEL_SKX 60 + +// TODO(brianosman,kjlubick) clean up these checks + +// Are we in GCC/Clang? +#ifndef SK_CPU_SSE_LEVEL + // These checks must be done in descending order to ensure we set the highest + // available SSE level. + #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ + defined(__AVX512BW__) && defined(__AVX512VL__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX + #elif defined(__AVX2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 + #elif defined(__AVX__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX + #elif defined(__SSE4_2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42 + #elif defined(__SSE4_1__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41 + #elif defined(__SSSE3__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 + #elif defined(__SSE3__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 + #elif defined(__SSE2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #endif +#endif + +// Are we in VisualStudio? +#ifndef SK_CPU_SSE_LEVEL + // These checks must be done in descending order to ensure we set the highest + // available SSE level. 64-bit intel guarantees at least SSE2 support. + #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ + defined(__AVX512BW__) && defined(__AVX512VL__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX + #elif defined(__AVX2__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 + #elif defined(__AVX__) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX + #elif defined(_M_X64) || defined(_M_AMD64) + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #elif defined(_M_IX86_FP) + #if _M_IX86_FP >= 2 + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 + #elif _M_IX86_FP == 1 + #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 + #endif + #endif +#endif + +// ARM defines +#if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) + #define SK_CPU_ARM32 +#elif defined(__aarch64__) + #define SK_CPU_ARM64 +#endif + +// All 64-bit ARM chips have NEON. Many 32-bit ARM chips do too. +#if !defined(SK_ARM_HAS_NEON) && defined(__ARM_NEON) + #define SK_ARM_HAS_NEON +#endif + +#if defined(__ARM_FEATURE_CRC32) + #define SK_ARM_HAS_CRC32 +#endif + +#endif // SkFeatures_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h similarity index 94% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h index e34c19f2ac867..2c8f2fb56c188 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFixed.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFixed.h @@ -8,11 +8,12 @@ #ifndef SkFixed_DEFINED #define SkFixed_DEFINED -#include "include/core/SkScalar.h" -#include "include/core/SkTypes.h" -#include "include/private/SkSafe_math.h" -#include "include/private/SkTPin.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMath.h" // IWYU pragma: keep +#include "include/private/base/SkTPin.h" // IWYU pragma: keep + +#include /** \file SkFixed.h @@ -86,7 +87,6 @@ static inline SkFixed SkFixedFloorToFixed(SkFixed x) { return (SkFixed)( (uint32_t)x & 0xFFFF0000 ); } -#define SkFixedAbs(x) SkAbs32(x) #define SkFixedAve(a, b) (((a) + (b)) >> 1) // The divide may exceed 32 bits. Clamp to a signed 32 bit result. @@ -102,6 +102,8 @@ static inline SkFixed SkFixedMul(SkFixed a, SkFixed b) { // The VCVT float-to-fixed instruction is part of the VFPv3 instruction set. #if defined(__ARM_VFPV3__) + #include + /* This does not handle NaN or other obscurities, but is faster than than (int)(x*65536). When built on Android with -Os, needs forcing to inline or we lose the speed benefit. @@ -110,7 +112,7 @@ static inline SkFixed SkFixedMul(SkFixed a, SkFixed b) { { int32_t y; asm("vcvt.s32.f32 %0, %0, #16": "+w"(x)); - memcpy(&y, &x, sizeof(y)); + std::memcpy(&y, &x, sizeof(y)); return y; } #undef SkFloatToFixed diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h similarity index 96% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h index 89eea4b9e3495..37a7b271aee12 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatBits.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatBits.h @@ -8,10 +8,9 @@ #ifndef SkFloatBits_DEFINED #define SkFloatBits_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkSafe_math.h" +#include "include/private/base/SkMath.h" -#include +#include /** Convert a sign-bit int (i.e. float interpreted as int) into a 2s compliement int. This also converts -0 (0x80000000) to 0. Doing this to a float allows diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h similarity index 89% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h index 8135abbfe1952..7aa8909f3a5eb 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkFloatingPoint.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkFloatingPoint.h @@ -8,14 +8,14 @@ #ifndef SkFloatingPoint_DEFINED #define SkFloatingPoint_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkFloatBits.h" -#include "include/private/SkSafe_math.h" -#include -#include +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkFloatBits.h" +#include "include/private/base/SkMath.h" + +#include #include +#include #include -#include constexpr float SK_FloatSqrt2 = 1.41421356f; constexpr float SK_FloatPI = 3.14159265f; @@ -150,7 +150,7 @@ static inline int64_t sk_float_saturate2int64(float x) { // Cast double to float, ignoring any warning about too-large finite values being cast to float. // Clang thinks this is undefined, but it's actually implementation defined to return either // the largest float or infinity (one of the two bracketing representable floats). Good enough! -SK_ATTRIBUTE(no_sanitize("float-cast-overflow")) +SK_NO_SANITIZE("float-cast-overflow") static inline float sk_double_to_float(double x) { return static_cast(x); } @@ -196,12 +196,12 @@ static inline int sk_float_nextlog2(float x) { // IEEE defines how float divide behaves for non-finite values and zero-denoms, but C does not // so we have a helper that suppresses the possible undefined-behavior warnings. -SK_ATTRIBUTE(no_sanitize("float-divide-by-zero")) +SK_NO_SANITIZE("float-divide-by-zero") static inline float sk_ieee_float_divide(float numer, float denom) { return numer / denom; } -SK_ATTRIBUTE(no_sanitize("float-divide-by-zero")) +SK_NO_SANITIZE("float-divide-by-zero") static inline double sk_ieee_double_divide(double numer, double denom) { return numer / denom; } @@ -219,4 +219,13 @@ static inline float sk_fmaf(float f, float m, float a) { #endif } +// Returns true iff the provided number is within a small epsilon of 0. +bool sk_double_nearly_zero(double a); + +// Comparing floating point numbers is complicated. This helper only works if one or none +// of the two inputs is not very close to zero. It also does not work if both inputs could be NaN. +// The term "ulps" stands for "units of least precision". Read the following for more nuance: +// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ +bool sk_doubles_nearly_equal_ulps(double a, double b, uint8_t max_ulps_diff=16); + #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h new file mode 100644 index 0000000000000..b212ada86b0e5 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkLoadUserConfig.h @@ -0,0 +1,63 @@ +/* + * 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 SK_USER_CONFIG_WAS_LOADED + +// Include this to set reasonable defaults (e.g. for SK_CPU_LENDIAN) +#include "include/private/base/SkFeatures.h" + +// Allows embedders that want to disable macros that take arguments to just +// define that symbol to be one of these +#define SK_NOTHING_ARG1(arg1) +#define SK_NOTHING_ARG2(arg1, arg2) +#define SK_NOTHING_ARG3(arg1, arg2, arg3) + +// IWYU pragma: begin_exports + +// Note: SK_USER_CONFIG_HEADER will not work with Bazel builds and some C++ compilers. +#if defined(SK_USER_CONFIG_HEADER) + #include SK_USER_CONFIG_HEADER +#elif defined(SK_USE_BAZEL_CONFIG_HEADER) + // The Bazel config file is presumed to be in the root directory of its Bazel Workspace. + // This is achieved in Skia by having a nested WORKSPACE in include/config and a cc_library + // defined in that folder. As a result, we do not try to include SkUserConfig.h from the + // top of Skia because Bazel sandboxing will move it to a different location. + #include "SkUserConfig.h" +#else + #include "include/config/SkUserConfig.h" +#endif +// IWYU pragma: end_exports + +// Checks to make sure the SkUserConfig options do not conflict. +#if !defined(SK_DEBUG) && !defined(SK_RELEASE) + #ifdef NDEBUG + #define SK_RELEASE + #else + #define SK_DEBUG + #endif +#endif + +#if defined(SK_DEBUG) && defined(SK_RELEASE) +# error "cannot define both SK_DEBUG and SK_RELEASE" +#elif !defined(SK_DEBUG) && !defined(SK_RELEASE) +# error "must define either SK_DEBUG or SK_RELEASE" +#endif + +#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) +# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" +#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) +# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" +#endif + +#if defined(SK_CPU_BENDIAN) && !defined(I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN) + #error "The Skia team is not endian-savvy enough to support big-endian CPUs." + #error "If you still want to use Skia," + #error "please define I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN." +#endif + +#define SK_USER_CONFIG_WAS_LOADED +#endif // SK_USER_CONFIG_WAS_LOADED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h similarity index 77% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h index 308c5d05fd4a7..5d1835d013096 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMacros.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMacros.h @@ -7,8 +7,6 @@ #ifndef SkMacros_DEFINED #define SkMacros_DEFINED -#include - /* * Usage: SK_MACRO_CONCAT(a, b) to construct the symbol ab * @@ -40,6 +38,23 @@ #define SK_END_REQUIRE_DENSE #endif +#if defined(__clang__) && defined(__has_feature) + // Some compilers have a preprocessor that does not appear to do short-circuit + // evaluation as expected + #if __has_feature(leak_sanitizer) || __has_feature(address_sanitizer) + // Chrome had issues if we tried to include lsan_interface.h ourselves. + // https://github.com/llvm/llvm-project/blob/10a35632d55bb05004fe3d0c2d4432bb74897ee7/compiler-rt/include/sanitizer/lsan_interface.h#L26 +extern "C" { + void __lsan_ignore_object(const void *p); +} + #define SK_INTENTIONALLY_LEAKED(X) __lsan_ignore_object(X) + #else + #define SK_INTENTIONALLY_LEAKED(X) ((void)0) + #endif +#else + #define SK_INTENTIONALLY_LEAKED(X) ((void)0) +#endif + #define SK_INIT_TO_AVOID_WARNING = 0 //////////////////////////////////////////////////////////////////////////////// diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h similarity index 94% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h index 206bf14e2f877..1c0c2e73da625 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMalloc.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMalloc.h @@ -8,10 +8,9 @@ #ifndef SkMalloc_DEFINED #define SkMalloc_DEFINED -#include #include -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" /* memory wrappers to be implemented by the porting layer (platform) @@ -51,7 +50,9 @@ enum { SK_API extern void* sk_malloc_flags(size_t size, unsigned flags); /** Same as standard realloc(), but this one never returns null on failure. It will throw - * an exception if it fails. + * if it fails. + * If size is 0, it will call sk_free on buffer and return null. (This behavior is implementation- + * defined for normal realloc. We follow what glibc does.) */ SK_API extern void* sk_realloc_throw(void* buffer, size_t size); @@ -78,10 +79,6 @@ SK_API extern void* sk_calloc_throw(size_t count, size_t elemSize); SK_API extern void* sk_malloc_throw(size_t count, size_t elemSize); SK_API extern void* sk_realloc_throw(void* buffer, size_t count, size_t elemSize); -// Returns the true usable size provided by the underlying allocator, or 0 if -// querying the allocation size is not supported. -SK_API extern size_t sk_malloc_usable_size(void* buffer); - /** * These variants return nullptr on failure */ diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h similarity index 64% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h index 97352afab9d6f..34bfa739f7a97 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/core/SkMath.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMath.h @@ -8,7 +8,22 @@ #ifndef SkMath_DEFINED #define SkMath_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkCPUTypes.h" + +#include +#include + +// Max Signed 16 bit value +static constexpr int16_t SK_MaxS16 = INT16_MAX; +static constexpr int16_t SK_MinS16 = -SK_MaxS16; + +static constexpr int32_t SK_MaxS32 = INT32_MAX; +static constexpr int32_t SK_MinS32 = -SK_MaxS32; +static constexpr int32_t SK_NaN32 = INT32_MIN; + +static constexpr int64_t SK_MaxS64 = INT64_MAX; +static constexpr int64_t SK_MinS64 = -SK_MaxS64; // 64bit -> 32bit utilities @@ -19,6 +34,14 @@ static inline int64_t sk_64_mul(int64_t a, int64_t b) { return a * b; } +static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { + return (int32_t) ((uint32_t) value << shift); +} + +static inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) { + return (int64_t) ((uint64_t) value << shift); +} + /////////////////////////////////////////////////////////////////////////////// /** @@ -48,7 +71,7 @@ static inline unsigned SkMul16ShiftRound(U16CPU a, U16CPU b, int shift) { * Only valid if a and b are unsigned and <= 32767. */ static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { - return SkMul16ShiftRound(a,b,8); + return SkMul16ShiftRound(a, b, 8); } #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h similarity index 86% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h index b7cdceb1e1d8d..4452beb912f56 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkMutex.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkMutex.h @@ -8,11 +8,11 @@ #ifndef SkMutex_DEFINED #define SkMutex_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMacros.h" -#include "include/private/SkSemaphore.h" -#include "include/private/SkThreadAnnotations.h" -#include "include/private/SkThreadID.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkSemaphore.h" +#include "include/private/base/SkThreadAnnotations.h" +#include "include/private/base/SkThreadID.h" class SK_CAPABILITY("mutex") SkMutex { public: diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h similarity index 89% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h index bda5d50bb6804..ec4a4e5161199 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkNoncopyable.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkNoncopyable.h @@ -8,9 +8,9 @@ #ifndef SkNoncopyable_DEFINED #define SkNoncopyable_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" -/** \class SkNoncopyable +/** \class SkNoncopyable (DEPRECATED) SkNoncopyable is the base class for objects that do not want to be copied. It hides its copy-constructor and its assignment-operator. diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h similarity index 96% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h index edf3e833582b5..97ce6b6311e0b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkOnce.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkOnce.h @@ -8,8 +8,10 @@ #ifndef SkOnce_DEFINED #define SkOnce_DEFINED -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkThreadAnnotations.h" + #include +#include #include // SkOnce provides call-once guarantees for Skia, much like std::once_flag/std::call_once(). diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h new file mode 100644 index 0000000000000..642bbb3489f7e --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkPathEnums.h @@ -0,0 +1,25 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * This file contains private enums related to paths. See also skbug.com/10670 + */ + +#ifndef SkPathEnums_DEFINED +#define SkPathEnums_DEFINED + +enum class SkPathConvexity { + kConvex, + kConcave, + kUnknown, +}; + +enum class SkPathFirstDirection { + kCW, // == SkPathDirection::kCW + kCCW, // == SkPathDirection::kCCW + kUnknown, +}; + +#endif diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h similarity index 64% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h index 7e59f2b0040ad..5ba4c2f9a48e2 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkSafe32.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSafe32.h @@ -8,7 +8,10 @@ #ifndef SkSafe32_DEFINED #define SkSafe32_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkMath.h" + +#include static constexpr int32_t Sk64_pin_to_s32(int64_t x) { return x < SK_MinS32 ? SK_MinS32 : (x > SK_MaxS32 ? SK_MaxS32 : (int32_t)x); @@ -31,4 +34,16 @@ static constexpr int32_t Sk32_can_overflow_sub(int32_t a, int32_t b) { return (int32_t)((uint32_t)a - (uint32_t)b); } +/** + * This is a 'safe' abs for 32-bit integers that asserts when undefined behavior would occur. + * SkTAbs (in SkTemplates.h) is a general purpose absolute-value function. + */ +static inline int32_t SkAbs32(int32_t value) { + SkASSERT(value != SK_NaN32); // The most negative int32_t can't be negated. + if (value < 0) { + value = -value; + } + return value; +} + #endif diff --git a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h similarity index 95% rename from android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h index d7318be577919..f78ee86625a42 100644 --- a/android/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkSemaphore.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSemaphore.h @@ -8,9 +8,10 @@ #ifndef SkSemaphore_DEFINED #define SkSemaphore_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkOnce.h" -#include "include/private/SkThreadAnnotations.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkOnce.h" +#include "include/private/base/SkThreadAnnotations.h" + #include #include diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h new file mode 100644 index 0000000000000..5f31a651bb375 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkSpan_impl.h @@ -0,0 +1,129 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkSpan_DEFINED +#define SkSpan_DEFINED + +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTo.h" + +#include +#include +#include +#include +#include + +// Having this be an export works around IWYU churn related to +// https://github.com/include-what-you-use/include-what-you-use/issues/1121 +#include // IWYU pragma: export + +// Add macro to check the lifetime of initializer_list arguments. initializer_list has a very +// short life span, and can only be used as a parameter, and not as a variable. +#if defined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::lifetimebound) +#define SK_CHECK_IL_LIFETIME [[clang::lifetimebound]] +#else +#define SK_CHECK_IL_LIFETIME +#endif + +/** + * SkSpan holds a reference to contiguous data of type T along with a count. SkSpan does not own + * the data itself but is merely a reference, therefore you must take care with the lifetime of + * the underlying data. + * + * SkSpan is a count and a pointer into existing array or data type that stores its data in + * contiguous memory like std::vector. Any container that works with std::size() and std::data() + * can be used. + * + * SkSpan makes a convenient parameter for a routine to accept array like things. This allows you to + * write the routine without overloads for all different container types. + * + * Example: + * void routine(SkSpan a) { ... } + * + * std::vector v = {1, 2, 3, 4, 5}; + * + * routine(a); + * + * A word of caution when working with initializer_list, initializer_lists have a lifetime that is + * limited to the current statement. The following is correct and safe: + * + * Example: + * routine({1,2,3,4,5}); + * + * The following is undefined, and will result in erratic execution: + * + * Bad Example: + * initializer_list l = {1, 2, 3, 4, 5}; // The data behind l dies at the ;. + * routine(l); + */ +template +class SkSpan { +public: + constexpr SkSpan() : fPtr{nullptr}, fSize{0} {} + + template , bool> = true> + constexpr SkSpan(T* ptr, Integer size) : fPtr{ptr}, fSize{SkToSizeT(size)} { + SkASSERT(ptr || fSize == 0); // disallow nullptr + a nonzero size + SkASSERT(fSize < kMaxSize); + } + template >> + constexpr SkSpan(const SkSpan& that) : fPtr(std::data(that)), fSize(std::size(that)) {} + constexpr SkSpan(const SkSpan& o) = default; + template constexpr SkSpan(T(&a)[N]) : SkSpan(a, N) { } + template + constexpr SkSpan(Container& c) : SkSpan(std::data(c), std::size(c)) { } + SkSpan(std::initializer_list il SK_CHECK_IL_LIFETIME) + : SkSpan(std::data(il), std::size(il)) {} + + constexpr SkSpan& operator=(const SkSpan& that) = default; + + constexpr T& operator [] (size_t i) const { + SkASSERT(i < this->size()); + return fPtr[i]; + } + constexpr T& front() const { return fPtr[0]; } + constexpr T& back() const { return fPtr[fSize - 1]; } + constexpr T* begin() const { return fPtr; } + constexpr T* end() const { return fPtr + fSize; } + constexpr auto rbegin() const { return std::make_reverse_iterator(this->end()); } + constexpr auto rend() const { return std::make_reverse_iterator(this->begin()); } + constexpr T* data() const { return this->begin(); } + constexpr size_t size() const { return fSize; } + constexpr bool empty() const { return fSize == 0; } + constexpr size_t size_bytes() const { return fSize * sizeof(T); } + constexpr SkSpan first(size_t prefixLen) const { + SkASSERT(prefixLen <= this->size()); + return SkSpan{fPtr, prefixLen}; + } + constexpr SkSpan last(size_t postfixLen) const { + SkASSERT(postfixLen <= this->size()); + return SkSpan{fPtr + (this->size() - postfixLen), postfixLen}; + } + constexpr SkSpan subspan(size_t offset) const { + return this->subspan(offset, this->size() - offset); + } + constexpr SkSpan subspan(size_t offset, size_t count) const { + SkASSERT(offset <= this->size()); + SkASSERT(count <= this->size() - offset); + return SkSpan{fPtr + offset, count}; + } + +private: + static const constexpr size_t kMaxSize = std::numeric_limits::max() / sizeof(T); + T* fPtr; + size_t fSize; +}; + +template +SkSpan(Container&) -> + SkSpan()))>>; + +template +SkSpan(std::initializer_list) -> + SkSpan>()))>>; + +#endif // SkSpan_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h new file mode 100644 index 0000000000000..de8e276513b2e --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTArray.h @@ -0,0 +1,694 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkTArray_DEFINED +#define SkTArray_DEFINED + +#include "include/private/base/SkAlignedStorage.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkAttributes.h" +#include "include/private/base/SkContainers.h" +#include "include/private/base/SkMalloc.h" +#include "include/private/base/SkMath.h" +#include "include/private/base/SkSpan_impl.h" +#include "include/private/base/SkTo.h" +#include "include/private/base/SkTypeTraits.h" // IWYU pragma: keep + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace skia_private { +/** TArray implements a typical, mostly std::vector-like array. + Each T will be default-initialized on allocation, and ~T will be called on destruction. + + MEM_MOVE controls the behavior when a T needs to be moved (e.g. when the array is resized) + - true: T will be bit-copied via memcpy. + - false: T will be moved via move-constructors. +*/ +template > class TArray { +public: + using value_type = T; + + /** + * Creates an empty array with no initial storage + */ + TArray() : fOwnMemory(true), fCapacity{0} {} + + /** + * Creates an empty array that will preallocate space for reserveCount + * elements. + */ + explicit TArray(int reserveCount) : TArray() { this->reserve_back(reserveCount); } + + /** + * Copies one array to another. The new array will be heap allocated. + */ + TArray(const TArray& that) : TArray(that.fData, that.fSize) {} + + TArray(TArray&& that) { + if (that.fOwnMemory) { + this->setData(that); + that.setData({}); + } else { + this->initData(that.fSize); + that.move(fData); + } + fSize = std::exchange(that.fSize, 0); + } + + /** + * Creates a TArray by copying contents of a standard C array. The new + * array will be heap allocated. Be careful not to use this constructor + * when you really want the (void*, int) version. + */ + TArray(const T* array, int count) { + this->initData(count); + this->copy(array); + } + + /** + * Creates a TArray by copying contents of an initializer list. + */ + TArray(std::initializer_list data) : TArray(data.begin(), data.size()) {} + + TArray& operator=(const TArray& that) { + if (this == &that) { + return *this; + } + this->clear(); + this->checkRealloc(that.size(), kExactFit); + fSize = that.fSize; + this->copy(that.fData); + return *this; + } + TArray& operator=(TArray&& that) { + if (this != &that) { + this->clear(); + if (that.fOwnMemory) { + // The storage is on the heap, so move the data pointer. + if (fOwnMemory) { + sk_free(fData); + } + + fData = std::exchange(that.fData, nullptr); + + // Can't use exchange with bitfields. + fCapacity = that.fCapacity; + that.fCapacity = 0; + + fOwnMemory = true; + } else { + // The data is stored inline in that, so move it element-by-element. + this->checkRealloc(that.size(), kExactFit); + that.move(fData); + } + fSize = std::exchange(that.fSize, 0); + } + return *this; + } + + ~TArray() { + this->destroyAll(); + if (fOwnMemory) { + sk_free(fData); + } + } + + /** + * Resets to size() = n newly constructed T objects and resets any reserve count. + */ + void reset(int n) { + SkASSERT(n >= 0); + this->clear(); + this->checkRealloc(n, kExactFit); + fSize = n; + for (int i = 0; i < this->size(); ++i) { + new (fData + i) T; + } + } + + /** + * Resets to a copy of a C array and resets any reserve count. + */ + void reset(const T* array, int count) { + SkASSERT(count >= 0); + this->clear(); + this->checkRealloc(count, kExactFit); + fSize = count; + this->copy(array); + } + + /** + * Ensures there is enough reserved space for n elements. + */ + void reserve(int n) { + SkASSERT(n >= 0); + if (n > this->size()) { + this->checkRealloc(n - this->size(), kGrowing); + } + } + + /** + * Ensures there is enough reserved space for n additional elements. The is guaranteed at least + * until the array size grows above n and subsequently shrinks below n, any version of reset() + * is called, or reserve_back() is called again. + */ + void reserve_back(int n) { + SkASSERT(n >= 0); + if (n > 0) { + this->checkRealloc(n, kExactFit); + } + } + + void removeShuffle(int n) { + SkASSERT(n < this->size()); + int newCount = fSize - 1; + fSize = newCount; + fData[n].~T(); + if (n != newCount) { + this->move(n, newCount); + } + } + + // Is the array empty. + bool empty() const { return fSize == 0; } + + /** + * Adds 1 new default-initialized T value and returns it by reference. Note + * the reference only remains valid until the next call that adds or removes + * elements. + */ + T& push_back() { + void* newT = this->push_back_raw(1); + return *new (newT) T; + } + + /** + * Version of above that uses a copy constructor to initialize the new item + */ + T& push_back(const T& t) { + void* newT = this->push_back_raw(1); + return *new (newT) T(t); + } + + /** + * Version of above that uses a move constructor to initialize the new item + */ + T& push_back(T&& t) { + void* newT = this->push_back_raw(1); + return *new (newT) T(std::move(t)); + } + + /** + * Construct a new T at the back of this array. + */ + template T& emplace_back(Args&&... args) { + void* newT = this->push_back_raw(1); + return *new (newT) T(std::forward(args)...); + } + + /** + * Allocates n more default-initialized T values, and returns the address of + * the start of that new range. Note: this address is only valid until the + * next API call made on the array that might add or remove elements. + */ + T* push_back_n(int n) { + SkASSERT(n >= 0); + T* newTs = TCast(this->push_back_raw(n)); + for (int i = 0; i < n; ++i) { + new (&newTs[i]) T; + } + return newTs; + } + + /** + * Version of above that uses a copy constructor to initialize all n items + * to the same T. + */ + T* push_back_n(int n, const T& t) { + SkASSERT(n >= 0); + T* newTs = TCast(this->push_back_raw(n)); + for (int i = 0; i < n; ++i) { + new (&newTs[i]) T(t); + } + return static_cast(newTs); + } + + /** + * Version of above that uses a copy constructor to initialize the n items + * to separate T values. + */ + T* push_back_n(int n, const T t[]) { + SkASSERT(n >= 0); + this->checkRealloc(n, kGrowing); + T* end = this->end(); + for (int i = 0; i < n; ++i) { + new (end + i) T(t[i]); + } + fSize += n; + return end; + } + + /** + * Version of above that uses the move constructor to set n items. + */ + T* move_back_n(int n, T* t) { + SkASSERT(n >= 0); + this->checkRealloc(n, kGrowing); + T* end = this->end(); + for (int i = 0; i < n; ++i) { + new (end + i) T(std::move(t[i])); + } + fSize += n; + return end; + } + + /** + * Removes the last element. Not safe to call when size() == 0. + */ + void pop_back() { + SkASSERT(fSize > 0); + --fSize; + fData[fSize].~T(); + } + + /** + * Removes the last n elements. Not safe to call when size() < n. + */ + void pop_back_n(int n) { + SkASSERT(n >= 0); + SkASSERT(this->size() >= n); + int i = fSize; + while (i-- > fSize - n) { + (*this)[i].~T(); + } + fSize -= n; + } + + /** + * Pushes or pops from the back to resize. Pushes will be default + * initialized. + */ + void resize_back(int newCount) { + SkASSERT(newCount >= 0); + + if (newCount > this->size()) { + this->push_back_n(newCount - fSize); + } else if (newCount < this->size()) { + this->pop_back_n(fSize - newCount); + } + } + + /** Swaps the contents of this array with that array. Does a pointer swap if possible, + otherwise copies the T values. */ + void swap(TArray& that) { + using std::swap; + if (this == &that) { + return; + } + if (fOwnMemory && that.fOwnMemory) { + swap(fData, that.fData); + swap(fSize, that.fSize); + + // Can't use swap because fCapacity is a bit field. + auto allocCount = fCapacity; + fCapacity = that.fCapacity; + that.fCapacity = allocCount; + } else { + // This could be more optimal... + TArray copy(std::move(that)); + that = std::move(*this); + *this = std::move(copy); + } + } + + T* begin() { + return fData; + } + const T* begin() const { + return fData; + } + + // It's safe to use fItemArray + fSize because if fItemArray is nullptr then adding 0 is + // valid and returns nullptr. See [expr.add] in the C++ standard. + T* end() { + if (fData == nullptr) { + SkASSERT(fSize == 0); + } + return fData + fSize; + } + const T* end() const { + if (fData == nullptr) { + SkASSERT(fSize == 0); + } + return fData + fSize; + } + T* data() { return fData; } + const T* data() const { return fData; } + int size() const { return fSize; } + size_t size_bytes() const { return this->bytes(fSize); } + void resize(size_t count) { this->resize_back((int)count); } + + void clear() { + this->destroyAll(); + fSize = 0; + } + + void shrink_to_fit() { + if (!fOwnMemory || fSize == fCapacity) { + return; + } + if (fSize == 0) { + sk_free(fData); + fData = nullptr; + fCapacity = 0; + } else { + SkSpan allocation = Allocate(fSize); + this->move(TCast(allocation.data())); + if (fOwnMemory) { + sk_free(fData); + } + this->setDataFromBytes(allocation); + } + } + + /** + * Get the i^th element. + */ + T& operator[] (int i) { + SkASSERT(i < this->size()); + SkASSERT(i >= 0); + return fData[i]; + } + + const T& operator[] (int i) const { + SkASSERT(i < this->size()); + SkASSERT(i >= 0); + return fData[i]; + } + + T& at(int i) { return (*this)[i]; } + const T& at(int i) const { return (*this)[i]; } + + /** + * equivalent to operator[](0) + */ + T& front() { SkASSERT(fSize > 0); return fData[0];} + + const T& front() const { SkASSERT(fSize > 0); return fData[0];} + + /** + * equivalent to operator[](size() - 1) + */ + T& back() { SkASSERT(fSize); return fData[fSize - 1];} + + const T& back() const { SkASSERT(fSize > 0); return fData[fSize - 1];} + + /** + * equivalent to operator[](size()-1-i) + */ + T& fromBack(int i) { + SkASSERT(i >= 0); + SkASSERT(i < this->size()); + return fData[fSize - i - 1]; + } + + const T& fromBack(int i) const { + SkASSERT(i >= 0); + SkASSERT(i < this->size()); + return fData[fSize - i - 1]; + } + + bool operator==(const TArray& right) const { + int leftCount = this->size(); + if (leftCount != right.size()) { + return false; + } + for (int index = 0; index < leftCount; ++index) { + if (fData[index] != right.fData[index]) { + return false; + } + } + return true; + } + + bool operator!=(const TArray& right) const { + return !(*this == right); + } + + int capacity() const { + return fCapacity; + } + +protected: + // Creates an empty array that will use the passed storage block until it is insufficiently + // large to hold the entire array. + template + TArray(SkAlignedSTStorage* storage, int size = 0) { + static_assert(InitialCapacity >= 0); + SkASSERT(size >= 0); + SkASSERT(storage->get() != nullptr); + if (size > InitialCapacity) { + this->initData(size); + } else { + this->setDataFromBytes(*storage); + fSize = size; + + // setDataFromBytes always sets fOwnMemory to true, but we are actually using static + // storage here, which shouldn't ever be freed. + fOwnMemory = false; + } + } + + // Copy a C array, using pre-allocated storage if preAllocCount >= count. Otherwise, storage + // will only be used when array shrinks to fit. + template + TArray(const T* array, int size, SkAlignedSTStorage* storage) + : TArray{storage, size} + { + this->copy(array); + } + +private: + // Growth factors for checkRealloc. + static constexpr double kExactFit = 1.0; + static constexpr double kGrowing = 1.5; + + static constexpr int kMinHeapAllocCount = 8; + static_assert(SkIsPow2(kMinHeapAllocCount), "min alloc count not power of two."); + + // Note for 32-bit machines kMaxCapacity will be <= SIZE_MAX. For 64-bit machines it will + // just be INT_MAX if the sizeof(T) < 2^32. + static constexpr int kMaxCapacity = SkToInt(std::min(SIZE_MAX / sizeof(T), (size_t)INT_MAX)); + + void setDataFromBytes(SkSpan allocation) { + T* data = TCast(allocation.data()); + // We have gotten extra bytes back from the allocation limit, pin to kMaxCapacity. It + // would seem like the SkContainerAllocator should handle the divide, but it would have + // to a full divide instruction. If done here the size is known at compile, and usually + // can be implemented by a right shift. The full divide takes ~50X longer than the shift. + size_t size = std::min(allocation.size() / sizeof(T), SkToSizeT(kMaxCapacity)); + setData(SkSpan(data, size)); + } + + void setData(SkSpan array) { + fData = array.data(); + fCapacity = SkToU32(array.size()); + fOwnMemory = true; + } + + // We disable Control-Flow Integrity sanitization (go/cfi) when casting item-array buffers. + // CFI flags this code as dangerous because we are casting `buffer` to a T* while the buffer's + // contents might still be uninitialized memory. When T has a vtable, this is especially risky + // because we could hypothetically access a virtual method on fItemArray and jump to an + // unpredictable location in memory. Of course, TArray won't actually use fItemArray in this + // way, and we don't want to construct a T before the user requests one. There's no real risk + // here, so disable CFI when doing these casts. + SK_CLANG_NO_SANITIZE("cfi") + static T* TCast(void* buffer) { + return (T*)buffer; + } + + size_t bytes(int n) const { + SkASSERT(n <= kMaxCapacity); + return SkToSizeT(n) * sizeof(T); + } + + static SkSpan Allocate(int capacity, double growthFactor = 1.0) { + return SkContainerAllocator{sizeof(T), kMaxCapacity}.allocate(capacity, growthFactor); + } + + void initData(int count) { + this->setDataFromBytes(Allocate(count)); + fSize = count; + } + + void destroyAll() { + if (!this->empty()) { + T* cursor = this->begin(); + T* const end = this->end(); + do { + cursor->~T(); + cursor++; + } while (cursor < end); + } + } + + /** In the following move and copy methods, 'dst' is assumed to be uninitialized raw storage. + * In the following move methods, 'src' is destroyed leaving behind uninitialized raw storage. + */ + void copy(const T* src) { + if constexpr (std::is_trivially_copyable_v) { + if (!this->empty() && src != nullptr) { + sk_careful_memcpy(fData, src, this->size_bytes()); + } + } else { + for (int i = 0; i < this->size(); ++i) { + new (fData + i) T(src[i]); + } + } + } + + void move(int dst, int src) { + if constexpr (MEM_MOVE) { + memcpy(static_cast(&fData[dst]), + static_cast(&fData[src]), + sizeof(T)); + } else { + new (&fData[dst]) T(std::move(fData[src])); + fData[src].~T(); + } + } + + void move(void* dst) { + if constexpr (MEM_MOVE) { + sk_careful_memcpy(dst, fData, this->bytes(fSize)); + } else { + for (int i = 0; i < this->size(); ++i) { + new (static_cast(dst) + this->bytes(i)) T(std::move(fData[i])); + fData[i].~T(); + } + } + } + + // Helper function that makes space for n objects, adjusts the count, but does not initialize + // the new objects. + void* push_back_raw(int n) { + this->checkRealloc(n, kGrowing); + void* ptr = fData + fSize; + fSize += n; + return ptr; + } + + void checkRealloc(int delta, double growthFactor) { + // This constant needs to be declared in the function where it is used to work around + // MSVC's persnickety nature about template definitions. + SkASSERT(delta >= 0); + SkASSERT(fSize >= 0); + SkASSERT(fCapacity >= 0); + + // Return if there are enough remaining allocated elements to satisfy the request. + if (this->capacity() - fSize >= delta) { + return; + } + + // Don't overflow fSize or size_t later in the memory allocation. Overflowing memory + // allocation really only applies to fSizes on 32-bit machines; on 64-bit machines this + // will probably never produce a check. Since kMaxCapacity is bounded above by INT_MAX, + // this also checks the bounds of fSize. + if (delta > kMaxCapacity - fSize) { + sk_report_container_overflow_and_die(); + } + const int newCount = fSize + delta; + + SkSpan allocation = Allocate(newCount, growthFactor); + + this->move(TCast(allocation.data())); + if (fOwnMemory) { + sk_free(fData); + } + this->setDataFromBytes(allocation); + SkASSERT(this->capacity() >= newCount); + SkASSERT(fData != nullptr); + } + + T* fData{nullptr}; + int fSize{0}; + uint32_t fOwnMemory : 1; + uint32_t fCapacity : 31; +}; + +template static inline void swap(TArray& a, TArray& b) { + a.swap(b); +} + +// Subclass of TArray that contains a pre-allocated memory block for the array. +template > +class STArray : private SkAlignedSTStorage, public TArray { + static_assert(N > 0); + using Storage = SkAlignedSTStorage; + +public: + STArray() + : Storage{} + , TArray(this) {} // Must use () to avoid confusion with initializer_list + // when T=bool because * are convertable to bool. + + STArray(const T* array, int count) + : Storage{} + , TArray{array, count, this} {} + + STArray(std::initializer_list data) + : STArray{data.begin(), SkToInt(data.size())} {} + + explicit STArray(int reserveCount) + : STArray() { this->reserve_back(reserveCount); } + + STArray(const STArray& that) + : STArray() { *this = that; } + + explicit STArray(const TArray& that) + : STArray() { *this = that; } + + STArray(STArray&& that) + : STArray() { *this = std::move(that); } + + explicit STArray(TArray&& that) + : STArray() { *this = std::move(that); } + + STArray& operator=(const STArray& that) { + TArray::operator=(that); + return *this; + } + + STArray& operator=(const TArray& that) { + TArray::operator=(that); + return *this; + } + + STArray& operator=(STArray&& that) { + TArray::operator=(std::move(that)); + return *this; + } + + STArray& operator=(TArray&& that) { + TArray::operator=(std::move(that)); + return *this; + } + + // Force the use of TArray for data() and size(). + using TArray::data; + using TArray::size; +}; +} // namespace skia_private +#endif // SkTArray_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h similarity index 81% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h index 1b56266535a56..b08d285378b10 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTDArray.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTDArray.h @@ -8,21 +8,18 @@ #ifndef SkTDArray_DEFINED #define SkTDArray_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTo.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTo.h" #include #include -#include #include -#include -#include class SK_SPI SkTDStorage { public: explicit SkTDStorage(int sizeOfT); - SkTDStorage(const void* src, int count, int sizeOfT); + SkTDStorage(const void* src, int size, int sizeOfT); // Copy SkTDStorage(const SkTDStorage& that); @@ -38,15 +35,15 @@ class SK_SPI SkTDStorage { void swap(SkTDStorage& that); // Size routines - bool empty() const { return fCount == 0; } - void clear() { fCount = 0; } - int size() const { return fCount; } - void resize(int newCount); - size_t size_bytes() const { return this->bytes(fCount); } + bool empty() const { return fSize == 0; } + void clear() { fSize = 0; } + int size() const { return fSize; } + void resize(int newSize); + size_t size_bytes() const { return this->bytes(fSize); } // Capacity routines - int capacity() const { return fReserve; } - void reserve(int newReserve); + int capacity() const { return fCapacity; } + void reserve(int newCapacity); void shrink_to_fit(); void* data() { return fStorage; } @@ -68,8 +65,8 @@ class SK_SPI SkTDStorage { void* insert(int index, int count, const void* src); void pop_back() { - SkASSERT(fCount > 0); - fCount--; + SkASSERT(fSize > 0); + fSize--; } friend bool operator==(const SkTDStorage& a, const SkTDStorage& b); @@ -81,7 +78,7 @@ class SK_SPI SkTDStorage { size_t bytes(int n) const { return SkToSizeT(n * fSizeOfT); } void* address(int n) { return fStorage + this->bytes(n); } - // Adds delta to fCount. Crash if outside [0, INT_MAX] + // Adds delta to fSize. Crash if outside [0, INT_MAX] int calculateSizeOrDie(int delta); // Move the tail of the array defined by the indexes tailStart and tailEnd to dstIndex. The @@ -93,8 +90,8 @@ class SK_SPI SkTDStorage { const int fSizeOfT; std::byte* fStorage{nullptr}; - int fReserve{0}; // size of the allocation in fArray (#elements) - int fCount{0}; // logical number of elements (fCount <= fReserve) + int fCapacity{0}; // size of the allocation in fArray (#elements) + int fSize{0}; // logical number of elements (fSize <= fCapacity) }; static inline void swap(SkTDStorage& a, SkTDStorage& b) { @@ -188,7 +185,7 @@ template class SkTDArray { fStorage.resize(count); } - void reserve(size_t n) { + void reserve(int n) { fStorage.reserve(n); } @@ -219,18 +216,6 @@ template class SkTDArray { fStorage.removeShuffle(index); } - int find(const T& elem) const { - const T* iter = this->begin(); - const T* stop = this->end(); - - for (; iter < stop; iter++) { - if (*iter == elem) { - return SkToInt(iter - this->begin()); - } - } - return -1; - } - // routines to treat the array like a stack void push_back(const T& v) { this->append(); @@ -238,28 +223,6 @@ template class SkTDArray { } void pop_back() { fStorage.pop_back(); } - void deleteAll() { - for (T p : *this) { - delete p; - } - this->reset(); - } - - void freeAll() { - for (T p : *this) { - sk_free(p); - } - - this->reset(); - } - - void unrefAll() { - for (T p : *this) { - p->unref(); - } - this->reset(); - } - void shrink_to_fit() { fStorage.shrink_to_fit(); } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h similarity index 82% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h index a912f13e08c01..365748abef483 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTFitsIn.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTFitsIn.h @@ -8,8 +8,10 @@ #ifndef SkTFitsIn_DEFINED #define SkTFitsIn_DEFINED +#include "include/private/base/SkDebug.h" + +#include #include -#include #include /** @@ -71,28 +73,32 @@ static constexpr inline typename std::enable_if<(std::is_integral::value || std::is_enum::value) && (std::is_integral::value || std::is_enum::value), bool>::type /*bool*/ SkTFitsIn(S src) { + // Ensure that is_signed and is_unsigned are passed the arithmetic underlyng types of enums. + using Sa = typename sk_strip_enum::type; + using Da = typename sk_strip_enum::type; + // SkTFitsIn() is used in public headers, so needs to be written targeting at most C++11. return // E.g. (int8_t)(uint8_t) int8_t(-1) == -1, but the uint8_t == 255, not -1. - (std::is_signed::value && std::is_unsigned::value && sizeof(S) <= sizeof(D)) ? + (std::is_signed::value && std::is_unsigned::value && sizeof(Sa) <= sizeof(Da)) ? (S)0 <= src : // E.g. (uint8_t)(int8_t) uint8_t(255) == 255, but the int8_t == -1. - (std::is_signed::value && std::is_unsigned::value && sizeof(D) <= sizeof(S)) ? - src <= (S)std::numeric_limits::type>::max() : + (std::is_signed::value && std::is_unsigned::value && sizeof(Da) <= sizeof(Sa)) ? + src <= (S)std::numeric_limits::max() : #if !defined(SK_DEBUG) && !defined(__MSVC_RUNTIME_CHECKS ) // Correct (simple) version. This trips up MSVC's /RTCc run-time checking. (S)(D)src == src; #else // More complex version that's safe with /RTCc. Used in all debug builds, for coverage. - (std::is_signed::value) ? - (intmax_t)src >= (intmax_t)std::numeric_limits::type>::min() && - (intmax_t)src <= (intmax_t)std::numeric_limits::type>::max() : + (std::is_signed::value) ? + (intmax_t)src >= (intmax_t)std::numeric_limits::min() && + (intmax_t)src <= (intmax_t)std::numeric_limits::max() : // std::is_unsigned ? - (uintmax_t)src <= (uintmax_t)std::numeric_limits::type>::max(); + (uintmax_t)src <= (uintmax_t)std::numeric_limits::max(); #endif } diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h similarity index 98% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h index dce0dc804becd..26f363c94699e 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTLogic.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTLogic.h @@ -14,7 +14,7 @@ #include #include -#include "include/private/SkTo.h" +#include "include/private/base/SkTo.h" // The sknonstd namespace contains things we would like to be proposed and feel std-ish. namespace sknonstd { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTPin.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTPin.h similarity index 100% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTPin.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTPin.h diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h similarity index 73% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h index 16b0e0e586a29..cbcf36c5943b8 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTemplates.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTemplates.h @@ -8,18 +8,21 @@ #ifndef SkTemplates_DEFINED #define SkTemplates_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkMalloc.h" -#include "include/private/SkTLogic.h" +#include "include/private/base/SkAlign.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkDebug.h" +#include "include/private/base/SkMalloc.h" +#include "include/private/base/SkTLogic.h" -#include #include #include +#include +#include #include -#include #include #include + /** \file SkTemplates.h This file contains light-weight template classes for type-safe and exception-safe @@ -32,6 +35,17 @@ */ template inline void sk_ignore_unused_variable(const T&) { } +/** + * This is a general purpose absolute-value function. + * See SkAbs32 in (SkSafe32.h) for a 32-bit int specific version that asserts. + */ +template static inline T SkTAbs(T value) { + if (value < 0) { + value = -value; + } + return value; +} + /** * Returns a pointer to a D which comes immediately after S[count]. */ @@ -48,14 +62,16 @@ template inline D* SkTAddOffset(S* ptr, ptrdiff_t byteO return reinterpret_cast(reinterpret_cast*>(ptr) + byteOffset); } -// TODO: when C++17 the language is available, use template -template struct SkFunctionWrapper { +template struct SkOverloadedFunctionObject { template auto operator()(Args&&... args) const -> decltype(P(std::forward(args)...)) { return P(std::forward(args)...); } }; +template using SkFunctionObject = + SkOverloadedFunctionObject, F>; + /** \class SkAutoTCallVProc Call a function when this goes out of scope. The template uses two @@ -65,8 +81,8 @@ template struct SkFunctionWrapper { function. */ template class SkAutoTCallVProc - : public std::unique_ptr, P>> { - using inherited = std::unique_ptr, P>>; + : public std::unique_ptr> { + using inherited = std::unique_ptr>; public: using inherited::inherited; SkAutoTCallVProc(const SkAutoTCallVProc&) = delete; @@ -75,14 +91,16 @@ template class SkAutoTCallVProc operator T*() const { return this->get(); } }; + +namespace skia_private { /** Allocate an array of T elements, and free the array in the destructor */ -template class SkAutoTArray { +template class AutoTArray { public: - SkAutoTArray() {} + AutoTArray() {} /** Allocate count number of T elements */ - explicit SkAutoTArray(int count) { + explicit AutoTArray(int count) { SkASSERT(count >= 0); if (count) { fArray.reset(new T[count]); @@ -90,10 +108,10 @@ template class SkAutoTArray { SkDEBUGCODE(fCount = count;) } - SkAutoTArray(SkAutoTArray&& other) : fArray(std::move(other.fArray)) { + AutoTArray(AutoTArray&& other) : fArray(std::move(other.fArray)) { SkDEBUGCODE(fCount = other.fCount; other.fCount = 0;) } - SkAutoTArray& operator=(SkAutoTArray&& other) { + AutoTArray& operator=(AutoTArray&& other) { if (this != &other) { fArray = std::move(other.fArray); SkDEBUGCODE(fCount = other.fCount; other.fCount = 0;) @@ -103,7 +121,7 @@ template class SkAutoTArray { /** Reallocates given a new count. Reallocation occurs even if new count equals old count. */ - void reset(int count = 0) { *this = SkAutoTArray(count); } + void reset(int count = 0) { *this = AutoTArray(count); } /** Return the array of T elements. Will be NULL if count == 0 */ @@ -125,30 +143,30 @@ template class SkAutoTArray { SkDEBUGCODE(int fCount = 0;) }; -/** Wraps SkAutoTArray, with room for kCountRequested elements preallocated. +/** Wraps AutoTArray, with room for kCountRequested elements preallocated. */ -template class SkAutoSTArray { +template class AutoSTArray { public: - SkAutoSTArray(SkAutoSTArray&&) = delete; - SkAutoSTArray(const SkAutoSTArray&) = delete; - SkAutoSTArray& operator=(SkAutoSTArray&&) = delete; - SkAutoSTArray& operator=(const SkAutoSTArray&) = delete; + AutoSTArray(AutoSTArray&&) = delete; + AutoSTArray(const AutoSTArray&) = delete; + AutoSTArray& operator=(AutoSTArray&&) = delete; + AutoSTArray& operator=(const AutoSTArray&) = delete; /** Initialize with no objects */ - SkAutoSTArray() { + AutoSTArray() { fArray = nullptr; fCount = 0; } /** Allocate count number of T elements */ - SkAutoSTArray(int count) { + AutoSTArray(int count) { fArray = nullptr; fCount = 0; this->reset(count); } - ~SkAutoSTArray() { + ~AutoSTArray() { this->reset(0); } @@ -216,8 +234,8 @@ template class SkAutoSTArray { private: #if defined(SK_BUILD_FOR_GOOGLE3) - // Stack frame size is limited for SK_BUILD_FOR_GOOGLE3. 4k is less than the actual max, but some functions - // have multiple large stack allocations. + // Stack frame size is limited for SK_BUILD_FOR_GOOGLE3. 4k is less than the actual max, + // but some functions have multiple large stack allocations. static const int kMaxBytes = 4 * 1024; static const int kCount = kCountRequested * sizeof(T) > kMaxBytes ? kMaxBytes / sizeof(T) @@ -226,10 +244,9 @@ template class SkAutoSTArray { static const int kCount = kCountRequested; #endif - int fCount; - T* fArray; - // since we come right after fArray, fStorage should be properly aligned - char fStorage[kCount * sizeof(T)]; + int fCount; + T* fArray; + alignas(T) char fStorage[kCount * sizeof(T)]; }; /** Manages an array of T elements, freeing the array in the destructor. @@ -238,17 +255,17 @@ template class SkAutoSTArray { template ::value && std::is_trivially_destructible::value>> -class SkAutoTMalloc { +class AutoTMalloc { public: /** Takes ownership of the ptr. The ptr must be a value which can be passed to sk_free. */ - explicit SkAutoTMalloc(T* ptr = nullptr) : fPtr(ptr) {} + explicit AutoTMalloc(T* ptr = nullptr) : fPtr(ptr) {} /** Allocates space for 'count' Ts. */ - explicit SkAutoTMalloc(size_t count) + explicit AutoTMalloc(size_t count) : fPtr(count ? (T*)sk_malloc_throw(count, sizeof(T)) : nullptr) {} - SkAutoTMalloc(SkAutoTMalloc&&) = default; - SkAutoTMalloc& operator=(SkAutoTMalloc&&) = default; + AutoTMalloc(AutoTMalloc&&) = default; + AutoTMalloc& operator=(AutoTMalloc&&) = default; /** Resize the memory area pointed to by the current ptr preserving contents. */ void realloc(size_t count) { @@ -283,18 +300,18 @@ class SkAutoTMalloc { T* release() { return fPtr.release(); } private: - std::unique_ptr> fPtr; + std::unique_ptr> fPtr; }; template ::value && std::is_trivially_destructible::value>> -class SkAutoSTMalloc { +class AutoSTMalloc { public: - SkAutoSTMalloc() : fPtr(fTStorage) {} + AutoSTMalloc() : fPtr(fTStorage) {} - SkAutoSTMalloc(size_t count) { + AutoSTMalloc(size_t count) { if (count > kCount) { fPtr = (T*)sk_malloc_throw(count, sizeof(T)); } else if (count) { @@ -304,12 +321,12 @@ class SkAutoSTMalloc { } } - SkAutoSTMalloc(SkAutoSTMalloc&&) = delete; - SkAutoSTMalloc(const SkAutoSTMalloc&) = delete; - SkAutoSTMalloc& operator=(SkAutoSTMalloc&&) = delete; - SkAutoSTMalloc& operator=(const SkAutoSTMalloc&) = delete; + AutoSTMalloc(AutoSTMalloc&&) = delete; + AutoSTMalloc(const AutoSTMalloc&) = delete; + AutoSTMalloc& operator=(AutoSTMalloc&&) = delete; + AutoSTMalloc& operator=(const AutoSTMalloc&) = delete; - ~SkAutoSTMalloc() { + ~AutoSTMalloc() { if (fPtr != fTStorage) { sk_free(fPtr); } @@ -391,27 +408,9 @@ class SkAutoSTMalloc { }; }; -////////////////////////////////////////////////////////////////////////////////////////////////// +using UniqueVoidPtr = std::unique_ptr>; -template class SkAlignedSTStorage { -public: - SkAlignedSTStorage() {} - SkAlignedSTStorage(SkAlignedSTStorage&&) = delete; - SkAlignedSTStorage(const SkAlignedSTStorage&) = delete; - SkAlignedSTStorage& operator=(SkAlignedSTStorage&&) = delete; - SkAlignedSTStorage& operator=(const SkAlignedSTStorage&) = delete; - - /** - * Returns void* because this object does not initialize the - * memory. Use placement new for types that require a constructor. - */ - void* get() { return fStorage; } - const void* get() const { return fStorage; } -private: - alignas(T) char fStorage[sizeof(T)*N]; -}; - -using SkAutoFree = std::unique_ptr>; +} // namespace skia_private template constexpr auto SkMakeArrayFromIndexSequence(C c, std::index_sequence is) @@ -424,28 +423,4 @@ template constexpr auto SkMakeArray(C c) return SkMakeArrayFromIndexSequence(c, std::make_index_sequence{}); } -/** - * Trait for identifying types which are relocatable via memcpy, for container optimizations. - * - */ -template -struct sk_has_trivially_relocatable_member : std::false_type {}; - -// Types can declare themselves trivially relocatable with a public -// using sk_is_trivially_relocatable = std::true_type; -template -struct sk_has_trivially_relocatable_member> - : T::sk_is_trivially_relocatable {}; - -// By default, all trivially copyable types are trivially relocatable. -template -struct sk_is_trivially_relocatable - : std::disjunction, sk_has_trivially_relocatable_member ->{}; - -// Here be some dragons: while technically not guaranteed, we count on all sane unique_ptr -// implementations to be trivially relocatable. -template -struct sk_is_trivially_relocatable> : std::true_type {}; - #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkThreadAnnotations.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadAnnotations.h similarity index 100% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkThreadAnnotations.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadAnnotations.h diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h similarity index 69% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h index e14388b3de5bd..18984884c96f7 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkThreadID.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkThreadID.h @@ -8,11 +8,14 @@ #ifndef SkThreadID_DEFINED #define SkThreadID_DEFINED -#include "include/core/SkTypes.h" +#include "include/private/base/SkAPI.h" +#include "include/private/base/SkDebug.h" + +#include typedef int64_t SkThreadID; -// SkMutex.h uses SkGetThredID in debug only code. +// SkMutex.h uses SkGetThreadID in debug only code. SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID(); const SkThreadID kIllegalThreadID = 0; diff --git a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h similarity index 71% rename from ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h index d788f7b269dad..51ccafeeaf754 100644 --- a/ios/vendored/sdk47/@shopify/react-native-skia/cpp/skia/include/private/SkTo.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTo.h @@ -7,8 +7,11 @@ #ifndef SkTo_DEFINED #define SkTo_DEFINED -#include "include/core/SkTypes.h" -#include "include/private/SkTFitsIn.h" +#include "include/private/base/SkAssert.h" +#include "include/private/base/SkTFitsIn.h" + +#include +#include template constexpr D SkTo(S s) { return SkASSERT(SkTFitsIn(s)), @@ -21,8 +24,16 @@ template constexpr int16_t SkToS16(S x) { return SkTo(x template constexpr uint16_t SkToU16(S x) { return SkTo(x); } template constexpr int32_t SkToS32(S x) { return SkTo(x); } template constexpr uint32_t SkToU32(S x) { return SkTo(x); } +template constexpr int64_t SkToS64(S x) { return SkTo(x); } +template constexpr uint64_t SkToU64(S x) { return SkTo(x); } template constexpr int SkToInt(S x) { return SkTo(x); } template constexpr unsigned SkToUInt(S x) { return SkTo(x); } template constexpr size_t SkToSizeT(S x) { return SkTo(x); } +/** @return false or true based on the condition +*/ +template static constexpr bool SkToBool(const T& x) { + return (bool)x; +} + #endif // SkTo_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h new file mode 100644 index 0000000000000..736f7897763d5 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/base/SkTypeTraits.h @@ -0,0 +1,33 @@ +// 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 SkTypeTraits_DEFINED +#define SkTypeTraits_DEFINED + +#include +#include + +// Trait for identifying types which are relocatable via memcpy, for container optimizations. +template +struct sk_has_trivially_relocatable_member : std::false_type {}; + +// Types can declare themselves trivially relocatable with a public +// using sk_is_trivially_relocatable = std::true_type; +template +struct sk_has_trivially_relocatable_member> + : T::sk_is_trivially_relocatable {}; + +// By default, all trivially copyable types are trivially relocatable. +template +struct sk_is_trivially_relocatable + : std::disjunction, sk_has_trivially_relocatable_member>{}; + +// Here be some dragons: while technically not guaranteed, we count on all sane unique_ptr +// implementations to be trivially relocatable. +template +struct sk_is_trivially_relocatable> : std::true_type {}; + +template +inline constexpr bool sk_is_trivially_relocatable_v = sk_is_trivially_relocatable::value; + +#endif // SkTypeTraits_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h new file mode 100644 index 0000000000000..51ed8a804defe --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h @@ -0,0 +1,130 @@ +/* + * Copyright 2019 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrVkSecondaryCBDrawContext_DEFINED +#define GrVkSecondaryCBDrawContext_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/core/SkSurfaceProps.h" +#include "include/core/SkTypes.h" + +#include + +class GrBackendSemaphore; +class GrRecordingContext; +struct GrVkDrawableInfo; +namespace skgpu::ganesh { +class Device; +} +class SkCanvas; +class SkDeferredDisplayList; +struct SkImageInfo; +class SkSurfaceCharacterization; +class SkSurfaceProps; + +/** + * This class is a private header that is intended to only be used inside of Chromium. This requires + * Chromium to burrow in and include this specifically since it is not part of skia's public include + * directory. + */ + +/** + * This class is used to draw into an external Vulkan secondary command buffer that is imported + * by the client. The secondary command buffer that gets imported must already have had begin called + * on it with VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT. Thus any draws to the imported + * command buffer cannot require changing the render pass. This requirement means that certain types + * of draws will not be supported when using a GrVkSecondaryCBDrawContext. This includes: + * Draws that require a dst copy for blending will be dropped + * Text draws will be dropped (these may require intermediate uploads of text data) + * Read and Write pixels will not work + * Any other draw that requires a copy will fail (this includes using backdrop filter with save + * layer). + * Stenciling is also disabled, but that should not restrict any actual draws from working. + * + * While using a GrVkSecondaryCBDrawContext, the client can also draw into normal SkSurfaces and + * then draw those SkSufaces (as SkImages) into the GrVkSecondaryCBDrawContext. If any of the + * previously mentioned unsupported draws are needed by the client, they can draw them into an + * offscreen surface, and then draw that into the GrVkSecondaryCBDrawContext. + * + * After all drawing to the GrVkSecondaryCBDrawContext has been done, the client must call flush() + * on the GrVkSecondaryCBDrawContext to actually fill in the secondary VkCommandBuffer with the + * draws. + * + * Additionally, the client must keep the GrVkSecondaryCBDrawContext alive until the secondary + * VkCommandBuffer has been submitted and all work finished on the GPU. Before deleting the + * GrVkSecondaryCBDrawContext, the client must call releaseResources() so that Skia can cleanup + * any internal objects that were created for the draws into the secondary command buffer. + */ +class SK_SPI GrVkSecondaryCBDrawContext : public SkRefCnt { +public: + static sk_sp Make(GrRecordingContext*, + const SkImageInfo&, + const GrVkDrawableInfo&, + const SkSurfaceProps* props); + + ~GrVkSecondaryCBDrawContext() override; + + SkCanvas* getCanvas(); + + // Records all the draws to the imported secondary command buffer and sets any dependent + // offscreen draws to the GPU. + void flush(); + + /** Inserts a list of GPU semaphores that Skia will have the driver wait on before executing + commands for this secondary CB. The wait semaphores will get added to the VkCommandBuffer + owned by this GrContext when flush() is called, and not the command buffer which the + Secondary CB is from. This will guarantee that the driver waits on the semaphores before + the secondary command buffer gets executed. If this call returns false, then the GPU + back end will not wait on any passed in semaphores, and the client will still own the + semaphores, regardless of the value of deleteSemaphoresAfterWait. + + If deleteSemaphoresAfterWait is false then Skia will not delete the semaphores. In this case + it is the client's responsibility to not destroy or attempt to reuse the semaphores until it + knows that Skia has finished waiting on them. This can be done by using finishedProcs + on flush calls. + + @param numSemaphores size of waitSemaphores array + @param waitSemaphores array of semaphore containers + @paramm deleteSemaphoresAfterWait who owns and should delete the semaphores + @return true if GPU is waiting on semaphores + */ + bool wait(int numSemaphores, + const GrBackendSemaphore waitSemaphores[], + bool deleteSemaphoresAfterWait = true); + + // This call will release all resources held by the draw context. The client must call + // releaseResources() before deleting the drawing context. However, the resources also include + // any Vulkan resources that were created and used for draws. Therefore the client must only + // call releaseResources() after submitting the secondary command buffer, and waiting for it to + // finish on the GPU. If it is called earlier then some vulkan objects may be deleted while they + // are still in use by the GPU. + void releaseResources(); + + const SkSurfaceProps& props() const { return fProps; } + + // TODO: Fill out these calls to support DDL + bool characterize(SkSurfaceCharacterization* characterization) const; + +#ifndef SK_DDL_IS_UNIQUE_POINTER + bool draw(sk_sp deferredDisplayList); +#else + bool draw(const SkDeferredDisplayList* deferredDisplayList); +#endif + + bool isCompatible(const SkSurfaceCharacterization& characterization) const; + +private: + explicit GrVkSecondaryCBDrawContext(sk_sp, const SkSurfaceProps*); + + sk_sp fDevice; + std::unique_ptr fCachedCanvas; + const SkSurfaceProps fProps; + + using INHERITED = SkRefCnt; +}; + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h index 55568b9af75a9..962d183b2d979 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h @@ -13,6 +13,7 @@ #include "include/core/SkData.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTypeface.h" #include "include/utils/SkNoDrawCanvas.h" struct SkPackedGlyphID; @@ -21,7 +22,6 @@ class SkStrikeCache; class SkStrikeClientImpl; class SkStrikeServer; class SkStrikeServerImpl; -class SkTypeface; namespace sktext::gpu { class Slug; } using SkDiscardableHandleId = uint32_t; @@ -62,9 +62,6 @@ class SkStrikeServer { bool DFTSupport, bool DFTPerspSupport = true); - // Serializes the typeface to be transmitted using this server. - SK_SPI sk_sp serializeTypeface(SkTypeface*); - // Serializes the strike data captured using a canvas returned by ::makeAnalysisCanvas. Any // handles locked using the DiscardableHandleManager will be assumed to be // unlocked after this call. @@ -128,10 +125,6 @@ class SkStrikeClient { SkStrikeCache* strikeCache = nullptr); SK_SPI ~SkStrikeClient(); - // Deserializes the typeface previously serialized using the SkStrikeServer. Returns null if the - // data is invalid. - SK_SPI sk_sp deserializeTypeface(const void* data, size_t length); - // Deserializes the strike data from a SkStrikeServer. All messages generated // from a server when serializing the ops must be deserialized before the op // is rasterized. @@ -142,9 +135,12 @@ class SkStrikeClient { // corresponding typefaceID on the GPU. SK_SPI bool translateTypefaceID(SkAutoDescriptor* descriptor) const; + // Testing helpers + sk_sp retrieveTypefaceUsingServerIDForTest(SkTypefaceID) const; + // Given a buffer, unflatten into a slug making sure to do the typefaceID translation from // renderer to GPU. Returns nullptr if there was a problem. - sk_sp deserializeSlug(const void* data, size_t size) const; + sk_sp deserializeSlugForTest(const void* data, size_t size) const; private: std::unique_ptr fImpl; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h new file mode 100644 index 0000000000000..ade4d71aa7497 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/SkDiscardableMemory.h @@ -0,0 +1,70 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkDiscardableMemory_DEFINED +#define SkDiscardableMemory_DEFINED + +#include "include/core/SkRefCnt.h" +#include "include/core/SkTypes.h" + +/** + * Interface for discardable memory. Implementation is provided by the + * embedder. + */ +class SK_SPI SkDiscardableMemory { +public: + /** + * Factory method that creates, initializes and locks an SkDiscardableMemory + * object. If either of these steps fails, a nullptr pointer will be returned. + */ + static SkDiscardableMemory* Create(size_t bytes); + + /** + * Factory class that creates, initializes and locks an SkDiscardableMemory + * object. If either of these steps fails, a nullptr pointer will be returned. + */ + class Factory : public SkRefCnt { + public: + virtual SkDiscardableMemory* create(size_t bytes) = 0; + private: + using INHERITED = SkRefCnt; + }; + + /** Must not be called while locked. + */ + virtual ~SkDiscardableMemory() {} + + /** + * Locks the memory, prevent it from being discarded. Once locked. you may + * obtain a pointer to that memory using the data() method. + * + * lock() may return false, indicating that the underlying memory was + * discarded and that the lock failed. + * + * Nested calls to lock are not allowed. + */ + virtual bool SK_WARN_UNUSED_RESULT lock() = 0; + + /** + * Returns the current pointer for the discardable memory. This call is ONLY + * valid when the discardable memory object is locked. + */ + virtual void* data() = 0; + + /** + * Unlock the memory so that it can be purged by the system. Must be called + * after every successful lock call. + */ + virtual void unlock() = 0; + +protected: + SkDiscardableMemory() = default; + SkDiscardableMemory(const SkDiscardableMemory&) = delete; + SkDiscardableMemory& operator=(const SkDiscardableMemory&) = delete; +}; + +#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h index 0f4d9773db776..6775af0fc6966 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/chromium/Slug.h @@ -21,14 +21,6 @@ class SkStrikeClient; class SkWriteBuffer; namespace sktext::gpu { - -// You can use Slug to simulate drawTextBlob by defining the following at compile time. -// SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG -// You can use Slug serialization to simulate drawTextBlob by defining the following: -// SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE -// For Skia, add this to your args.gn file. -// extra_cflags = ["-D", "SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG"] - // Slug encapsulates an SkTextBlob at a specific origin, using a specific paint. It can be // manipulated using matrix and clip changes to the canvas. If the canvas is transformed, then // the Slug will also transform with smaller glyphs using bi-linear interpolation to render. You @@ -70,7 +62,6 @@ class SK_API Slug : public SkRefCnt { static uint32_t NextUniqueID(); const uint32_t fUniqueID{NextUniqueID()}; }; - } // namespace sktext::gpu #endif // sktext_gpu_Slug_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h index 847e76f23252e..ba7172e005ae5 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h @@ -19,6 +19,7 @@ class GrContextThreadSafeProxy; class GrDirectContext; class GrImageContext; class GrRecordingContext; +enum class SkTextureCompressionType; class GrContext_Base : public SkRefCnt { public: @@ -43,7 +44,7 @@ class GrContext_Base : public SkRefCnt { */ SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const; - SK_API GrBackendFormat compressedBackendFormat(SkImage::CompressionType) const; + SK_API GrBackendFormat compressedBackendFormat(SkTextureCompressionType) const; /** * Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h index 049c07bff63be..26b75344760ee 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h @@ -65,7 +65,7 @@ struct GrD3DTextureResourceSpecHolder { GrD3DSurfaceInfo getSurfaceInfo(uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected) const; + skgpu::Protected isProtected) const; private: GrD3DTextureResourceSpec* fSpec; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h index 5eacf2ea2d263..ffcdc0eaaf49e 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h @@ -20,7 +20,7 @@ struct GrDawnTextureSpec { GrDawnSurfaceInfo GrDawnTextureSpecToSurfaceInfo(const GrDawnTextureSpec& dawnSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h index e951fbd17cfa5..7db777487aecc 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h @@ -103,6 +103,6 @@ struct GrGLTextureSpec { GrGLSurfaceInfo GrGLTextureSpecToSurfaceInfo(const GrGLTextureSpec& glSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h index 5a1a7a32d6241..72fdd4433d065 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrImageContext.h @@ -8,7 +8,7 @@ #ifndef GrImageContext_DEFINED #define GrImageContext_DEFINED -#include "include/private/SingleOwner.h" +#include "include/private/base/SingleOwner.h" #include "include/private/gpu/ganesh/GrContext_Base.h" class GrImageContextPriv; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h index fc72c7fd93bed..59a608dcfca0d 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h @@ -8,18 +8,19 @@ #ifndef GrMockTypesPriv_DEFINED #define GrMockTypesPriv_DEFINED +#include "include/core/SkTextureCompressionType.h" #include "include/gpu/mock/GrMockTypes.h" struct GrMockTextureSpec { GrMockTextureSpec() : fColorType(GrColorType::kUnknown) - , fCompressionType(SkImage::CompressionType::kNone) {} + , fCompressionType(SkTextureCompressionType::kNone) {} GrMockTextureSpec(const GrMockSurfaceInfo& info) : fColorType(info.fColorType) , fCompressionType(info.fCompressionType) {} GrColorType fColorType = GrColorType::kUnknown; - SkImage::CompressionType fCompressionType = SkImage::CompressionType::kNone; + SkTextureCompressionType fCompressionType = SkTextureCompressionType::kNone; }; GrMockSurfaceInfo GrMockTextureSpecToSurfaceInfo(const GrMockTextureSpec& mockSpec, diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h index 550d01760f946..ef65848b5e15a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h @@ -68,7 +68,7 @@ struct GrMtlTextureSpec { GrMtlSurfaceInfo GrMtlTextureSpecToSurfaceInfo(const GrMtlTextureSpec& mtlSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif // __APPLE__ diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h index b663ff2b193ee..84e2346348503 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h @@ -8,28 +8,21 @@ #ifndef GrTypesPriv_DEFINED #define GrTypesPriv_DEFINED -#include -#include "include/core/SkImage.h" +#include "include/core/SkColor.h" #include "include/core/SkImageInfo.h" #include "include/core/SkPath.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTextureCompressionType.h" #include "include/gpu/GrTypes.h" -#include "include/private/SkImageInfoPriv.h" -#include "include/private/SkMacros.h" +#include "include/private/base/SkMacros.h" +#include "include/private/base/SkTypeTraits.h" + +#include class GrBackendFormat; class GrCaps; class GrSurfaceProxy; -// The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might -// not actually be monotonic, depending on how libstdc++ was built. However, this is only currently -// used for idle resource purging so it shouldn't cause a correctness problem. -#if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000) -using GrStdSteadyClock = std::chrono::monotonic_clock; -#else -using GrStdSteadyClock = std::chrono::steady_clock; -#endif - /** * divide, rounding up */ @@ -643,6 +636,7 @@ static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct) { case kRGB_101010x_SkColorType: return GrColorType::kUnknown; case kBGRA_1010102_SkColorType: return GrColorType::kBGRA_1010102; case kBGR_101010x_SkColorType: return GrColorType::kUnknown; + case kBGR_101010x_XR_SkColorType: return GrColorType::kUnknown; case kRGBA_F32_SkColorType: return GrColorType::kRGBA_F32; case kR8G8_unorm_SkColorType: return GrColorType::kRG_88; case kA16_unorm_SkColorType: return GrColorType::kAlpha_16; @@ -924,12 +918,12 @@ static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct) { // In general we try to not mix CompressionType and ColorType, but currently SkImage still requires // an SkColorType even for CompressedTypes so we need some conversion. -static constexpr SkColorType GrCompressionTypeToSkColorType(SkImage::CompressionType compression) { +static constexpr SkColorType GrCompressionTypeToSkColorType(SkTextureCompressionType compression) { switch (compression) { - case SkImage::CompressionType::kNone: return kUnknown_SkColorType; - case SkImage::CompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType; - case SkImage::CompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType; - case SkImage::CompressionType::kBC1_RGBA8_UNORM: return kRGBA_8888_SkColorType; + case SkTextureCompressionType::kNone: return kUnknown_SkColorType; + case SkTextureCompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType; + case SkTextureCompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType; + case SkTextureCompressionType::kBC1_RGBA8_UNORM: return kRGBA_8888_SkColorType; } SkUNREACHABLE; @@ -995,12 +989,12 @@ static constexpr const char* GrColorTypeToStr(GrColorType ct) { SkUNREACHABLE; } -static constexpr const char* GrCompressionTypeToStr(SkImage::CompressionType compression) { +static constexpr const char* GrCompressionTypeToStr(SkTextureCompressionType compression) { switch (compression) { - case SkImage::CompressionType::kNone: return "kNone"; - case SkImage::CompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM"; - case SkImage::CompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM"; - case SkImage::CompressionType::kBC1_RGBA8_UNORM: return "kBC1_RGBA8_UNORM"; + case SkTextureCompressionType::kNone: return "kNone"; + case SkTextureCompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM"; + case SkTextureCompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM"; + case SkTextureCompressionType::kBC1_RGBA8_UNORM: return "kBC1_RGBA8_UNORM"; } SkUNREACHABLE; } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h index a68d467dd8c92..f300a7139632b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h @@ -35,7 +35,7 @@ struct GrVkBackendSurfaceInfo { GrVkImageInfo snapImageInfo(const skgpu::MutableTextureStateRef*) const; - bool isProtected() const { return fImageInfo.fProtected == GrProtected::kYes; } + bool isProtected() const { return fImageInfo.fProtected == skgpu::Protected::kYes; } #if GR_TEST_UTILS bool operator==(const GrVkBackendSurfaceInfo& that) const; #endif @@ -68,6 +68,6 @@ struct GrVkImageSpec { GrVkSurfaceInfo GrVkImageSpecToSurfaceInfo(const GrVkImageSpec& vkSpec, uint32_t sampleCount, uint32_t levelCount, - GrProtected isProtected); + skgpu::Protected isProtected); #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h new file mode 100644 index 0000000000000..bbf401c95e48d --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h @@ -0,0 +1,38 @@ +/* + * 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 skgpu_graphite_DawnTypesPriv_DEFINED +#define skgpu_graphite_DawnTypesPriv_DEFINED + +#include "include/gpu/graphite/dawn/DawnTypes.h" + +namespace skgpu::graphite { + +struct DawnTextureSpec { + DawnTextureSpec() + : fFormat(wgpu::TextureFormat::Undefined) + , fUsage(wgpu::TextureUsage::None) {} + DawnTextureSpec(const DawnTextureInfo& info) + : fFormat(info.fFormat) + , fUsage(info.fUsage) {} + + bool operator==(const DawnTextureSpec& that) const { + return fUsage == that.fUsage && + fFormat == that.fFormat; + } + + wgpu::TextureFormat fFormat; + wgpu::TextureUsage fUsage; +}; + +DawnTextureInfo DawnTextureSpecToTextureInfo(const DawnTextureSpec& dawnSpec, + uint32_t sampleCount, + Mipmapped mipmapped); + +} // namespace skgpu::graphite + +#endif // skgpu_graphite_DawnTypesPriv_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h similarity index 87% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h index 697628a84d939..bf26aa2a78ad3 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlTypesPriv.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h @@ -5,11 +5,11 @@ * found in the LICENSE file. */ -#ifndef skgpu_graphite_MtlTypesPriv_DEFINED -#define skgpu_graphite_MtlTypesPriv_DEFINED +#ifndef skgpu_graphite_MtlGraphiteTypesPriv_DEFINED +#define skgpu_graphite_MtlGraphiteTypesPriv_DEFINED #include "include/gpu/graphite/GraphiteTypes.h" -#include "include/gpu/graphite/mtl/MtlTypes.h" +#include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" /////////////////////////////////////////////////////////////////////////////// @@ -67,8 +67,8 @@ struct MtlTextureSpec { MtlTextureInfo MtlTextureSpecToTextureInfo(const MtlTextureSpec& mtlSpec, uint32_t sampleCount, - uint32_t levelCount); + Mipmapped mipmapped); } // namespace skgpu::graphite -#endif // skgpu_graphite_MtlTypesPriv_DEFINED +#endif // skgpu_graphite_MtlGraphiteTypesPriv_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h index e0703d7ef1c86..b4304e3ae8988 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h @@ -19,8 +19,6 @@ struct VulkanTextureSpec { , fImageTiling(VK_IMAGE_TILING_OPTIMAL) , fImageUsageFlags(0) , fSharingMode(VK_SHARING_MODE_EXCLUSIVE) - , fCurrentQueueFamily(VK_QUEUE_FAMILY_IGNORED) - , fImageLayout(VK_IMAGE_LAYOUT_UNDEFINED) , fAspectMask(VK_IMAGE_ASPECT_COLOR_BIT) {} VulkanTextureSpec(const VulkanTextureInfo& info) : fFlags(info.fFlags) @@ -28,8 +26,6 @@ struct VulkanTextureSpec { , fImageTiling(info.fImageTiling) , fImageUsageFlags(info.fImageUsageFlags) , fSharingMode(info.fSharingMode) - , fCurrentQueueFamily(info.fCurrentQueueFamily) - , fImageLayout(info.fImageLayout) , fAspectMask(info.fAspectMask) {} bool operator==(const VulkanTextureSpec& that) const { @@ -38,8 +34,6 @@ struct VulkanTextureSpec { fImageTiling == that.fImageTiling && fImageUsageFlags == that.fImageUsageFlags && fSharingMode == that.fSharingMode && - fCurrentQueueFamily == that.fCurrentQueueFamily && - fImageLayout == that.fImageLayout && fAspectMask == that.fAspectMask; } @@ -48,15 +42,13 @@ struct VulkanTextureSpec { VkImageTiling fImageTiling; VkImageUsageFlags fImageUsageFlags; VkSharingMode fSharingMode; - uint32_t fCurrentQueueFamily; - VkImageLayout fImageLayout; VkImageAspectFlags fAspectMask; // GrVkYcbcrConversionInfo fYcbcrConversionInfo; }; VulkanTextureInfo VulkanTextureSpecToTextureInfo(const VulkanTextureSpec& vkSpec, uint32_t sampleCount, - uint32_t levelCount); + Mipmapped mipmapped); } // namespace skgpu::graphite diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h index c0a9b03bdaa02..ca4bcf108bf45 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/gpu/vk/SkiaVulkan.h @@ -10,6 +10,8 @@ #include "include/core/SkTypes.h" +// IWYU pragma: begin_exports + #if SKIA_IMPLEMENTATION || !defined(SK_VULKAN) #include "include/third_party/vulkan/vulkan/vulkan_core.h" #else @@ -29,4 +31,6 @@ #endif #endif +// IWYU pragma: end_exports + #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h deleted file mode 100644 index 6b9ebd4727730..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSL.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL -#define SKSL_DSL - -#include "include/sksl/DSLBlock.h" -#include "include/sksl/DSLCore.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLFunction.h" -#include "include/sksl/DSLType.h" - -namespace SkSL { - -namespace dsl { - -using Block = DSLBlock; -using Case = DSLCase; -using Expression = DSLExpression; -using Field = DSLField; -using Function = DSLFunction; -using GlobalVar = DSLGlobalVar; -using Layout = DSLLayout; -using Modifiers = DSLModifiers; -using Parameter = DSLParameter; -using Statement = DSLStatement; -using Var = DSLVar; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h deleted file mode 100644 index 959ea2235bacd..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLBlock.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_BLOCK -#define SKSL_DSL_BLOCK - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include - -namespace SkSL { - -class Block; -class SymbolTable; - -namespace dsl { - -class DSLBlock { -public: - template - DSLBlock(Statements... statements) { - fStatements.reserve_back(sizeof...(statements)); - ((void)fStatements.push_back(DSLStatement(statements.release()).release()), ...); - } - - DSLBlock(SkSL::StatementArray statements, std::shared_ptr symbols = nullptr, - Position pos = {}); - - DSLBlock(SkTArray statements, std::shared_ptr symbols = nullptr, - Position pos = {}); - - DSLBlock(DSLBlock&& other) = default; - DSLBlock& operator=(DSLBlock&& other) = default; - - ~DSLBlock() = default; - - void append(DSLStatement stmt); - - std::unique_ptr release(); - -private: - SkSL::StatementArray fStatements; - std::shared_ptr fSymbols; - Position fPosition; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h deleted file mode 100644 index 16780e644a2c9..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCase.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_CASE -#define SKSL_DSL_CASE - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include - -namespace SkSL { - -namespace dsl { - -class DSLCase { -public: - // An empty expression means 'default:'. - template - DSLCase(DSLExpression value, Statements... statements) - : fValue(std::move(value)) { - fStatements.reserve_back(sizeof...(statements)); - ((void)fStatements.push_back(DSLStatement(std::move(statements)).release()), ...); - } - - DSLCase(DSLExpression value, SkTArray statements, - Position pos = {}); - - DSLCase(DSLExpression value, SkSL::StatementArray statements, - Position pos = {}); - - DSLCase(DSLCase&&); - - ~DSLCase(); - - DSLCase& operator=(DSLCase&&); - - void append(DSLStatement stmt); - -private: - DSLExpression fValue; - SkSL::StatementArray fStatements; - Position fPosition; - - friend class DSLCore; - - template - friend DSLStatement Switch(DSLExpression value, Cases... cases); -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h deleted file mode 100644 index 72441d4dee15a..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLCore.h +++ /dev/null @@ -1,492 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_CORE -#define SKSL_DSL_CORE - -#include "include/private/SkSLDefines.h" -#include "include/private/SkSLProgramKind.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLCase.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/DSLVar.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Compiler; -class ErrorReporter; -struct Program; -struct ProgramSettings; - -namespace dsl { - -class DSLField; -class DSLModifiers; - -// When users import the DSL namespace via `using namespace SkSL::dsl`, we want the SwizzleComponent -// Type enum to come into scope as well, so `Swizzle(var, X, Y, ONE)` can work as expected. -// `namespace SkSL::SwizzleComponent` contains only an `enum Type`; this `using namespace` directive -// shouldn't pollute the SkSL::dsl namespace with anything else. -using namespace SkSL::SwizzleComponent; - -/** - * Starts DSL output on the current thread using the specified compiler. This must be called - * prior to any other DSL functions. - */ -void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind = SkSL::ProgramKind::kFragment); - -void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind, const SkSL::ProgramSettings& settings); - -/** - * Signals the end of DSL output. This must be called sometime between a call to Start() and the - * termination of the thread. - */ -void End(); - -/** - * Returns all global elements (functions and global variables) as a self-contained Program. The - * optional source string is retained as the program's source. DSL programs do not normally have - * sources, but when a DSL program is produced from parsed program text (as in Parser), it may be - * important to retain it so that any std::string_views derived from it remain valid. - */ -std::unique_ptr ReleaseProgram(std::unique_ptr source = nullptr); - -/** - * Returns the ErrorReporter which will be notified of any errors that occur during DSL calls. The - * default error reporter aborts on any error. - */ -ErrorReporter& GetErrorReporter(); - -/** - * Installs an ErrorReporter which will be notified of any errors that occur during DSL calls. - */ -void SetErrorReporter(ErrorReporter* errorReporter); - -DSLGlobalVar sk_FragColor(); - -DSLGlobalVar sk_FragCoord(); - -DSLExpression sk_Position(); - -/** - * #extension : enable - */ -void AddExtension(std::string_view name, Position pos = {}); - -/** - * break; - */ -DSLStatement Break(Position pos = {}); - -/** - * continue; - */ -DSLStatement Continue(Position pos = {}); - -/** - * Adds a modifiers declaration to the current program. - */ -void Declare(const DSLModifiers& modifiers, Position pos = {}); - -/** - * Creates a local variable declaration statement. - */ -DSLStatement Declare(DSLVar& var, Position pos = {}); - -/** - * Creates a local variable declaration statement containing multiple variables. - */ -DSLStatement Declare(SkTArray& vars, Position pos = {}); - -/** - * Declares a global variable. - */ -void Declare(DSLGlobalVar& var, Position pos = {}); - -/** - * Declares a set of global variables. - */ -void Declare(SkTArray& vars, Position pos = {}); - -/** - * default: statements - */ -template -DSLCase Default(Statements... statements) { - return DSLCase(DSLExpression(), std::move(statements)...); -} - -/** - * discard; - */ -DSLStatement Discard(Position pos = {}); - -/** - * do stmt; while (test); - */ -DSLStatement Do(DSLStatement stmt, DSLExpression test, Position pos = {}); - -/** - * for (initializer; test; next) stmt; - */ -DSLStatement For(DSLStatement initializer, DSLExpression test, DSLExpression next, - DSLStatement stmt, Position pos = {}, ForLoopPositions positions = {}); - -/** - * if (test) ifTrue; [else ifFalse;] - */ -DSLStatement If(DSLExpression test, DSLStatement ifTrue, DSLStatement ifFalse = DSLStatement(), - Position pos = {}); - -DSLGlobalVar InterfaceBlock(const DSLModifiers& modifiers, std::string_view typeName, - SkTArray fields, std::string_view varName = "", - int arraySize = 0, Position pos = {}); - -/** - * return [value]; - */ -DSLStatement Return(DSLExpression value = DSLExpression(), - Position pos = {}); - -/** - * test ? ifTrue : ifFalse - */ -DSLExpression Select(DSLExpression test, DSLExpression ifTrue, DSLExpression ifFalse, - Position = {}); - -DSLStatement StaticIf(DSLExpression test, DSLStatement ifTrue, - DSLStatement ifFalse = DSLStatement(), - Position pos = {}); - -// Internal use only -DSLStatement StaticSwitch(DSLExpression value, SkTArray cases, Position pos = {}); - -/** - * @switch (value) { cases } - */ -template -DSLStatement StaticSwitch(DSLExpression value, Cases... cases) { - SkTArray caseArray; - caseArray.reserve_back(sizeof...(cases)); - (caseArray.push_back(std::move(cases)), ...); - return StaticSwitch(std::move(value), std::move(caseArray), Position{}); -} - -// Internal use only -DSLStatement Switch(DSLExpression value, SkTArray cases, Position pos = {}); - -/** - * switch (value) { cases } - */ -template -DSLStatement Switch(DSLExpression value, Cases... cases) { - SkTArray caseArray; - caseArray.reserve_back(sizeof...(cases)); - (caseArray.push_back(std::move(cases)), ...); - return Switch(std::move(value), std::move(caseArray), Position{}); -} - -/** - * while (test) stmt; - */ -DSLStatement While(DSLExpression test, DSLStatement stmt, - Position pos = {}); - -/** - * expression.xyz1 - */ -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - SkSL::SwizzleComponent::Type c, - Position pos = {}, - Position maskPos = {}); - -DSLExpression Swizzle(DSLExpression base, - SkSL::SwizzleComponent::Type a, - SkSL::SwizzleComponent::Type b, - SkSL::SwizzleComponent::Type c, - SkSL::SwizzleComponent::Type d, - Position pos = {}, - Position maskPos = {}); - -/** - * Returns the absolute value of x. If x is a vector, operates componentwise. - */ -DSLExpression Abs(DSLExpression x, Position pos = {}); - -/** - * Returns true if all of the components of boolean vector x are true. - */ -DSLExpression All(DSLExpression x, Position pos = {}); - -/** - * Returns true if any of the components of boolean vector x are true. - */ -DSLExpression Any(DSLExpression x, Position pos = {}); - -/** - * Returns the arctangent of y over x. Operates componentwise on vectors. - */ -DSLExpression Atan(DSLExpression y_over_x, Position pos = {}); -DSLExpression Atan(DSLExpression y, DSLExpression x, Position pos = {}); - -/** - * Returns x rounded towards positive infinity. If x is a vector, operates componentwise. - */ -DSLExpression Ceil(DSLExpression x, Position pos = {}); - -/** - * Returns x clamped to between min and max. If x is a vector, operates componentwise. - */ -DSLExpression Clamp(DSLExpression x, DSLExpression min, DSLExpression max, - Position pos = {}); - -/** - * Returns the cosine of x. If x is a vector, operates componentwise. - */ -DSLExpression Cos(DSLExpression x, Position pos = {}); - -/** - * Returns the cross product of x and y. - */ -DSLExpression Cross(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns x converted from radians to degrees. If x is a vector, operates componentwise. - */ -DSLExpression Degrees(DSLExpression x, Position pos = {}); - -/** - * Returns the distance between x and y. - */ -DSLExpression Distance(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the dot product of x and y. - */ -DSLExpression Dot(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are equal to the corresponding - * components of y. - */ -DSLExpression Equal(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns e^x. If x is a vector, operates componentwise. - */ -DSLExpression Exp(DSLExpression x, Position pos = {}); - -/** - * Returns 2^x. If x is a vector, operates componentwise. - */ -DSLExpression Exp2(DSLExpression x, Position pos = {}); - -/** - * If dot(i, nref) >= 0, returns n, otherwise returns -n. - */ -DSLExpression Faceforward(DSLExpression n, DSLExpression i, DSLExpression nref, - Position pos = {}); - -/** - * Returns x rounded towards negative infinity. If x is a vector, operates componentwise. - */ -DSLExpression Floor(DSLExpression x, Position pos = {}); - -/** - * Returns the fractional part of x. If x is a vector, operates componentwise. - */ -DSLExpression Fract(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are greater than the corresponding - * components of y. - */ -DSLExpression GreaterThan(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are greater than or equal to the - * corresponding components of y. - */ -DSLExpression GreaterThanEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the 1/sqrt(x). If x is a vector, operates componentwise. - */ -DSLExpression Inversesqrt(DSLExpression x, Position pos = {}); - -/** - * Returns the inverse of the matrix x. - */ -DSLExpression Inverse(DSLExpression x, Position pos = {}); - -/** - * Returns the length of the vector x. - */ -DSLExpression Length(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are less than the corresponding - * components of y. - */ -DSLExpression LessThan(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are less than or equal to the - * corresponding components of y. - */ -DSLExpression LessThanEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns the log base e of x. If x is a vector, operates componentwise. - */ -DSLExpression Log(DSLExpression x, Position pos = {}); - -/** - * Returns the log base 2 of x. If x is a vector, operates componentwise. - */ -DSLExpression Log2(DSLExpression x, Position pos = {}); - -/** - * Returns the larger (closer to positive infinity) of x and y. If x is a vector, operates - * componentwise. y may be either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Max(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns the smaller (closer to negative infinity) of x and y. If x is a vector, operates - * componentwise. y may be either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Min(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns a linear intepolation between x and y at position a, where a=0 results in x and a=1 - * results in y. If x and y are vectors, operates componentwise. a may be either a vector of the - * same dimensions as x and y, or a scalar. - */ -DSLExpression Mix(DSLExpression x, DSLExpression y, DSLExpression a, - Position pos = {}); - -/** - * Returns x modulo y. If x is a vector, operates componentwise. y may be either a vector of the - * same dimensions as x, or a scalar. - */ -DSLExpression Mod(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns the vector x normalized to a length of 1. - */ -DSLExpression Normalize(DSLExpression x, Position pos = {}); - -/** - * Returns a boolean vector indicating whether components of x are not equal to the corresponding - * components of y. - */ -DSLExpression NotEqual(DSLExpression x, DSLExpression y, - Position pos = {}); - -/** - * Returns x raised to the power y. If x is a vector, operates componentwise. y may be either a - * vector of the same dimensions as x, or a scalar. - */ -DSLExpression Pow(DSLExpression x, DSLExpression y, Position pos = {}); - -/** - * Returns x converted from degrees to radians. If x is a vector, operates componentwise. - */ -DSLExpression Radians(DSLExpression x, Position pos = {}); - -/** - * Returns i reflected from a surface with normal n. - */ -DSLExpression Reflect(DSLExpression i, DSLExpression n, Position pos = {}); - -/** - * Returns i refracted across a surface with normal n and ratio of indices of refraction eta. - */ -DSLExpression Refract(DSLExpression i, DSLExpression n, DSLExpression eta, - Position pos = {}); - -/** - * Returns x, rounded to the nearest integer. If x is a vector, operates componentwise. - */ -DSLExpression Round(DSLExpression x, Position pos = {}); - -/** - * Returns x clamped to the range [0, 1]. If x is a vector, operates componentwise. - */ -DSLExpression Saturate(DSLExpression x, Position pos = {}); - -/** - * Returns -1, 0, or 1 depending on whether x is negative, zero, or positive, respectively. If x is - * a vector, operates componentwise. - */ -DSLExpression Sign(DSLExpression x, Position pos = {}); - -/** - * Returns the sine of x. If x is a vector, operates componentwise. - */ -DSLExpression Sin(DSLExpression x, Position pos = {}); - -/** - * Returns a smooth interpolation between 0 (at x=edge1) and 1 (at x=edge2). If x is a vector, - * operates componentwise. edge1 and edge2 may either be both vectors of the same dimensions as x or - * scalars. - */ -DSLExpression Smoothstep(DSLExpression edge1, DSLExpression edge2, DSLExpression x, - Position pos = {}); - -/** - * Returns the square root of x. If x is a vector, operates componentwise. - */ -DSLExpression Sqrt(DSLExpression x, Position pos = {}); - -/** - * Returns 0 if x < edge or 1 if x >= edge. If x is a vector, operates componentwise. edge may be - * either a vector of the same dimensions as x, or a scalar. - */ -DSLExpression Step(DSLExpression edge, DSLExpression x, Position pos = {}); - -/** - * Returns the tangent of x. If x is a vector, operates componentwise. - */ -DSLExpression Tan(DSLExpression x, Position pos = {}); - -/** - * Returns x converted from premultipled to unpremultiplied alpha. - */ -DSLExpression Unpremul(DSLExpression x, Position pos = {}); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h deleted file mode 100644 index bdb5f2fe24691..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLExpression.h +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_EXPRESSION -#define SKSL_DSL_EXPRESSION - -#include "include/private/SkTArray.h" -#include "include/sksl/SkSLOperator.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include -#include - -#if defined(__has_cpp_attribute) && __has_cpp_attribute(clang::reinitializes) -#define SK_CLANG_REINITIALIZES [[clang::reinitializes]] -#else -#define SK_CLANG_REINITIALIZES -#endif - -namespace SkSL { - -class Expression; -class ExpressionArray; - -namespace dsl { - -class DSLType; -class DSLVarBase; - -/** - * Represents an expression such as 'cos(x)' or 'a + b'. - */ -class DSLExpression { -public: - DSLExpression(const DSLExpression&) = delete; - - DSLExpression(DSLExpression&&); - - DSLExpression(); - - /** - * Creates an expression representing a literal float. - */ - DSLExpression(float value, Position pos = {}); - - /** - * Creates an expression representing a literal float. - */ - DSLExpression(double value, Position pos = {}) - : DSLExpression((float) value) {} - - /** - * Creates an expression representing a literal int. - */ - DSLExpression(int value, Position pos = {}); - - /** - * Creates an expression representing a literal int. - */ - DSLExpression(int64_t value, Position pos = {}); - - /** - * Creates an expression representing a literal uint. - */ - DSLExpression(unsigned int value, Position pos = {}); - - /** - * Creates an expression representing a literal bool. - */ - DSLExpression(bool value, Position pos = {}); - - /** - * Creates an expression representing a variable reference. - */ - DSLExpression(DSLVarBase& var, Position pos = {}); - - DSLExpression(DSLVarBase&& var, Position pos = {}); - - // If expression is null, returns Poison - explicit DSLExpression(std::unique_ptr expression, Position pos = {}); - - static DSLExpression Poison(Position pos = {}); - - ~DSLExpression(); - - DSLType type() const; - - std::string description() const; - - Position position() const; - - void setPosition(Position pos); - - /** - * Performs assignment, like the '=' operator. - */ - DSLExpression assign(DSLExpression other); - - DSLExpression x(Position pos = {}); - - DSLExpression y(Position pos = {}); - - DSLExpression z(Position pos = {}); - - DSLExpression w(Position pos = {}); - - DSLExpression r(Position pos = {}); - - DSLExpression g(Position pos = {}); - - DSLExpression b(Position pos = {}); - - DSLExpression a(Position pos = {}); - - /** - * Creates an SkSL struct field access expression. - */ - DSLExpression field(std::string_view name, Position pos = {}); - - /** - * Creates an SkSL array index expression. - */ - DSLExpression operator[](DSLExpression index); - - DSLExpression operator()(SkTArray args, Position pos = {}); - - DSLExpression operator()(ExpressionArray args, Position pos = {}); - - /** - * Invokes a prefix operator. - */ - DSLExpression prefix(Operator::Kind op, Position pos); - - /** - * Invokes a postfix operator. - */ - DSLExpression postfix(Operator::Kind op, Position pos); - - /** - * Invokes a binary operator. - */ - DSLExpression binary(Operator::Kind op, DSLExpression right, Position pos); - - /** - * Equivalent to operator[]. - */ - DSLExpression index(DSLExpression index, Position pos); - - /** - * Returns true if this object contains an expression. DSLExpressions which were created with - * the empty constructor or which have already been release()ed do not have a value. - * DSLExpressions created with errors are still considered to have a value (but contain poison). - */ - bool hasValue() const { - return fExpression != nullptr; - } - - /** - * Returns true if this object contains an expression which is not poison. - */ - bool isValid() const; - - SK_CLANG_REINITIALIZES void swap(DSLExpression& other); - - /** - * Invalidates this object and returns the SkSL expression it represents. It is an error to call - * this on an invalid DSLExpression. - */ - std::unique_ptr release(); - -private: - /** - * Calls release if this expression has a value, otherwise returns null. - */ - std::unique_ptr releaseIfPossible(); - - std::unique_ptr fExpression; - - friend DSLExpression SampleChild(int index, DSLExpression coords); - - friend class DSLCore; - friend class DSLVarBase; - friend class DSLWriter; -}; - -DSLExpression operator+(DSLExpression left, DSLExpression right); -DSLExpression operator+(DSLExpression expr); -DSLExpression operator+=(DSLExpression left, DSLExpression right); -DSLExpression operator-(DSLExpression left, DSLExpression right); -DSLExpression operator-(DSLExpression expr); -DSLExpression operator-=(DSLExpression left, DSLExpression right); -DSLExpression operator*(DSLExpression left, DSLExpression right); -DSLExpression operator*=(DSLExpression left, DSLExpression right); -DSLExpression operator/(DSLExpression left, DSLExpression right); -DSLExpression operator/=(DSLExpression left, DSLExpression right); -DSLExpression operator%(DSLExpression left, DSLExpression right); -DSLExpression operator%=(DSLExpression left, DSLExpression right); -DSLExpression operator<<(DSLExpression left, DSLExpression right); -DSLExpression operator<<=(DSLExpression left, DSLExpression right); -DSLExpression operator>>(DSLExpression left, DSLExpression right); -DSLExpression operator>>=(DSLExpression left, DSLExpression right); -DSLExpression operator&&(DSLExpression left, DSLExpression right); -DSLExpression operator||(DSLExpression left, DSLExpression right); -DSLExpression operator&(DSLExpression left, DSLExpression right); -DSLExpression operator&=(DSLExpression left, DSLExpression right); -DSLExpression operator|(DSLExpression left, DSLExpression right); -DSLExpression operator|=(DSLExpression left, DSLExpression right); -DSLExpression operator^(DSLExpression left, DSLExpression right); -DSLExpression operator^=(DSLExpression left, DSLExpression right); -DSLExpression LogicalXor(DSLExpression left, DSLExpression right); -DSLExpression operator,(DSLExpression left, DSLExpression right); -DSLExpression operator==(DSLExpression left, DSLExpression right); -DSLExpression operator!=(DSLExpression left, DSLExpression right); -DSLExpression operator>(DSLExpression left, DSLExpression right); -DSLExpression operator<(DSLExpression left, DSLExpression right); -DSLExpression operator>=(DSLExpression left, DSLExpression right); -DSLExpression operator<=(DSLExpression left, DSLExpression right); -DSLExpression operator!(DSLExpression expr); -DSLExpression operator~(DSLExpression expr); -DSLExpression operator++(DSLExpression expr); -DSLExpression operator++(DSLExpression expr, int); -DSLExpression operator--(DSLExpression expr); -DSLExpression operator--(DSLExpression expr, int); - -} // namespace dsl - -} // namespace SkSL - -template struct sk_is_trivially_relocatable; - -template <> -struct sk_is_trivially_relocatable : std::true_type {}; - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h deleted file mode 100644 index de7b8f1fbcb6d..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLFunction.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_FUNCTION -#define SKSL_DSL_FUNCTION - -#include "include/private/SkSLDefines.h" -#include "include/private/SkTArray.h" -#include "include/sksl/DSLBlock.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/DSLStatement.h" -#include "include/sksl/DSLVar.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include - -namespace SkSL { - -class FunctionDeclaration; - -namespace dsl { - -class DSLType; - -class DSLFunction { -public: - template - DSLFunction(const DSLType& returnType, std::string_view name, Parameters&... parameters) - : DSLFunction(DSLModifiers(), returnType, name, parameters...) {} - - template - DSLFunction(const DSLModifiers& modifiers, const DSLType& returnType, std::string_view name, - Parameters&... parameters) { - SkTArray parameterArray; - parameterArray.reserve_back(sizeof...(parameters)); - (parameterArray.push_back(¶meters), ...); - - // We can't have a default parameter and a template parameter pack at the same time, so - // unfortunately we can't capture position from this overload. - this->init(modifiers, returnType, name, std::move(parameterArray), Position()); - } - - DSLFunction(std::string_view name, const DSLModifiers& modifiers, const DSLType& returnType, - SkTArray parameters, Position pos = {}) { - this->init(modifiers, returnType, name, std::move(parameters), pos); - } - - DSLFunction(SkSL::FunctionDeclaration* decl) - : fDecl(decl) {} - - virtual ~DSLFunction() = default; - - template - void define(Stmt... stmts) { - DSLBlock block = DSLBlock(DSLStatement(std::move(stmts))...); - this->define(std::move(block)); - } - - void define(DSLBlock block, Position pos = {}); - - void prototype(); - - /** - * Invokes the function with the given arguments. - */ - template - DSLExpression operator()(Args&&... args) { - ExpressionArray argArray; - argArray.reserve_back(sizeof...(args)); - this->collectArgs(argArray, std::forward(args)...); - return this->call(std::move(argArray)); - } - - /** - * Invokes the function with the given arguments. - */ - DSLExpression call(SkTArray args, Position pos = {}); - - DSLExpression call(ExpressionArray args, Position pos = {}); - -private: - void collectArgs(ExpressionArray& args) {} - - template - void collectArgs(ExpressionArray& args, DSLVar& var, RemainingArgs&&... remaining) { - args.push_back(DSLExpression(var).release()); - collectArgs(args, std::forward(remaining)...); - } - - template - void collectArgs(ExpressionArray& args, DSLExpression expr, RemainingArgs&&... remaining) { - args.push_back(expr.release()); - collectArgs(args, std::forward(remaining)...); - } - - void init(DSLModifiers modifiers, const DSLType& returnType, std::string_view name, - SkTArray params, Position pos); - - SkSL::FunctionDeclaration* fDecl = nullptr; - SkSL::Position fPosition; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h deleted file mode 100644 index a1c963a74eacd..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLLayout.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_LAYOUT -#define SKSL_DSL_LAYOUT - -#include "include/private/SkSLLayout.h" -#include "include/sksl/SkSLPosition.h" - -namespace SkSL { - -namespace dsl { - -class DSLLayout { -public: - DSLLayout() {} - - DSLLayout& originUpperLeft(Position pos = {}) { - return this->flag(SkSL::Layout::kOriginUpperLeft_Flag, "origin_upper_left", pos); - } - - DSLLayout& pushConstant(Position pos = {}) { - return this->flag(SkSL::Layout::kPushConstant_Flag, "push_constant", pos); - } - - DSLLayout& blendSupportAllEquations(Position pos = {}) { - return this->flag(SkSL::Layout::kBlendSupportAllEquations_Flag, - "blend_support_all_equations", pos); - } - - DSLLayout& color(Position pos = {}) { - return this->flag(SkSL::Layout::kColor_Flag, "color", pos); - } - - DSLLayout& location(int location, Position pos = {}) { - return this->intValue(&fSkSLLayout.fLocation, location, SkSL::Layout::kLocation_Flag, - "location", pos); - } - - DSLLayout& offset(int offset, Position pos = {}) { - return this->intValue(&fSkSLLayout.fOffset, offset, SkSL::Layout::kOffset_Flag, "offset", - pos); - } - - DSLLayout& binding(int binding, Position pos = {}) { - return this->intValue(&fSkSLLayout.fBinding, binding, SkSL::Layout::kBinding_Flag, - "binding", pos); - } - - DSLLayout& index(int index, Position pos = {}) { - return this->intValue(&fSkSLLayout.fIndex, index, SkSL::Layout::kIndex_Flag, "index", pos); - } - - DSLLayout& set(int set, Position pos = {}) { - return this->intValue(&fSkSLLayout.fSet, set, SkSL::Layout::kSet_Flag, "set", pos); - } - - DSLLayout& builtin(int builtin, Position pos = {}) { - return this->intValue(&fSkSLLayout.fBuiltin, builtin, SkSL::Layout::kBuiltin_Flag, - "builtin", pos); - } - - DSLLayout& inputAttachmentIndex(int inputAttachmentIndex, - Position pos = {}) { - return this->intValue(&fSkSLLayout.fInputAttachmentIndex, inputAttachmentIndex, - SkSL::Layout::kInputAttachmentIndex_Flag, "input_attachment_index", - pos); - } - -private: - explicit DSLLayout(SkSL::Layout skslLayout) - : fSkSLLayout(skslLayout) {} - - DSLLayout& flag(SkSL::Layout::Flag mask, const char* name, Position pos); - - DSLLayout& intValue(int* target, int value, SkSL::Layout::Flag flag, const char* name, - Position pos); - - SkSL::Layout fSkSLLayout; - - friend class DSLModifiers; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h deleted file mode 100644 index 01fb0623376d8..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLModifiers.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_MODIFIERS -#define SKSL_DSL_MODIFIERS - -#include "include/core/SkSpan.h" -#include "include/private/SkSLModifiers.h" -#include "include/sksl/DSLLayout.h" - -namespace SkSL { - -namespace dsl { - -class DSLField; -class DSLType; - -enum Modifier { - kNo_Modifier = SkSL::Modifiers::kNo_Flag, - kConst_Modifier = SkSL::Modifiers::kConst_Flag, - kIn_Modifier = SkSL::Modifiers::kIn_Flag, - kOut_Modifier = SkSL::Modifiers::kOut_Flag, - kInOut_Modifier = SkSL::Modifiers::kIn_Flag | SkSL::Modifiers::kOut_Flag, - kUniform_Modifier = SkSL::Modifiers::kUniform_Flag, - kFlat_Modifier = SkSL::Modifiers::kFlat_Flag, - kNoPerspective_Modifier = SkSL::Modifiers::kNoPerspective_Flag, -}; - -class DSLModifiers { -public: - DSLModifiers(int flags = 0, Position pos = {}) - : DSLModifiers(DSLLayout(), flags, pos) {} - - DSLModifiers(DSLLayout layout, int flags = 0, Position pos = {}) - : fModifiers(layout.fSkSLLayout, flags) - , fPosition(pos) {} - - int& flags() { - return fModifiers.fFlags; - } - - const int& flags() const { - return fModifiers.fFlags; - } - - DSLLayout layout() const { - return DSLLayout(fModifiers.fLayout); - } - -private: - SkSL::Modifiers fModifiers; - Position fPosition; - - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); - friend class DSLCore; - friend class DSLFunction; - friend class DSLType; - friend class DSLWriter; -}; - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h deleted file mode 100644 index 391e911d3aac9..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLStatement.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_STATEMENT -#define SKSL_DSL_STATEMENT - -#include "include/core/SkTypes.h" -#include "include/private/SkSLStatement.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include - -namespace SkSL { - -class Expression; - -namespace dsl { - -class DSLBlock; -class DSLExpression; - -class DSLStatement { -public: - DSLStatement(); - - DSLStatement(DSLExpression expr); - - DSLStatement(DSLBlock block); - - DSLStatement(DSLStatement&&) = default; - - DSLStatement(std::unique_ptr expr); - - DSLStatement(std::unique_ptr stmt, Position pos); - - DSLStatement(std::unique_ptr stmt); - - ~DSLStatement(); - - DSLStatement& operator=(DSLStatement&& other) = default; - - Position position() { - SkASSERT(this->hasValue()); - return fStatement->fPosition; - } - - void setPosition(Position pos) { - SkASSERT(this->hasValue()); - fStatement->fPosition = pos; - } - - bool hasValue() { return fStatement != nullptr; } - - std::unique_ptr release() { - SkASSERT(this->hasValue()); - return std::move(fStatement); - } - -private: - std::unique_ptr releaseIfPossible() { - return std::move(fStatement); - } - - std::unique_ptr fStatement; - - friend class DSLCore; - friend class DSLWriter; - friend DSLStatement operator,(DSLStatement left, DSLStatement right); -}; - -DSLStatement operator,(DSLStatement left, DSLStatement right); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h deleted file mode 100644 index dfd45d1b34280..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLSymbols.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_SYMBOLS -#define SKSL_DSL_SYMBOLS - -#include "include/sksl/DSLExpression.h" - -#include -#include - -namespace SkSL { - -class Position; -class SymbolTable; - -namespace dsl { - -class DSLVarBase; - -// This header provides methods for manually managing symbol tables in DSL code. They should not be -// used by normal hand-written DSL code, where we rely on C++ to manage symbols, but are instead -// needed when DSL objects are being constructed programmatically (as in Parser). - -/** - * Pushes a new symbol table onto the symbol table stack. - */ -void PushSymbolTable(); - -/** - * Pops the top symbol table from the stack. As symbol tables are shared pointers, this will only - * destroy the symbol table if it was never attached to anything (e.g. passed into a Block - * constructor). - */ -void PopSymbolTable(); - -/** - * Returns the current symbol table. Outside of SkSL itself, this is an opaque pointer, used only - * for passing it to DSL methods that require it. - */ -std::shared_ptr CurrentSymbolTable(); - -/** - * Returns an expression referring to the named symbol. - */ -DSLExpression Symbol(std::string_view name, Position pos = {}); - -/** - * Adds a variable to the current symbol table. - */ -void AddToSymbolTable(DSLVarBase& var, Position pos = {}); - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h deleted file mode 100644 index d15e01b3a3eac..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLType.h +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_TYPE -#define SKSL_DSL_TYPE - -#include "include/core/SkSpan.h" -#include "include/core/SkTypes.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include - -namespace SkSL { - -class Compiler; -class Type; - -namespace dsl { - -class DSLField; -class DSLVarBase; - -enum TypeConstant : uint8_t { - kBool_Type, - kBool2_Type, - kBool3_Type, - kBool4_Type, - kHalf_Type, - kHalf2_Type, - kHalf3_Type, - kHalf4_Type, - kHalf2x2_Type, - kHalf3x2_Type, - kHalf4x2_Type, - kHalf2x3_Type, - kHalf3x3_Type, - kHalf4x3_Type, - kHalf2x4_Type, - kHalf3x4_Type, - kHalf4x4_Type, - kFloat_Type, - kFloat2_Type, - kFloat3_Type, - kFloat4_Type, - kFragmentProcessor_Type, - kFloat2x2_Type, - kFloat3x2_Type, - kFloat4x2_Type, - kFloat2x3_Type, - kFloat3x3_Type, - kFloat4x3_Type, - kFloat2x4_Type, - kFloat3x4_Type, - kFloat4x4_Type, - kInt_Type, - kInt2_Type, - kInt3_Type, - kInt4_Type, - kShader_Type, - kShort_Type, - kShort2_Type, - kShort3_Type, - kShort4_Type, - kUInt_Type, - kUInt2_Type, - kUInt3_Type, - kUInt4_Type, - kUShort_Type, - kUShort2_Type, - kUShort3_Type, - kUShort4_Type, - kVoid_Type, - kPoison_Type, -}; - -class DSLType { -public: - DSLType(TypeConstant tc, Position pos = {}); - - DSLType(const SkSL::Type* type, Position pos = {}); - - DSLType(std::string_view name, Position pos = {}); - - DSLType(std::string_view name, - DSLModifiers* modifiers, - Position pos = {}); - - /** - * Returns true if the SkSL type is non-null. - */ - bool hasValue() const { return fSkSLType != nullptr; } - - /** - * Returns true if this type is a bool. - */ - bool isBoolean() const; - - /** - * Returns true if this is a numeric scalar type. - */ - bool isNumber() const; - - /** - * Returns true if this is a floating-point scalar type (float or half). - */ - bool isFloat() const; - - /** - * Returns true if this is a signed scalar type (int or short). - */ - bool isSigned() const; - - /** - * Returns true if this is an unsigned scalar type (uint or ushort). - */ - bool isUnsigned() const; - - /** - * Returns true if this is a signed or unsigned integer. - */ - bool isInteger() const; - - /** - * Returns true if this is a scalar type. - */ - bool isScalar() const; - - /** - * Returns true if this is a vector type. - */ - bool isVector() const; - - /** - * Returns true if this is a matrix type. - */ - bool isMatrix() const; - - /** - * Returns true if this is a array type. - */ - bool isArray() const; - - /** - * Returns true if this is a struct type. - */ - bool isStruct() const; - - /** - * Returns true if this is a Skia object type (shader, colorFilter, blender). - */ - bool isEffectChild() const; - - template - static DSLExpression Construct(DSLType type, DSLVarBase& var, Args&&... args) { - DSLExpression argArray[] = {var, args...}; - return Construct(type, SkSpan(argArray)); - } - - template - static DSLExpression Construct(DSLType type, DSLExpression expr, Args&&... args) { - DSLExpression argArray[] = {std::move(expr), std::move(args)...}; - return Construct(type, SkSpan(argArray)); - } - - static DSLExpression Construct(DSLType type, SkSpan argArray); - -private: - const SkSL::Type& skslType() const { - SkASSERT(fSkSLType); - return *fSkSLType; - } - - const SkSL::Type* fSkSLType = nullptr; - - friend DSLType Array(const DSLType& base, int count, Position pos); - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); - friend DSLType UnsizedArray(const DSLType& base, Position pos); - friend class DSLCore; - friend class DSLFunction; - friend class DSLVarBase; - friend class DSLWriter; - friend class SkSL::Compiler; -}; - -#define TYPE(T) \ - template \ - DSLExpression T(Args&&... args) { \ - return DSLType::Construct(k ## T ## _Type, std::forward(args)...); \ - } - -#define VECTOR_TYPE(T) \ - TYPE(T) \ - TYPE(T ## 2) \ - TYPE(T ## 3) \ - TYPE(T ## 4) - -#define MATRIX_TYPE(T) \ - TYPE(T ## 2x2) \ - TYPE(T ## 3x2) \ - TYPE(T ## 4x2) \ - TYPE(T ## 2x3) \ - TYPE(T ## 3x3) \ - TYPE(T ## 4x3) \ - TYPE(T ## 2x4) \ - TYPE(T ## 3x4) \ - TYPE(T ## 4x4) - -VECTOR_TYPE(Bool) -VECTOR_TYPE(Float) -VECTOR_TYPE(Half) -VECTOR_TYPE(Int) -VECTOR_TYPE(UInt) -VECTOR_TYPE(Short) -VECTOR_TYPE(UShort) - -MATRIX_TYPE(Float) -MATRIX_TYPE(Half) - -#undef TYPE -#undef VECTOR_TYPE -#undef MATRIX_TYPE - -DSLType Array(const DSLType& base, int count, Position pos = {}); - -DSLType UnsizedArray(const DSLType& base, Position pos = {}); - -class DSLField { -public: - DSLField(const DSLType type, std::string_view name, - Position pos = {}) - : DSLField(DSLModifiers(), type, name, pos) {} - - DSLField(const DSLModifiers& modifiers, const DSLType type, std::string_view name, - Position pos = {}) - : fModifiers(modifiers) - , fType(type) - , fName(name) - , fPosition(pos) {} - -private: - DSLModifiers fModifiers; - const DSLType fType; - std::string_view fName; - Position fPosition; - - friend class DSLCore; - friend DSLType Struct(std::string_view name, SkSpan fields, Position pos); -}; - -DSLType Struct(std::string_view name, SkSpan fields, - Position pos = {}); - -template -DSLType Struct(std::string_view name, Field... fields) { - DSLField fieldTypes[] = {std::move(fields)...}; - return Struct(name, SkSpan(fieldTypes), Position()); -} - -} // namespace dsl - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h deleted file mode 100644 index f052a525e355d..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/DSLVar.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_DSL_VAR -#define SKSL_DSL_VAR - -#include "include/private/SkSLStatement.h" -#include "include/sksl/DSLExpression.h" -#include "include/sksl/DSLModifiers.h" -#include "include/sksl/DSLType.h" -#include "include/sksl/SkSLPosition.h" - -#include -#include -#include -#include - -namespace SkSL { - -class Expression; -class ExpressionArray; -class Variable; -enum class VariableStorage : int8_t; - -namespace dsl { - -class DSLVarBase { -public: - /** - * Constructs a new variable with the specified type and name. - */ - DSLVarBase(VariableStorage storage, DSLType type, std::string_view name, - DSLExpression initialValue, Position pos, Position namePos); - - DSLVarBase(VariableStorage storage, const DSLModifiers& modifiers, DSLType type, - std::string_view name, DSLExpression initialValue, Position pos, Position namePos); - - DSLVarBase(DSLVarBase&&) = default; - - std::string_view name() const { - return fName; - } - - const DSLModifiers& modifiers() const { - return fModifiers; - } - - VariableStorage storage() const { - return fStorage; - } - - DSLExpression x() { - return DSLExpression(*this).x(); - } - - DSLExpression y() { - return DSLExpression(*this).y(); - } - - DSLExpression z() { - return DSLExpression(*this).z(); - } - - DSLExpression w() { - return DSLExpression(*this).w(); - } - - DSLExpression r() { - return DSLExpression(*this).r(); - } - - DSLExpression g() { - return DSLExpression(*this).g(); - } - - DSLExpression b() { - return DSLExpression(*this).b(); - } - - DSLExpression a() { - return DSLExpression(*this).a(); - } - - DSLExpression field(std::string_view name) { - return DSLExpression(*this).field(name); - } - - DSLExpression operator[](DSLExpression&& index); - - DSLExpression operator++() { - return ++DSLExpression(*this); - } - - DSLExpression operator++(int) { - return DSLExpression(*this)++; - } - - DSLExpression operator--() { - return --DSLExpression(*this); - } - - DSLExpression operator--(int) { - return DSLExpression(*this)--; - } - - template DSLExpression assign(T&& param) { - return this->assignExpression(DSLExpression(std::forward(param))); - } - -protected: - /** - * Creates an empty, unpopulated var. Can be replaced with a real var later via `swap`. - */ - DSLVarBase(VariableStorage storage) : fType(kVoid_Type), fStorage(storage) {} - - DSLExpression assignExpression(DSLExpression other); - - void swap(DSLVarBase& other); - - DSLModifiers fModifiers; - // We only need to keep track of the type here so that we can create the SkSL::Variable. For - // predefined variables this field is unnecessary, so we don't bother tracking it and just set - // it to kVoid; in other words, you shouldn't generally be relying on this field to be correct. - // If you need to determine the variable's type, look at DSLWriter::Var(...)->type() instead. - DSLType fType; - std::unique_ptr fDeclaration; - SkSL::Variable* fVar = nullptr; - Position fNamePosition; - std::string_view fName; - DSLExpression fInitialValue; - Position fPosition; - VariableStorage fStorage; - bool fInitialized = false; - - friend class DSLCore; - friend class DSLFunction; - friend class DSLWriter; -}; - -/** - * A local variable. - */ -class DSLVar : public DSLVarBase { -public: - DSLVar(); - - DSLVar(DSLType type, std::string_view name, DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLVar(const DSLModifiers& modifiers, DSLType type, std::string_view name, - DSLExpression initialValue = DSLExpression(), Position pos = {}, Position namePos = {}); - - DSLVar(DSLVar&&) = default; - - void swap(DSLVar& other); - -private: - using INHERITED = DSLVarBase; -}; - -/** - * A global variable. - */ -class DSLGlobalVar : public DSLVarBase { -public: - DSLGlobalVar(); - - DSLGlobalVar(DSLType type, std::string_view name, DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLGlobalVar(const DSLModifiers& modifiers, DSLType type, std::string_view name, - DSLExpression initialValue = DSLExpression(), - Position pos = {}, Position namePos = {}); - - DSLGlobalVar(const char* name); - - DSLGlobalVar(DSLGlobalVar&&) = default; - - void swap(DSLGlobalVar& other); - - /** - * Implements the following method calls: - * half4 shader::eval(float2 coords); - * half4 colorFilter::eval(half4 input); - */ - DSLExpression eval(DSLExpression x, Position pos = {}); - - /** - * Implements the following method call: - * half4 blender::eval(half4 src, half4 dst); - */ - DSLExpression eval(DSLExpression x, DSLExpression y, Position pos = {}); - -private: - DSLExpression eval(ExpressionArray args, Position pos); - - std::unique_ptr methodCall(std::string_view methodName, Position pos); - - using INHERITED = DSLVarBase; -}; - -/** - * A function parameter. - */ -class DSLParameter : public DSLVarBase { -public: - DSLParameter(); - - DSLParameter(DSLType type, std::string_view name, Position pos = {}, Position namePos = {}); - - DSLParameter(const DSLModifiers& modifiers, DSLType type, std::string_view name, - Position pos = {}, Position namePos = {}); - - DSLParameter(DSLParameter&&) = default; - - void swap(DSLParameter& other); - -private: - using INHERITED = DSLVarBase; -}; - -} // namespace dsl - -} // namespace SkSL - - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h deleted file mode 100644 index 4abf4631b8b17..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLErrorReporter.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_ERROR_REPORTER -#define SKSL_ERROR_REPORTER - -#include "include/core/SkTypes.h" - -#include - -namespace SkSL { - -class Position; - -/** - * Class which is notified in the event of an error. - */ -class ErrorReporter { -public: - ErrorReporter() {} - - virtual ~ErrorReporter() {} - - void error(Position position, std::string_view msg); - - std::string_view source() const { return fSource; } - - void setSource(std::string_view source) { fSource = source; } - - int errorCount() const { - return fErrorCount; - } - - void resetErrorCount() { - fErrorCount = 0; - } - -protected: - /** - * Called when an error is reported. - */ - virtual void handleError(std::string_view msg, Position position) = 0; - -private: - Position position(int offset) const; - - std::string_view fSource; - int fErrorCount = 0; -}; - -/** - * Error reporter for tests that need an SkSL context; aborts immediately if an error is reported. - */ -class TestingOnly_AbortErrorReporter : public ErrorReporter { -public: - void handleError(std::string_view msg, Position pos) override; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h deleted file mode 100644 index 1e47dce618856..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLOperator.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2021 Google LLC - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_OPERATOR -#define SKSL_OPERATOR - -#include -#include - -namespace SkSL { - -class Context; -class Type; - -enum class OperatorKind : uint8_t { - PLUS, - MINUS, - STAR, - SLASH, - PERCENT, - SHL, - SHR, - LOGICALNOT, - LOGICALAND, - LOGICALOR, - LOGICALXOR, - BITWISENOT, - BITWISEAND, - BITWISEOR, - BITWISEXOR, - EQ, - EQEQ, - NEQ, - LT, - GT, - LTEQ, - GTEQ, - PLUSEQ, - MINUSEQ, - STAREQ, - SLASHEQ, - PERCENTEQ, - SHLEQ, - SHREQ, - BITWISEANDEQ, - BITWISEOREQ, - BITWISEXOREQ, - PLUSPLUS, - MINUSMINUS, - COMMA -}; - -enum class OperatorPrecedence : uint8_t { - kParentheses = 1, - kPostfix = 2, - kPrefix = 3, - kMultiplicative = 4, - kAdditive = 5, - kShift = 6, - kRelational = 7, - kEquality = 8, - kBitwiseAnd = 9, - kBitwiseXor = 10, - kBitwiseOr = 11, - kLogicalAnd = 12, - kLogicalXor = 13, - kLogicalOr = 14, - kTernary = 15, - kAssignment = 16, - kSequence = 17, - kTopLevel = kSequence -}; - -class Operator { -public: - using Kind = OperatorKind; - - Operator(Kind op) : fKind(op) {} - - Kind kind() const { return fKind; } - - bool isEquality() const { - return fKind == Kind::EQEQ || fKind == Kind::NEQ; - } - - OperatorPrecedence getBinaryPrecedence() const; - - // Returns the operator name surrounded by the expected whitespace for a tidy binary expression. - const char* operatorName() const; - - // Returns the operator name without any surrounding whitespace. - std::string_view tightOperatorName() const; - - // Returns true if op is '=' or any compound assignment operator ('+=', '-=', etc.) - bool isAssignment() const; - - // Given a compound assignment operator, returns the non-assignment version of the operator - // (e.g. '+=' becomes '+') - Operator removeAssignment() const; - - /** - * Defines the set of relational (comparison) operators: - * < <= > >= - */ - bool isRelational() const; - - /** - * Defines the set of operators which are only valid on integral types: - * << <<= >> >>= & &= | |= ^ ^= % %= - */ - bool isOnlyValidForIntegralTypes() const; - - /** - * Defines the set of operators which perform vector/matrix math. - * + += - -= * *= / /= % %= << <<= >> >>= & &= | |= ^ ^= - */ - bool isValidForMatrixOrVector() const; - - /* - * Defines the set of operators allowed by The OpenGL ES Shading Language 1.00, Section 5.1. - * The set of illegal (reserved) operators are the ones that only make sense with integral - * types. This is not a coincidence: It's because ES2 doesn't require 'int' to be anything but - * syntactic sugar for floats with truncation after each operation. - */ - bool isAllowedInStrictES2Mode() const { - return !this->isOnlyValidForIntegralTypes(); - } - - /** - * Determines the operand and result types of a binary expression. Returns true if the - * expression is legal, false otherwise. If false, the values of the out parameters are - * undefined. - */ - bool determineBinaryType(const Context& context, - const Type& left, - const Type& right, - const Type** outLeftType, - const Type** outRightType, - const Type** outResultType) const; - -private: - bool isOperator() const; - bool isMatrixMultiply(const Type& left, const Type& right) const; - - Kind fKind; -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h deleted file mode 100644 index 5f8e80a607b8f..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/sksl/SkSLPosition.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SKSL_POSITION -#define SKSL_POSITION - -#include "include/core/SkTypes.h" - -#include -#include - -namespace SkSL { - -class Position { -public: - Position() - : fStartOffset(-1) - , fLength(0) {} - - static Position Range(int startOffset, int endOffset) { - SkASSERT(startOffset <= endOffset); - SkASSERT(startOffset <= 0xFFFFFF); - int length = endOffset - startOffset; - Position result; - result.fStartOffset = startOffset; - result.fLength = length <= 0xFF ? length : 0xFF; - return result; - } - - bool valid() const { - return fStartOffset != -1; - } - - int line(std::string_view source) const; - - int startOffset() const { - SkASSERT(this->valid()); - return fStartOffset; - } - - int endOffset() const { - SkASSERT(this->valid()); - return fStartOffset + fLength; - } - - // Returns the position from this through, and including the entirety of, end. - Position rangeThrough(Position end) const { - if (fStartOffset == -1 || end.fStartOffset == -1) { - return *this; - } - SkASSERTF(this->startOffset() <= end.startOffset() && this->endOffset() <= end.endOffset(), - "Invalid range: (%d-%d) - (%d-%d)\n", this->startOffset(), this->endOffset(), - end.startOffset(), end.endOffset()); - return Range(this->startOffset(), end.endOffset()); - } - - // Returns a position representing the character immediately after this position - Position after() const { - int endOffset = this->endOffset(); - return Range(endOffset, endOffset + 1); - } - - bool operator==(const Position& other) const { - return fStartOffset == other.fStartOffset && fLength == other.fLength; - } - - bool operator!=(const Position& other) const { - return !(*this == other); - } - - bool operator>(const Position& other) const { - return fStartOffset > other.fStartOffset; - } - - bool operator>=(const Position& other) const { - return fStartOffset >= other.fStartOffset; - } - - bool operator<(const Position& other) const { - return fStartOffset < other.fStartOffset; - } - - bool operator<=(const Position& other) const { - return fStartOffset <= other.fStartOffset; - } - -private: - int32_t fStartOffset : 24; - uint32_t fLength : 8; -}; - -struct ForLoopPositions { - Position initPosition = Position(); - Position conditionPosition = Position(); - Position nextPosition = Position(); -}; - -} // namespace SkSL - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h index d2c8b8b23b964..536691875e4f4 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCamera.h @@ -14,7 +14,7 @@ #include "include/core/SkMatrix.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" // NOTE -- This entire header / impl is deprecated, and will be removed from Skia soon. // diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h index afdf91e5ebcb8..d387fb24ca6bc 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkCustomTypeface.h @@ -14,12 +14,15 @@ #include "include/core/SkPath.h" #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" +#include #include class SkStream; -class SkTypeface; +class SkStreamAsset; +struct SkFontArguments; class SK_API SkCustomTypefaceBuilder { public: @@ -33,6 +36,9 @@ class SK_API SkCustomTypefaceBuilder { sk_sp detach(); + static constexpr SkTypeface::FactoryId FactoryId = SkSetFourByteTag('u','s','e','r'); + static sk_sp MakeFromStream(std::unique_ptr, const SkFontArguments&); + private: struct GlyphRec { // logical union diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h index 5ef7a103a98af..87c6916b39f09 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkNWayCanvas.h @@ -9,17 +9,14 @@ #ifndef SkNWayCanvas_DEFINED #define SkNWayCanvas_DEFINED -#include "include/core/SkBlendMode.h" -#include "include/core/SkCanvas.h" #include "include/core/SkCanvasVirtualEnforcer.h" -#include "include/core/SkClipOp.h" #include "include/core/SkColor.h" #include "include/core/SkM44.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSamplingOptions.h" #include "include/core/SkScalar.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" #include "include/utils/SkNoDrawCanvas.h" #include @@ -28,6 +25,7 @@ namespace sktext { class GlyphRunList; } +class SkCanvas; class SkData; class SkDrawable; class SkImage; @@ -40,12 +38,14 @@ class SkRegion; class SkShader; class SkTextBlob; class SkVertices; +enum class SkBlendMode; +enum class SkClipOp; struct SkDrawShadowRec; struct SkPoint; struct SkRSXform; struct SkRect; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) namespace sktext::gpu { class Slug; } @@ -77,7 +77,7 @@ class SK_API SkNWayCanvas : public SkCanvasVirtualEnforcer { void onDrawGlyphRunList(const sktext::GlyphRunList&, const SkPaint&) override; void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) override; -#if SK_SUPPORT_GPU +#if defined(SK_GANESH) void onDrawSlug(const sktext::gpu::Slug* slug) override; #endif void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h index a03bfdb54108a..0b686e5edc5af 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkOrderedFontMgr.h @@ -39,14 +39,15 @@ class SK_API SkOrderedFontMgr : public SkFontMgr { protected: int onCountFamilies() const override; void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onCreateStyleSet(int index)const override; + sk_sp onCreateStyleSet(int index)const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkTypeface* onMatchFamilyStyle(const char familyName[], const SkFontStyle&) const override; - SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const override; + sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle&) const override; + sk_sp onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const override; // Note: all of these always return null sk_sp onMakeFromData(sk_sp, int ttcIndex) const override; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h index 5ce3c26f1dc74..9a836bc7c2551 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkPaintFilterCanvas.h @@ -8,7 +8,6 @@ #ifndef SkPaintFilterCanvas_DEFINED #define SkPaintFilterCanvas_DEFINED -#include "include/core/SkBlendMode.h" #include "include/core/SkCanvas.h" #include "include/core/SkCanvasVirtualEnforcer.h" #include "include/core/SkColor.h" @@ -18,7 +17,7 @@ #include "include/core/SkScalar.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" +#include "include/private/base/SkTDArray.h" #include "include/utils/SkNWayCanvas.h" #include @@ -42,6 +41,7 @@ class SkSurface; class SkSurfaceProps; class SkTextBlob; class SkVertices; +enum class SkBlendMode; struct SkDrawShadowRec; struct SkPoint; struct SkRSXform; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h index f1c81b2f28d3c..acd0ef2305c03 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkParsePath.h @@ -19,7 +19,7 @@ class SK_API SkParsePath { static bool FromSVGString(const char str[], SkPath*); enum class PathEncoding { Absolute, Relative }; - static void ToSVGString(const SkPath&, SkString*, PathEncoding = PathEncoding::Absolute); + static SkString ToSVGString(const SkPath&, PathEncoding = PathEncoding::Absolute); }; #endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h deleted file mode 100644 index ba40732b9cf7a..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/utils/SkRandom.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2006 The Android Open Source Project - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkRandom_DEFINED -#define SkRandom_DEFINED - -#include "include/core/SkScalar.h" -#include "include/private/SkFixed.h" -#include "include/private/SkFloatBits.h" - -/** \class SkRandom - - Utility class that implements pseudo random 32bit numbers using Marsaglia's - multiply-with-carry "mother of all" algorithm. Unlike rand(), this class holds - its own state, so that multiple instances can be used with no side-effects. - - Has a large period and all bits are well-randomized. - */ -class SkRandom { -public: - SkRandom() { init(0); } - SkRandom(uint32_t seed) { init(seed); } - SkRandom(const SkRandom& rand) : fK(rand.fK), fJ(rand.fJ) {} - - SkRandom& operator=(const SkRandom& rand) { - fK = rand.fK; - fJ = rand.fJ; - - return *this; - } - - /** Return the next pseudo random number as an unsigned 32bit value. - */ - uint32_t nextU() { - fK = kKMul*(fK & 0xffff) + (fK >> 16); - fJ = kJMul*(fJ & 0xffff) + (fJ >> 16); - return (((fK << 16) | (fK >> 16)) + fJ); - } - - /** Return the next pseudo random number as a signed 32bit value. - */ - int32_t nextS() { return (int32_t)this->nextU(); } - - /** - * Returns value [0...1) as an IEEE float - */ - float nextF() { - int floatint = 0x3f800000 | (int)(this->nextU() >> 9); - float f = SkBits2Float(floatint) - 1.0f; - return f; - } - - /** - * Returns value [min...max) as a float - */ - float nextRangeF(float min, float max) { - return min + this->nextF() * (max - min); - } - - /** Return the next pseudo random number, as an unsigned value of - at most bitCount bits. - @param bitCount The maximum number of bits to be returned - */ - uint32_t nextBits(unsigned bitCount) { - SkASSERT(bitCount > 0 && bitCount <= 32); - return this->nextU() >> (32 - bitCount); - } - - /** Return the next pseudo random unsigned number, mapped to lie within - [min, max] inclusive. - */ - uint32_t nextRangeU(uint32_t min, uint32_t max) { - SkASSERT(min <= max); - uint32_t range = max - min + 1; - if (0 == range) { - return this->nextU(); - } else { - return min + this->nextU() % range; - } - } - - /** Return the next pseudo random unsigned number, mapped to lie within - [0, count). - */ - uint32_t nextULessThan(uint32_t count) { - SkASSERT(count > 0); - return this->nextRangeU(0, count - 1); - } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [0..SK_Scalar1). - */ - SkScalar nextUScalar1() { return SkFixedToScalar(this->nextUFixed1()); } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [min..max). - */ - SkScalar nextRangeScalar(SkScalar min, SkScalar max) { - return this->nextUScalar1() * (max - min) + min; - } - - /** Return the next pseudo random number expressed as a SkScalar - in the range [-SK_Scalar1..SK_Scalar1). - */ - SkScalar nextSScalar1() { return SkFixedToScalar(this->nextSFixed1()); } - - /** Return the next pseudo random number as a bool. - */ - bool nextBool() { return this->nextU() >= 0x80000000; } - - /** A biased version of nextBool(). - */ - bool nextBiasedBool(SkScalar fractionTrue) { - SkASSERT(fractionTrue >= 0 && fractionTrue <= SK_Scalar1); - return this->nextUScalar1() <= fractionTrue; - } - - /** Reset the random object. - */ - void setSeed(uint32_t seed) { init(seed); } - -private: - // Initialize state variables with LCG. - // We must ensure that both J and K are non-zero, otherwise the - // multiply-with-carry step will forevermore return zero. - void init(uint32_t seed) { - fK = NextLCG(seed); - if (0 == fK) { - fK = NextLCG(fK); - } - fJ = NextLCG(fK); - if (0 == fJ) { - fJ = NextLCG(fJ); - } - SkASSERT(0 != fK && 0 != fJ); - } - static uint32_t NextLCG(uint32_t seed) { return kMul*seed + kAdd; } - - /** Return the next pseudo random number expressed as an unsigned SkFixed - in the range [0..SK_Fixed1). - */ - SkFixed nextUFixed1() { return this->nextU() >> 16; } - - /** Return the next pseudo random number expressed as a signed SkFixed - in the range [-SK_Fixed1..SK_Fixed1). - */ - SkFixed nextSFixed1() { return this->nextS() >> 15; } - - // See "Numerical Recipes in C", 1992 page 284 for these constants - // For the LCG that sets the initial state from a seed - enum { - kMul = 1664525, - kAdd = 1013904223 - }; - // Constants for the multiply-with-carry steps - enum { - kKMul = 30345, - kJMul = 18000, - }; - - uint32_t fK; - uint32_t fJ; -}; - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h index 2ee56934ade6d..322549b38f7ed 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/skcms.h @@ -51,6 +51,17 @@ SKCMS_API float skcms_TransferFunction_eval (const skcms_TransferFunction*, flo SKCMS_API bool skcms_TransferFunction_invert(const skcms_TransferFunction*, skcms_TransferFunction*); +typedef enum skcms_TFType { + skcms_TFType_Invalid, + skcms_TFType_sRGBish, + skcms_TFType_PQish, + skcms_TFType_HLGish, + skcms_TFType_HLGinvish, +} skcms_TFType; + +// Identify which kind of transfer function is encoded in an skcms_TransferFunction +SKCMS_API skcms_TFType skcms_TransferFunction_getType(const skcms_TransferFunction*); + // We can jam a couple alternate transfer function forms into skcms_TransferFunction, // including those matching the general forms of the SMPTE ST 2084 PQ function or HLG. // @@ -307,6 +318,9 @@ typedef enum skcms_PixelFormat { skcms_PixelFormat_BGR_fff, // Pointers must be 32-bit aligned. skcms_PixelFormat_RGBA_ffff, skcms_PixelFormat_BGRA_ffff, + + skcms_PixelFormat_RGB_101010x_XR, // Note: This is located here to signal no clamping. + skcms_PixelFormat_BGR_101010x_XR, // Compatible with MTLPixelFormatBGR10_XR. } skcms_PixelFormat; // We always store any alpha channel linearly. In the chart below, tf-1() is the inverse diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h index 7b8aa8ac1c50f..350f6a20a6c6b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skcms/src/Transform_inl.h @@ -903,6 +903,16 @@ static void exec_ops(const Op* ops, const void** args, a = cast((rgba >> 30) & 0x3 ) * (1/ 3.0f); } break; + case Op_load_101010x_XR:{ + static constexpr float min = -0.752941f; + static constexpr float max = 1.25098f; + static constexpr float range = max - min; + U32 rgba = load(src + 4*i); + r = cast((rgba >> 0) & 0x3ff) * (1/1023.0f) * range + min; + g = cast((rgba >> 10) & 0x3ff) * (1/1023.0f) * range + min; + b = cast((rgba >> 20) & 0x3ff) * (1/1023.0f) * range + min; + } break; + case Op_load_161616LE:{ uintptr_t ptr = (uintptr_t)(src + 6*i); assert( (ptr & 1) == 0 ); // src must be 2-byte aligned for this @@ -1313,6 +1323,15 @@ static void exec_ops(const Op* ops, const void** args, | cast(to_fixed(a * 255)) << 24); } return; + case Op_store_101010x_XR: { + static constexpr float min = -0.752941f; + static constexpr float max = 1.25098f; + static constexpr float range = max - min; + store(dst + 4*i, cast(to_fixed(((r - min) / range) * 1023)) << 0 + | cast(to_fixed(((g - min) / range) * 1023)) << 10 + | cast(to_fixed(((b - min) / range) * 1023)) << 20); + return; + } case Op_store_1010102: { store(dst + 4*i, cast(to_fixed(r * 1023)) << 0 | cast(to_fixed(g * 1023)) << 10 diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h index a119e4b28d2c7..bc895f99c6e81 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/FontCollection.h @@ -7,10 +7,10 @@ #include #include "include/core/SkFontMgr.h" #include "include/core/SkRefCnt.h" -#include "include/private/SkTHash.h" #include "modules/skparagraph/include/FontArguments.h" #include "modules/skparagraph/include/ParagraphCache.h" #include "modules/skparagraph/include/TextStyle.h" +#include "src/core/SkTHash.h" namespace skia { namespace textlayout { @@ -69,7 +69,7 @@ class FontCollection : public SkRefCnt { }; bool fEnableFontFallback; - SkTHashMap>, FamilyKey::Hasher> fTypefaces; + skia_private::THashMap>, FamilyKey::Hasher> fTypefaces; sk_sp fDefaultFontManager; sk_sp fAssetFontManager; sk_sp fDynamicFontManager; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h index 5c5503876bec8..c78b0798412a1 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/Paragraph.h @@ -12,6 +12,8 @@ class SkCanvas; namespace skia { namespace textlayout { +class ParagraphPainter; + class Paragraph { public: @@ -39,6 +41,8 @@ class Paragraph { virtual void paint(SkCanvas* canvas, SkScalar x, SkScalar y) = 0; + virtual void paint(ParagraphPainter* painter, SkScalar x, SkScalar y) = 0; + // Returns a vector of bounding boxes that enclose all text between // start and end glyph indexes, including start and excluding end virtual std::vector getRectsForRange(unsigned start, @@ -66,9 +70,9 @@ class Paragraph { // -1 if not applicable (has not been shaped yet - valid case) virtual int32_t unresolvedGlyphs() = 0; - // Experimental API that allows fast way to update "immutable" paragraph + // Experimental API that allows fast way to update some of "immutable" paragraph attributes + // but not the text itself virtual void updateTextAlign(TextAlign textAlign) = 0; - virtual void updateText(size_t from, SkString text) = 0; virtual void updateFontSize(size_t from, size_t to, SkScalar fontSize) = 0; virtual void updateForegroundPaint(size_t from, size_t to, SkPaint paint) = 0; virtual void updateBackgroundPaint(size_t from, size_t to, SkPaint paint) = 0; @@ -91,6 +95,72 @@ class Paragraph { using Visitor = std::function; virtual void visit(const Visitor&) = 0; + // Editing API + virtual int getLineNumberAt(TextIndex codeUnitIndex) const = 0; + + /* Returns line metrics info for the line + * + * @param lineNumber a line number + * @param lineMetrics an address to return the info (in case of null just skipped) + * @return true if the line is found; false if not + */ + virtual bool getLineMetricsAt(int lineNumber, LineMetrics* lineMetrics) const = 0; + + /* Returns the visible text on the line (excluding a possible ellipsis) + * + * @param lineNumber a line number + * @param includeSpaces indicates if the whitespaces should be included + * @return the range of the text that is shown in the line + */ + virtual TextRange getActualTextRange(int lineNumber, bool includeSpaces) const = 0; + + struct GlyphClusterInfo { + SkRect fBounds; + TextRange fClusterTextRange; + TextDirection fGlyphClusterPosition; + }; + + /** Finds a glyph cluster for text index + * + * @param codeUnitIndex a text index + * @param glyphInfo a glyph cluster info filled if not null + * @return true if glyph cluster was found; false if not + */ + virtual bool getGlyphClusterAt(TextIndex codeUnitIndex, GlyphClusterInfo* glyphInfo) = 0; + + /** Finds the closest glyph cluster for a visual text position + * + * @param dx x coordinate + * @param dy y coordinate + * @param glyphInfo a glyph cluster info filled if not null + * @return + */ + virtual bool getClosestGlyphClusterAt(SkScalar dx, + SkScalar dy, + GlyphClusterInfo* glyphInfo) = 0; + + struct FontInfo { + FontInfo(const SkFont font, const TextRange textRange) + : fFont(font), fTextRange(textRange) { } + virtual ~FontInfo() = default; + FontInfo(const FontInfo& ) = default; + SkFont fFont; + TextRange fTextRange; + }; + + /** Returns the font that is used to shape the text at the position + * + * @param codeUnitIndex text index + * @return font info or an empty font info if the text is not found + */ + virtual SkFont getFontAt(TextIndex codeUnitIndex) const = 0; + + /** Returns the information about all the fonts used to shape the paragraph text + * + * @return a list of fonts and text ranges + */ + virtual std::vector getFonts() const = 0; + protected: sk_sp fFontCollection; ParagraphStyle fParagraphStyle; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h index 90ffb7019d8e8..45652ae79912c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphCache.h @@ -2,7 +2,7 @@ #ifndef ParagraphCache_DEFINED #define ParagraphCache_DEFINED -#include "include/private/SkMutex.h" +#include "include/private/base/SkMutex.h" #include "src/core/SkLRUCache.h" #include // std::function @@ -11,16 +11,6 @@ namespace skia { namespace textlayout { -enum InternalState { - kUnknown = 0, - kShaped = 2, - kClusterized = 3, - kMarked = 4, - kLineBroken = 5, - kFormatted = 6, - kDrawn = 7 -}; - class ParagraphImpl; class ParagraphCacheKey; class ParagraphCacheValue; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h new file mode 100644 index 0000000000000..56388e64f17bd --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/ParagraphPainter.h @@ -0,0 +1,63 @@ +// Copyright 2019 Google LLC. +#ifndef ParagraphPainter_DEFINED +#define ParagraphPainter_DEFINED + +#include "include/core/SkPaint.h" +#include "include/core/SkTextBlob.h" + +#include +#include + +namespace skia { +namespace textlayout { + +class ParagraphPainter { +public: + typedef int PaintID; + typedef std::variant SkPaintOrID; + + struct DashPathEffect { + DashPathEffect(SkScalar onLength, SkScalar offLength); + + SkScalar fOnLength; + SkScalar fOffLength; + }; + + class DecorationStyle { + public: + DecorationStyle(); + DecorationStyle(SkColor color, SkScalar strokeWidth, + std::optional dashPathEffect); + + SkColor getColor() const { return fColor; } + SkScalar getStrokeWidth() const { return fStrokeWidth; } + std::optional getDashPathEffect() const { return fDashPathEffect; } + const SkPaint& skPaint() const { return fPaint; } + + private: + SkColor fColor; + SkScalar fStrokeWidth; + std::optional fDashPathEffect; + SkPaint fPaint; + }; + + virtual ~ParagraphPainter() = default; + + virtual void drawTextBlob(const sk_sp& blob, SkScalar x, SkScalar y, const SkPaintOrID& paint) = 0; + virtual void drawTextShadow(const sk_sp& blob, SkScalar x, SkScalar y, SkColor color, SkScalar blurSigma) = 0; + virtual void drawRect(const SkRect& rect, const SkPaintOrID& paint) = 0; + virtual void drawFilledRect(const SkRect& rect, const DecorationStyle& decorStyle) = 0; + virtual void drawPath(const SkPath& path, const DecorationStyle& decorStyle) = 0; + virtual void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const DecorationStyle& decorStyle) = 0; + + virtual void clipRect(const SkRect& rect) = 0; + virtual void translate(SkScalar dx, SkScalar dy) = 0; + + virtual void save() = 0; + virtual void restore() = 0; +}; + +} // namespace textlayout +} // namespace skia + +#endif // ParagraphPainter_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h index 82b4a7cb13cb4..e6f0ae46302d9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TextStyle.h @@ -12,6 +12,7 @@ #include "include/core/SkScalar.h" #include "modules/skparagraph/include/DartTypes.h" #include "modules/skparagraph/include/FontArguments.h" +#include "modules/skparagraph/include/ParagraphPainter.h" #include "modules/skparagraph/include/TextShadow.h" // TODO: Make it external so the other platforms (Android) could use it @@ -165,19 +166,41 @@ class TextStyle { void setColor(SkColor color) { fColor = color; } bool hasForeground() const { return fHasForeground; } - SkPaint getForeground() const { return fForeground; } + SkPaint getForeground() const { + const SkPaint* paint = std::get_if(&fForeground); + return paint ? *paint : SkPaint(); + } + ParagraphPainter::SkPaintOrID getForegroundPaintOrID() const { + return fForeground; + } void setForegroundColor(SkPaint paint) { fHasForeground = true; fForeground = std::move(paint); } + // Set the foreground to a paint ID. This is intended for use by clients + // that implement a custom ParagraphPainter that can not accept an SkPaint. + void setForegroundPaintID(ParagraphPainter::PaintID paintID) { + fHasForeground = true; + fForeground = paintID; + } void clearForegroundColor() { fHasForeground = false; } bool hasBackground() const { return fHasBackground; } - SkPaint getBackground() const { return fBackground; } + SkPaint getBackground() const { + const SkPaint* paint = std::get_if(&fBackground); + return paint ? *paint : SkPaint(); + } + ParagraphPainter::SkPaintOrID getBackgroundPaintOrID() const { + return fBackground; + } void setBackgroundColor(SkPaint paint) { fHasBackground = true; fBackground = std::move(paint); } + void setBackgroundPaintID(ParagraphPainter::PaintID paintID) { + fHasBackground = true; + fBackground = paintID; + } void clearBackgroundColor() { fHasBackground = false; } // Decorations @@ -291,9 +314,9 @@ class TextStyle { SkColor fColor = SK_ColorWHITE; bool fHasBackground = false; - SkPaint fBackground; + ParagraphPainter::SkPaintOrID fBackground; bool fHasForeground = false; - SkPaint fForeground; + ParagraphPainter::SkPaintOrID fForeground; std::vector fTextShadows; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h index df759b125ad24..c51110cd4fea9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h @@ -2,8 +2,8 @@ #ifndef TypefaceFontProvider_DEFINED #define TypefaceFontProvider_DEFINED -#include "include/private/SkTArray.h" -#include "include/private/SkTHash.h" +#include "include/private/base/SkTArray.h" +#include "src/core/SkTHash.h" #include #include #include @@ -20,15 +20,15 @@ class TypefaceFontStyleSet : public SkFontStyleSet { int count() override; void getStyle(int index, SkFontStyle*, SkString* name) override; - SkTypeface* createTypeface(int index) override; - SkTypeface* matchStyle(const SkFontStyle& pattern) override; + sk_sp createTypeface(int index) override; + sk_sp matchStyle(const SkFontStyle& pattern) override; SkString getFamilyName() const { return fFamilyName; } SkString getAlias() const { return fAlias; } void appendTypeface(sk_sp typeface); private: - SkTArray> fStyles; + skia_private::TArray> fStyles; SkString fFamilyName; SkString fAlias; }; @@ -42,15 +42,15 @@ class TypefaceFontProvider : public SkFontMgr { void onGetFamilyName(int index, SkString* familyName) const override; - SkFontStyleSet* onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; - SkFontStyleSet* onCreateStyleSet(int) const override { return nullptr; } - SkTypeface* onMatchFamilyStyle(const char[], const SkFontStyle&) const override { + sk_sp onCreateStyleSet(int) const override { return nullptr; } + sk_sp onMatchFamilyStyle(const char[], const SkFontStyle&) const override { return nullptr; } - SkTypeface* onMatchFamilyStyleCharacter(const char[], const SkFontStyle&, - const char*[], int, - SkUnichar) const override { + sk_sp onMatchFamilyStyleCharacter(const char[], const SkFontStyle&, + const char*[], int, + SkUnichar) const override { return nullptr; } @@ -71,8 +71,8 @@ class TypefaceFontProvider : public SkFontMgr { } private: - SkTHashMap> fRegisteredFamilies; - SkTArray fFamilyNames; + skia_private::THashMap> fRegisteredFamilies; + skia_private::TArray fFamilyNames; }; } // namespace textlayout diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h index f59471198b066..a0f44a83be116 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/skresources/include/SkResources.h @@ -15,8 +15,8 @@ #include "include/core/SkString.h" #include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" -#include "include/private/SkMutex.h" -#include "include/private/SkTHash.h" +#include "include/private/base/SkMutex.h" +#include "src/core/SkTHash.h" #include @@ -50,6 +50,18 @@ class SK_API ImageAsset : public SkRefCnt { */ virtual sk_sp getFrame(float t); + // Describes how the frame image is to be scaled to the animation-declared asset size. + enum class SizeFit { + // See SkMatrix::ScaleToFit + kFill = SkMatrix::kFill_ScaleToFit, + kStart = SkMatrix::kStart_ScaleToFit, + kCenter = SkMatrix::kCenter_ScaleToFit, + kEnd = SkMatrix::kEnd_ScaleToFit, + + // No scaling. + kNone, + }; + struct FrameData { // SkImage payload. sk_sp image; @@ -57,6 +69,8 @@ class SK_API ImageAsset : public SkRefCnt { SkSamplingOptions sampling; // Additional image transform to be applied before AE scaling rules. SkMatrix matrix = SkMatrix::I(); + // Strategy for image size -> AE asset size scaling. + SizeFit scaling = SizeFit::kCenter; }; /** @@ -227,8 +241,8 @@ class SK_API CachingResourceProvider final : public ResourceProviderProxyBase { sk_sp loadImageAsset(const char[], const char[], const char[]) const override; - mutable SkMutex fMutex; - mutable SkTHashMap> fImageCache; + mutable SkMutex fMutex; + mutable skia_private::THashMap> fImageCache; using INHERITED = ResourceProviderProxyBase; }; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h index d6996638ccdcf..8e4d56caee221 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttribute.h @@ -9,7 +9,7 @@ #define SkSVGAttribute_DEFINED #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGRenderContext; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h index e4ac579f7966d..9513232218668 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGAttributeParser.h @@ -10,9 +10,9 @@ #include -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGAttributeParser : public SkNoncopyable { public: diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h index 560271854f5b6..e5e9516c32e68 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGContainer.h @@ -8,7 +8,7 @@ #ifndef SkSVGContainer_DEFINED #define SkSVGContainer_DEFINED -#include "include/private/SkTArray.h" +#include "include/private/base/SkTArray.h" #include "modules/svg/include/SkSVGTransformableNode.h" class SkSVGContainer : public SkSVGTransformableNode { @@ -27,7 +27,7 @@ class SkSVGContainer : public SkSVGTransformableNode { bool hasChildren() const final; // TODO: add some sort of child iterator, and hide the container. - SkSTArray<1, sk_sp, true> fChildren; + skia_private::STArray<1, sk_sp, true> fChildren; private: using INHERITED = SkSVGTransformableNode; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h index a035179b70e7b..f0bd467d28aee 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGDOM.h @@ -11,7 +11,7 @@ #include "include/core/SkFontMgr.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSize.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include "modules/skresources/include/SkResources.h" #include "modules/svg/include/SkSVGIDMapper.h" diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h index edd503403c130..dcd938d1e1838 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGFilterContext.h @@ -11,8 +11,8 @@ #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" #include "include/core/SkString.h" -#include "include/private/SkTHash.h" #include "modules/svg/include/SkSVGTypes.h" +#include "src/core/SkTHash.h" class SkImageFilter; class SkSVGFeInputType; @@ -61,7 +61,7 @@ class SkSVGFilterContext { SkSVGObjectBoundingBoxUnits fPrimitiveUnits; - SkTHashMap fResults; + skia_private::THashMap fResults; Result fPreviousResult; }; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h index 2c1e45afcf5d8..16053e83c85fd 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGGradient.h @@ -37,8 +37,8 @@ class SkSVGGradient : public SkSVGHiddenContainer { SkTileMode, const SkMatrix& localMatrix) const = 0; private: - using StopPositionArray = SkSTArray<2, SkScalar , true>; - using StopColorArray = SkSTArray<2, SkColor4f, true>; + using StopPositionArray = skia_private::STArray<2, SkScalar , true>; + using StopColorArray = skia_private::STArray<2, SkColor4f, true>; void collectColorStops(const SkSVGRenderContext&, StopPositionArray*, StopColorArray*) const; SkColor4f resolveStopColor(const SkSVGRenderContext&, const SkSVGStop&) const; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h index ea0d9165fcbae..e78f28de37368 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGIDMapper.h @@ -9,11 +9,11 @@ #define SkSVGIDMapper_DEFINED #include "include/core/SkRefCnt.h" -#include "include/private/SkTHash.h" +#include "src/core/SkTHash.h" class SkString; class SkSVGNode; -using SkSVGIDMapper = SkTHashMap>; +using SkSVGIDMapper = skia_private::THashMap>; #endif // SkSVGIDMapper_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h index 27a86395cb4b4..32ee8a08e415f 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGRenderContext.h @@ -15,11 +15,11 @@ #include "include/core/SkRect.h" #include "include/core/SkSize.h" #include "include/core/SkTypes.h" -#include "include/private/SkTHash.h" #include "modules/skresources/include/SkResources.h" #include "modules/svg/include/SkSVGAttribute.h" #include "modules/svg/include/SkSVGIDMapper.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" +#include "src/core/SkTHash.h" class SkCanvas; class SkSVGLength; @@ -52,7 +52,7 @@ struct SkSVGPresentationContext { SkSVGPresentationContext(const SkSVGPresentationContext&) = default; SkSVGPresentationContext& operator=(const SkSVGPresentationContext&) = default; - const SkTHashMap* fNamedColors = nullptr; + const skia_private::THashMap* fNamedColors = nullptr; // Inherited presentation attributes, computed for the current node. SkSVGPresentationAttributes fInherited; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h index 91f33dea9a3c2..41e041de3f76c 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGSVG.h @@ -10,7 +10,7 @@ #include "modules/svg/include/SkSVGContainer.h" #include "modules/svg/include/SkSVGTypes.h" -#include "src/core/SkTLazy.h" +#include "src/base/SkTLazy.h" class SkSVGLengthContext; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h index db103bef59179..77c5fbef40562 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGTypes.h @@ -18,8 +18,9 @@ #include "include/core/SkSpan.h" #include "include/core/SkString.h" #include "include/core/SkTypes.h" -#include "include/private/SkTDArray.h" -#include "src/core/SkTLazy.h" + +#include +#include using SkSVGColorType = SkColor; using SkSVGIntegerType = int; @@ -27,7 +28,7 @@ using SkSVGNumberType = SkScalar; using SkSVGStringType = SkString; using SkSVGViewBoxType = SkRect; using SkSVGTransformType = SkMatrix; -using SkSVGPointsType = SkTDArray; +using SkSVGPointsType = std::vector; enum class SkSVGPropertyState { kUnspecified, @@ -45,17 +46,17 @@ template class SkSVGProperty { explicit SkSVGProperty(SkSVGPropertyState state) : fState(state) {} explicit SkSVGProperty(const T& value) : fState(SkSVGPropertyState::kValue) { - fValue.set(value); + fValue = value; } explicit SkSVGProperty(T&& value) : fState(SkSVGPropertyState::kValue) { - fValue.set(std::move(value)); + fValue = std::move(value); } template void init(Args&&... args) { fState = SkSVGPropertyState::kValue; - fValue.init(std::forward(args)...); + fValue.emplace(std::forward(args)...); } constexpr bool isInheritable() const { return kInheritable; } @@ -63,7 +64,7 @@ template class SkSVGProperty { bool isValue() const { return fState == SkSVGPropertyState::kValue; } T* getMaybeNull() const { - return fValue.getMaybeNull(); + return fValue.has_value() ? &fValue.value() : nullptr; } void set(SkSVGPropertyState state) { @@ -75,41 +76,41 @@ template class SkSVGProperty { void set(const T& value) { fState = SkSVGPropertyState::kValue; - fValue.set(value); + fValue = value; } void set(T&& value) { fState = SkSVGPropertyState::kValue; - fValue.set(std::move(value)); + fValue = std::move(value); } T* operator->() { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); - return fValue.get(); + SkASSERT(fValue.has_value()); + return &fValue.value(); } const T* operator->() const { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); - return fValue.get(); + SkASSERT(fValue.has_value()); + return &fValue.value(); } T& operator*() { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); + SkASSERT(fValue.has_value()); return *fValue; } const T& operator*() const { SkASSERT(fState == SkSVGPropertyState::kValue); - SkASSERT(fValue.isValid()); + SkASSERT(fValue.has_value()); return *fValue; } private: SkSVGPropertyState fState; - SkTLazy fValue; + std::optional fValue; }; class SkSVGLength { @@ -180,7 +181,7 @@ class SkSVGColor { kColor, kICCColor, }; - using Vars = SkSTArray<1, SkString>; + using Vars = std::vector; SkSVGColor() : SkSVGColor(SK_ColorBLACK) {} explicit SkSVGColor(const SkSVGColorType& c) : fType(Type::kColor), fColor(c), fVars(nullptr) {} @@ -400,7 +401,7 @@ class SkSVGDashArray { SkSVGDashArray() : fType(Type::kNone) {} explicit SkSVGDashArray(Type t) : fType(t) {} - explicit SkSVGDashArray(SkTDArray&& dashArray) + explicit SkSVGDashArray(std::vector&& dashArray) : fType(Type::kDashArray) , fDashArray(std::move(dashArray)) {} @@ -414,11 +415,11 @@ class SkSVGDashArray { Type type() const { return fType; } - const SkTDArray& dashArray() const { return fDashArray; } + const std::vector& dashArray() const { return fDashArray; } private: Type fType; - SkTDArray fDashArray; + std::vector fDashArray; }; class SkSVGStopColor { @@ -673,7 +674,7 @@ enum class SkSVGFeColorMatrixType { kLuminanceToAlpha, }; -using SkSVGFeColorMatrixValues = SkTDArray; +using SkSVGFeColorMatrixValues = std::vector; enum class SkSVGFeCompositeOperator { kOver, diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h index eb1977feb356e..d03afa6d9fa98 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/modules/svg/include/SkSVGValue.h @@ -12,7 +12,7 @@ #include "include/core/SkMatrix.h" #include "include/core/SkPath.h" #include "include/core/SkTypes.h" -#include "include/private/SkNoncopyable.h" +#include "include/private/base/SkNoncopyable.h" #include "modules/svg/include/SkSVGTypes.h" class SkSVGValue : public SkNoncopyable { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h deleted file mode 100644 index 50429d500f25c..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkLRUCache.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkLRUCache_DEFINED -#define SkLRUCache_DEFINED - -#include "include/private/SkChecksum.h" -#include "include/private/SkTHash.h" -#include "src/core/SkTInternalLList.h" - -/** - * A generic LRU cache. - */ -template -class SkLRUCache : public SkNoncopyable { -private: - struct Entry { - Entry(const K& key, V&& value) - : fKey(key) - , fValue(std::move(value)) {} - - K fKey; - V fValue; - - SK_DECLARE_INTERNAL_LLIST_INTERFACE(Entry); - }; - -public: - explicit SkLRUCache(int maxCount) - : fMaxCount(maxCount) {} - - ~SkLRUCache() { - Entry* node = fLRU.head(); - while (node) { - fLRU.remove(node); - delete node; - node = fLRU.head(); - } - } - - V* find(const K& key) { - Entry** value = fMap.find(key); - if (!value) { - return nullptr; - } - Entry* entry = *value; - if (entry != fLRU.head()) { - fLRU.remove(entry); - fLRU.addToHead(entry); - } // else it's already at head position, don't need to do anything - return &entry->fValue; - } - - V* insert(const K& key, V value) { - SkASSERT(!this->find(key)); - - Entry* entry = new Entry(key, std::move(value)); - fMap.set(entry); - fLRU.addToHead(entry); - while (fMap.count() > fMaxCount) { - this->remove(fLRU.tail()->fKey); - } - return &entry->fValue; - } - - V* insert_or_update(const K& key, V value) { - if (V* found = this->find(key)) { - *found = std::move(value); - return found; - } else { - return this->insert(key, std::move(value)); - } - } - - int count() { - return fMap.count(); - } - - template // f(K*, V*) - void foreach(Fn&& fn) { - typename SkTInternalLList::Iter iter; - for (Entry* e = iter.init(fLRU, SkTInternalLList::Iter::kHead_IterStart); e; - e = iter.next()) { - fn(&e->fKey, &e->fValue); - } - } - - void reset() { - fMap.reset(); - for (Entry* e = fLRU.head(); e; e = fLRU.head()) { - fLRU.remove(e); - delete e; - } - } - -private: - struct Traits { - static const K& GetKey(Entry* e) { - return e->fKey; - } - - static uint32_t Hash(const K& k) { - return HashK()(k); - } - }; - - void remove(const K& key) { - Entry** value = fMap.find(key); - SkASSERT(value); - Entry* entry = *value; - SkASSERT(key == entry->fKey); - fMap.remove(key); - fLRU.remove(entry); - delete entry; - } - - int fMaxCount; - SkTHashTable fMap; - SkTInternalLList fLRU; -}; - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h similarity index 89% rename from ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h rename to ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h index 7fe6d33c70c84..e72483b501df1 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/include/private/SkTHash.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTHash.h @@ -10,13 +10,15 @@ #include "include/core/SkTypes.h" #include "include/private/SkChecksum.h" -#include "include/private/SkTemplates.h" +#include "include/private/base/SkTemplates.h" #include #include #include -// Before trying to use SkTHashTable, look below to see if SkTHashMap or SkTHashSet works for you. +namespace skia_private { + +// Before trying to use THashTable, look below to see if THashMap or THashSet works for you. // They're easier to use, usually perform the same, and have fewer sharp edges. // T and K are treated as ordinary copyable C++ types. @@ -26,15 +28,15 @@ // If the key is large and stored inside T, you may want to make K a const&. // Similarly, if T is large you might want it to be a pointer. template -class SkTHashTable { +class THashTable { public: - SkTHashTable() = default; - ~SkTHashTable() = default; + THashTable() = default; + ~THashTable() = default; - SkTHashTable(const SkTHashTable& that) { *this = that; } - SkTHashTable( SkTHashTable&& that) { *this = std::move(that); } + THashTable(const THashTable& that) { *this = that; } + THashTable( THashTable&& that) { *this = std::move(that); } - SkTHashTable& operator=(const SkTHashTable& that) { + THashTable& operator=(const THashTable& that) { if (this != &that) { fCount = that.fCount; fCapacity = that.fCapacity; @@ -46,7 +48,7 @@ class SkTHashTable { return *this; } - SkTHashTable& operator=(SkTHashTable&& that) { + THashTable& operator=(THashTable&& that) { if (this != &that) { fCount = that.fCount; fCapacity = that.fCapacity; @@ -58,7 +60,7 @@ class SkTHashTable { } // Clear the table. - void reset() { *this = SkTHashTable(); } + void reset() { *this = THashTable(); } // How many entries are in the table? int count() const { return fCount; } @@ -75,7 +77,7 @@ class SkTHashTable { // If you change an entry so that it no longer has the same key, all hell // will break loose. Do not do that! // - // Please prefer to use SkTHashMap or SkTHashSet, which do not have this danger. + // Please prefer to use THashMap or THashSet, which do not have this danger. // The pointers returned by set() and find() are valid only until the next call to set(). // The pointers you receive in foreach() are only valid for its duration. @@ -103,7 +105,7 @@ class SkTHashTable { } index = this->next(index); } - SkASSERT(fCapacity == 0); + SkASSERT(fCapacity == fCount); return nullptr; } @@ -145,8 +147,8 @@ class SkTHashTable { fCount = 0; fCapacity = capacity; - SkAutoTArray oldSlots = std::move(fSlots); - fSlots = SkAutoTArray(capacity); + AutoTArray oldSlots = std::move(fSlots); + fSlots = AutoTArray(capacity); for (int i = 0; i < oldCapacity; i++) { Slot& s = oldSlots[i]; @@ -178,12 +180,12 @@ class SkTHashTable { } // A basic iterator-like class which disallows mutation; sufficient for range-based for loops. - // Intended for use by SkTHashMap and SkTHashSet via begin() and end(). + // Intended for use by THashMap and THashSet via begin() and end(). // Adding or removing elements may invalidate all iterators. template class Iter { public: - using TTable = SkTHashTable; + using TTable = THashTable; Iter(const TTable* table, int slot) : fTable(table), fSlot(slot) {} @@ -411,22 +413,22 @@ class SkTHashTable { int fCount = 0, fCapacity = 0; - SkAutoTArray fSlots; + AutoTArray fSlots; }; -// Maps K->V. A more user-friendly wrapper around SkTHashTable, suitable for most use cases. +// Maps K->V. A more user-friendly wrapper around THashTable, suitable for most use cases. // K and V are treated as ordinary copyable C++ types, with no assumed relationship between the two. template -class SkTHashMap { +class THashMap { public: // Allow default construction and assignment. - SkTHashMap() = default; + THashMap() = default; - SkTHashMap(SkTHashMap&& that) = default; - SkTHashMap(const SkTHashMap& that) = default; + THashMap(THashMap&& that) = default; + THashMap(const THashMap& that) = default; - SkTHashMap& operator=(SkTHashMap&& that) = default; - SkTHashMap& operator=(const SkTHashMap& that) = default; + THashMap& operator=(THashMap&& that) = default; + THashMap& operator=(const THashMap& that) = default; // Construct with an initializer list of key-value pairs. struct Pair : public std::pair { @@ -435,7 +437,7 @@ class SkTHashMap { static auto Hash(const K& key) { return HashK()(key); } }; - SkTHashMap(std::initializer_list pairs) { + THashMap(std::initializer_list pairs) { fTable.resize(pairs.size() * 5 / 3); for (const Pair& p : pairs) { fTable.set(p); @@ -498,7 +500,7 @@ class SkTHashMap { } // Dereferencing an iterator gives back a key-value pair, suitable for structured binding. - using Iter = typename SkTHashTable::template Iter>; + using Iter = typename THashTable::template Iter>; Iter begin() const { return Iter::MakeBegin(&fTable); @@ -509,24 +511,24 @@ class SkTHashMap { } private: - SkTHashTable fTable; + THashTable fTable; }; // A set of T. T is treated as an ordinary copyable C++ type. template -class SkTHashSet { +class THashSet { public: // Allow default construction and assignment. - SkTHashSet() = default; + THashSet() = default; - SkTHashSet(SkTHashSet&& that) = default; - SkTHashSet(const SkTHashSet& that) = default; + THashSet(THashSet&& that) = default; + THashSet(const THashSet& that) = default; - SkTHashSet& operator=(SkTHashSet&& that) = default; - SkTHashSet& operator=(const SkTHashSet& that) = default; + THashSet& operator=(THashSet&& that) = default; + THashSet& operator=(const THashSet& that) = default; // Construct with an initializer list of Ts. - SkTHashSet(std::initializer_list vals) { + THashSet(std::initializer_list vals) { fTable.resize(vals.size() * 5 / 3); for (const T& val : vals) { fTable.set(val); @@ -574,7 +576,7 @@ class SkTHashSet { }; public: - using Iter = typename SkTHashTable::template Iter; + using Iter = typename THashTable::template Iter; Iter begin() const { return Iter::MakeBegin(&fTable); @@ -585,7 +587,9 @@ class SkTHashSet { } private: - SkTHashTable fTable; + THashTable fTable; }; -#endif//SkTHash_DEFINED +} // namespace skia_private + +#endif // SkTHash_DEFINED diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h deleted file mode 100644 index a5cb615556e56..0000000000000 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/skia/src/core/SkTInternalLList.h +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkTInternalLList_DEFINED -#define SkTInternalLList_DEFINED - -#include "include/core/SkTypes.h" - -/** - * This macro creates the member variables required by the SkTInternalLList class. It should be - * placed in the private section of any class that will be stored in a double linked list. - */ -#define SK_DECLARE_INTERNAL_LLIST_INTERFACE(ClassName) \ - friend class SkTInternalLList; \ - /* back pointer to the owning list - for debugging */ \ - SkDEBUGCODE(SkTInternalLList* fList = nullptr;) \ - ClassName* fPrev = nullptr; \ - ClassName* fNext = nullptr - -/** - * This class implements a templated internal doubly linked list data structure. - */ -template class SkTInternalLList { -public: - SkTInternalLList() {} - - void reset() { - fHead = nullptr; - fTail = nullptr; - } - - void remove(T* entry) { - SkASSERT(fHead && fTail); - SkASSERT(this->isInList(entry)); - - T* prev = entry->fPrev; - T* next = entry->fNext; - - if (prev) { - prev->fNext = next; - } else { - fHead = next; - } - if (next) { - next->fPrev = prev; - } else { - fTail = prev; - } - - entry->fPrev = nullptr; - entry->fNext = nullptr; - -#ifdef SK_DEBUG - entry->fList = nullptr; -#endif - } - - void addToHead(T* entry) { - SkASSERT(nullptr == entry->fPrev && nullptr == entry->fNext); - SkASSERT(nullptr == entry->fList); - - entry->fPrev = nullptr; - entry->fNext = fHead; - if (fHead) { - fHead->fPrev = entry; - } - fHead = entry; - if (nullptr == fTail) { - fTail = entry; - } - -#ifdef SK_DEBUG - entry->fList = this; -#endif - } - - void addToTail(T* entry) { - SkASSERT(nullptr == entry->fPrev && nullptr == entry->fNext); - SkASSERT(nullptr == entry->fList); - - entry->fPrev = fTail; - entry->fNext = nullptr; - if (fTail) { - fTail->fNext = entry; - } - fTail = entry; - if (nullptr == fHead) { - fHead = entry; - } - -#ifdef SK_DEBUG - entry->fList = this; -#endif - } - - /** - * Inserts a new list entry before an existing list entry. The new entry must not already be - * a member of this or any other list. If existingEntry is NULL then the new entry is added - * at the tail. - */ - void addBefore(T* newEntry, T* existingEntry) { - SkASSERT(newEntry); - - if (nullptr == existingEntry) { - this->addToTail(newEntry); - return; - } - - SkASSERT(this->isInList(existingEntry)); - newEntry->fNext = existingEntry; - T* prev = existingEntry->fPrev; - existingEntry->fPrev = newEntry; - newEntry->fPrev = prev; - if (nullptr == prev) { - SkASSERT(fHead == existingEntry); - fHead = newEntry; - } else { - prev->fNext = newEntry; - } -#ifdef SK_DEBUG - newEntry->fList = this; -#endif - } - - /** - * Inserts a new list entry after an existing list entry. The new entry must not already be - * a member of this or any other list. If existingEntry is NULL then the new entry is added - * at the head. - */ - void addAfter(T* newEntry, T* existingEntry) { - SkASSERT(newEntry); - - if (nullptr == existingEntry) { - this->addToHead(newEntry); - return; - } - - SkASSERT(this->isInList(existingEntry)); - newEntry->fPrev = existingEntry; - T* next = existingEntry->fNext; - existingEntry->fNext = newEntry; - newEntry->fNext = next; - if (nullptr == next) { - SkASSERT(fTail == existingEntry); - fTail = newEntry; - } else { - next->fPrev = newEntry; - } -#ifdef SK_DEBUG - newEntry->fList = this; -#endif - } - - void concat(SkTInternalLList&& list) { - if (list.isEmpty()) { - return; - } - - list.fHead->fPrev = fTail; - if (!fHead) { - SkASSERT(!list.fHead->fPrev); - fHead = list.fHead; - } else { - SkASSERT(fTail); - fTail->fNext = list.fHead; - } - fTail = list.fTail; - -#ifdef SK_DEBUG - for (T* node = list.fHead; node; node = node->fNext) { - SkASSERT(node->fList == &list); - node->fList = this; - } -#endif - - list.fHead = list.fTail = nullptr; - } - - bool isEmpty() const { - SkASSERT(SkToBool(fHead) == SkToBool(fTail)); - return !fHead; - } - - T* head() const { return fHead; } - T* tail() const { return fTail; } - - class Iter { - public: - enum IterStart { - kHead_IterStart, - kTail_IterStart - }; - - Iter() : fCurr(nullptr) {} - Iter(const Iter& iter) : fCurr(iter.fCurr) {} - Iter& operator= (const Iter& iter) { fCurr = iter.fCurr; return *this; } - - T* init(const SkTInternalLList& list, IterStart startLoc) { - if (kHead_IterStart == startLoc) { - fCurr = list.fHead; - } else { - SkASSERT(kTail_IterStart == startLoc); - fCurr = list.fTail; - } - - return fCurr; - } - - T* get() { return fCurr; } - - /** - * Return the next/previous element in the list or NULL if at the end. - */ - T* next() { - if (nullptr == fCurr) { - return nullptr; - } - - fCurr = fCurr->fNext; - return fCurr; - } - - T* prev() { - if (nullptr == fCurr) { - return nullptr; - } - - fCurr = fCurr->fPrev; - return fCurr; - } - - /** - * C++11 range-for interface. - */ - bool operator!=(const Iter& that) { return fCurr != that.fCurr; } - T* operator*() { return this->get(); } - void operator++() { this->next(); } - - private: - T* fCurr; - }; - - Iter begin() const { - Iter iter; - iter.init(*this, Iter::kHead_IterStart); - return iter; - } - - Iter end() const { return Iter(); } - -#ifdef SK_DEBUG - void validate() const { - SkASSERT(!fHead == !fTail); - Iter iter; - for (T* item = iter.init(*this, Iter::kHead_IterStart); item; item = iter.next()) { - SkASSERT(this->isInList(item)); - if (nullptr == item->fPrev) { - SkASSERT(fHead == item); - } else { - SkASSERT(item->fPrev->fNext == item); - } - if (nullptr == item->fNext) { - SkASSERT(fTail == item); - } else { - SkASSERT(item->fNext->fPrev == item); - } - } - } - - /** - * Debugging-only method that uses the list back pointer to check if 'entry' is indeed in 'this' - * list. - */ - bool isInList(const T* entry) const { - return entry->fList == this; - } - - /** - * Debugging-only method that laboriously counts the list entries. - */ - int countEntries() const { - int count = 0; - for (T* entry = fHead; entry; entry = entry->fNext) { - ++count; - } - return count; - } -#endif // SK_DEBUG - -private: - T* fHead = nullptr; - T* fTail = nullptr; - - SkTInternalLList(const SkTInternalLList&) = delete; - SkTInternalLList& operator=(const SkTInternalLList&) = delete; -}; - -#endif diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkMeasureTime.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkMeasureTime.h index 0edebdcc7a553..de3e6acde53d3 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkMeasureTime.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkMeasureTime.h @@ -7,7 +7,7 @@ #include #include -#include +#include "RNSkLog.h" namespace RNSkia { diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkTimingInfo.h b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkTimingInfo.h index 69172fe0fe6df..10d86ec2a7e19 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkTimingInfo.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/cpp/utils/RNSkTimingInfo.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "RNSkLog.h" #include #include #include diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/DisplayLink.mm b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/DisplayLink.mm index 49abc48310fa6..b30677ae668d9 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/DisplayLink.mm +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/DisplayLink.mm @@ -2,35 +2,33 @@ @implementation DisplayLink -- (void)start:(block_t)block -{ - self.updateBlock = block; - // check whether the loop is already running - if(_displayLink == nil) - { - // specify update method - _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(update:)]; +- (void)start:(block_t)block { + self.updateBlock = block; + // check whether the loop is already running + if (_displayLink == nil) { + // specify update method + _displayLink = [CADisplayLink displayLinkWithTarget:self + selector:@selector(update:)]; - // add the display link to the main run loop - [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; - } + // add the display link to the main run loop + [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] + forMode:NSRunLoopCommonModes]; + } } -- (void)stop -{ - // check whether the loop is already stopped - if (_displayLink != nil) { - // if the display link is present, it gets invalidated (loop stops) - - [_displayLink invalidate]; - _displayLink = nil; - } +- (void)stop { + // check whether the loop is already stopped + if (_displayLink != nil) { + // if the display link is present, it gets invalidated (loop stops) + + [_displayLink invalidate]; + _displayLink = nil; + } } -- (void)update:(CADisplayLink *)sender -{ - double time = [sender timestamp]; - _updateBlock(time); +- (void)update:(CADisplayLink *)sender { + double time = [sender timestamp]; + _updateBlock(time); } @end diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm index 98b5f6291c538..15a444530bd21 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm @@ -1,12 +1,12 @@ -#import #import +#import #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" +#import "SkCanvas.h" #import "SkColorSpace.h" #import "SkSurface.h" -#import "SkCanvas.h" #import @@ -25,14 +25,14 @@ return renderContexts.at(threadId); } -RNSkMetalCanvasProvider::RNSkMetalCanvasProvider(std::function requestRedraw, - std::shared_ptr context): -RNSkCanvasProvider(requestRedraw), - _context(context) { - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wunguarded-availability-new" +RNSkMetalCanvasProvider::RNSkMetalCanvasProvider( + std::function requestRedraw, + std::shared_ptr context) + : RNSkCanvasProvider(requestRedraw), _context(context) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability-new" _layer = [CAMetalLayer layer]; - #pragma clang diagnostic pop +#pragma clang diagnostic pop auto device = MTLCreateSystemDefaultDevice(); @@ -44,80 +44,102 @@ _layer.contentsGravity = kCAGravityBottomLeft; } -RNSkMetalCanvasProvider::~RNSkMetalCanvasProvider() { - -} +RNSkMetalCanvasProvider::~RNSkMetalCanvasProvider() {} /** Returns the scaled width of the view */ -float RNSkMetalCanvasProvider::getScaledWidth() { return _width * _context->getPixelDensity(); }; +float RNSkMetalCanvasProvider::getScaledWidth() { + return _width * _context->getPixelDensity(); +}; /** Returns the scaled height of the view */ -float RNSkMetalCanvasProvider::getScaledHeight() { return _height * _context->getPixelDensity(); }; +float RNSkMetalCanvasProvider::getScaledHeight() { + return _height * _context->getPixelDensity(); +}; /** Render to a canvas */ -void RNSkMetalCanvasProvider::renderToCanvas(const std::function& cb) { +void RNSkMetalCanvasProvider::renderToCanvas( + const std::function &cb) { if (_width <= 0 || _height <= 0) { return; } - - // Make sure to NOT render or try any render operations while we're in the background or inactive. - // This will cause an error that might clear the CAMetalLayer so that the canvas is empty when - // the app receives focus again. + + // Make sure to NOT render or try any render operations while we're in the + // background or inactive. This will cause an error that might clear the + // CAMetalLayer so that the canvas is empty when the app receives focus again. // Reference: https://github.com/Shopify/react-native-skia/issues/1257 - auto state = UIApplication.sharedApplication.applicationState; - if (state == UIApplicationStateBackground || state == UIApplicationStateInactive) - { - // Request a redraw in the next run loop callback - _requestRedraw(); - // and don't draw now since it might cause errors in the metal renderer if - // we try to render while in the background. (see above issue) - return; + // NOTE: UIApplication.sharedApplication.applicationState can only be + // accessed from the main thread so we need to check here. + if ([[NSThread currentThread] isMainThread]) { + auto state = UIApplication.sharedApplication.applicationState; + if (state == UIApplicationStateBackground || + state == UIApplicationStateInactive) { + // Request a redraw in the next run loop callback + _requestRedraw(); + // and don't draw now since it might cause errors in the metal renderer if + // we try to render while in the background. (see above issue) + return; + } } - + // Get render context for current thread auto renderContext = getMetalRenderContext(); - + if (renderContext->skContext == nullptr) { auto device = MTLCreateSystemDefaultDevice(); - renderContext->commandQueue = id(CFRetain((GrMTLHandle)[device newCommandQueue])); - renderContext->skContext = GrDirectContext::MakeMetal((__bridge void*)device, (__bridge void*)renderContext->commandQueue); + renderContext->commandQueue = + id(CFRetain((GrMTLHandle)[device newCommandQueue])); + renderContext->skContext = GrDirectContext::MakeMetal( + (__bridge void *)device, (__bridge void *)renderContext->commandQueue); } - // Wrap in auto release pool since we want the system to clean up after rendering - // and not wait until later - we've seen some example of memory usage growing very - // fast in the simulator without this. - @autoreleasepool - { - - GrMTLHandle drawableHandle; - auto skSurface = SkSurface::MakeFromCAMetalLayer(renderContext->skContext.get(), - (__bridge GrMTLHandle)_layer, - kTopLeft_GrSurfaceOrigin, - 1, - kBGRA_8888_SkColorType, - nullptr, - nullptr, - &drawableHandle); - - if(skSurface == nullptr || skSurface->getCanvas() == nullptr) { - RNSkia::RNSkLogger::logToConsole("Skia surface could not be created from parameters."); + // Wrap in auto release pool since we want the system to clean up after + // rendering and not wait until later - we've seen some example of memory + // usage growing very fast in the simulator without this. + @autoreleasepool { + + /* It is super important that we use the pattern of calling nextDrawable + inside this autoreleasepool and not depend on Skia's + SkSurface::MakeFromCAMetalLayer to encapsulate since we're seeing a lot of + drawables leaking if they're not done this way. + + This is now reverted from: + (https://github.com/Shopify/react-native-skia/commit/2e2290f8e6dfc6921f97b79f779d920fbc1acceb) + back to the original implementation. + */ + id currentDrawable = [_layer nextDrawable]; + if (currentDrawable == nullptr) { + return; + } + + GrMtlTextureInfo fbInfo; + fbInfo.fTexture.retain((__bridge void *)currentDrawable.texture); + + GrBackendRenderTarget backendRT(_layer.drawableSize.width, + _layer.drawableSize.height, 1, fbInfo); + + auto skSurface = SkSurface::MakeFromBackendRenderTarget( + renderContext->skContext.get(), backendRT, kTopLeft_GrSurfaceOrigin, + kBGRA_8888_SkColorType, nullptr, nullptr); + + if (skSurface == nullptr || skSurface->getCanvas() == nullptr) { + RNSkia::RNSkLogger::logToConsole( + "Skia surface could not be created from parameters."); return; } - + SkCanvas *canvas = skSurface->getCanvas(); - canvas->clear(SK_AlphaTRANSPARENT); - cb(canvas); + cb(canvas); + skSurface->flushAndSubmit(); - - id currentDrawable = (__bridge id)drawableHandle; - id commandBuffer([renderContext->commandQueue commandBuffer]); - commandBuffer.label = @"PresentSkia"; + + id commandBuffer( + [renderContext->commandQueue commandBuffer]); [commandBuffer presentDrawable:currentDrawable]; [commandBuffer commit]; } @@ -128,9 +150,9 @@ _height = height; _layer.frame = CGRectMake(0, 0, width, height); _layer.drawableSize = CGSizeMake(width * _context->getPixelDensity(), - height* _context->getPixelDensity()); + height * _context->getPixelDensity()); _requestRedraw(); } -CALayer* RNSkMetalCanvasProvider::getLayer() { return _layer; } +CALayer *RNSkMetalCanvasProvider::getLayer() { return _layer; } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkiOSPlatformContext.h b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkiOSPlatformContext.h index e4bdc71ed9566..693aa3d6c3e69 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkiOSPlatformContext.h @@ -1,20 +1,16 @@ #pragma once +#import #import +#import #include #include #include -#include -#include - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdocumentation" - -#include "SkStream.h" - -#pragma clang diagnostic pop +#include "DisplayLink.h" +#include "RNSkPlatformContext.h" +#include "ViewScreenshotService.h" #include @@ -34,15 +30,19 @@ static void handleNotification(CFNotificationCenterRef center, void *observer, class RNSkiOSPlatformContext : public RNSkPlatformContext { public: - RNSkiOSPlatformContext(jsi::Runtime *runtime, - std::shared_ptr callInvoker) - : RNSkPlatformContext(runtime, callInvoker, + RNSkiOSPlatformContext(jsi::Runtime *runtime, RCTBridge *bridge) + : RNSkPlatformContext(runtime, bridge.jsCallInvoker, [[UIScreen mainScreen] scale]) { + // We need to make sure we invalidate when modules are freed CFNotificationCenterAddObserver( CFNotificationCenterGetLocalCenter(), this, &handleNotification, (__bridge CFStringRef)RCTBridgeWillInvalidateModulesNotification, NULL, CFNotificationSuspensionBehaviorDeliverImmediately); + + // Create screenshot manager + _screenshotService = + [[ViewScreenshotService alloc] initWithUiManager:bridge.uiManager]; } ~RNSkiOSPlatformContext() { @@ -54,11 +54,16 @@ class RNSkiOSPlatformContext : public RNSkPlatformContext { void startDrawLoop() override; void stopDrawLoop() override; + void runOnMainThread(std::function) override; + + sk_sp takeScreenshotFromViewTag(size_t tag) override; + virtual void performStreamOperation( const std::string &sourceUri, const std::function)> &op) override; void raiseError(const std::exception &err) override; + sk_sp makeOffscreenSurface(int width, int height) override; void willInvalidateModules() { // We need to do some house-cleaning here! @@ -67,6 +72,7 @@ class RNSkiOSPlatformContext : public RNSkPlatformContext { private: DisplayLink *_displayLink; + ViewScreenshotService *_screenshotService; }; static void handleNotification(CFNotificationCenterRef center, void *observer, diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm index 5ba5c9208cec5..fc0df4571d85b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm @@ -4,36 +4,78 @@ #include #include -#include +#include + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdocumentation" + +#include "SkSurface.h" + +#pragma clang diagnostic pop namespace RNSkia { - void RNSkiOSPlatformContext::performStreamOperation(const std::string &sourceUri, - const std::function)> &op) { - - RNSkMeasureTime("PlatformContext::performStreamOperation"); - auto loader = [=]() { - - NSURL* url = [[NSURL alloc] initWithString:[NSString stringWithUTF8String: sourceUri.c_str()]]; - NSData* data = [NSData dataWithContentsOfURL:url]; - - auto bytes = [data bytes]; - auto skData = SkData::MakeWithCopy(bytes, [data length]); - auto stream = SkMemoryStream::Make(skData); - - op(std::move(stream)); - }; - - // Fire and forget the thread - will be resolved on completion - std::thread(loader).detach(); - } +void RNSkiOSPlatformContext::performStreamOperation( + const std::string &sourceUri, + const std::function)> &op) { + + auto loader = [=]() { + NSURL *url = [[NSURL alloc] + initWithString:[NSString stringWithUTF8String:sourceUri.c_str()]]; + + NSData *data = nullptr; + auto scheme = url.scheme; + auto extension = url.pathExtension; + + if (scheme == nullptr && + (extension == nullptr || [extension isEqualToString:@""])) { + // If the extension and scheme is nil, we assume that we're trying to + // load from the embedded iOS app bundle and will try to load image + // and get data from the image directly. imageNamed will return the + // best version of the requested image: + auto image = [UIImage imageNamed:[url absoluteString]]; + // We don't know the image format (png, jpg, etc) but + // UIImagePNGRepresentation will support all of them + data = UIImagePNGRepresentation(image); + } else { + // Load from metro / node + data = [NSData dataWithContentsOfURL:url]; + } + + auto bytes = [data bytes]; + auto skData = SkData::MakeWithCopy(bytes, [data length]); + auto stream = SkMemoryStream::Make(skData); + + op(std::move(stream)); + }; + + // Fire and forget the thread - will be resolved on completion + std::thread(loader).detach(); +} void RNSkiOSPlatformContext::raiseError(const std::exception &err) { - RCTFatal(RCTErrorWithMessage([NSString stringWithUTF8String:err.what()])); + RCTFatal(RCTErrorWithMessage([NSString stringWithUTF8String:err.what()])); +} + +sk_sp RNSkiOSPlatformContext::makeOffscreenSurface(int width, + int height) { + return MakeOffscreenMetalSurface(width, height); +} + +void RNSkiOSPlatformContext::runOnMainThread(std::function func) { + dispatch_async(dispatch_get_main_queue(), ^{ + func(); + }); +} + +sk_sp +RNSkiOSPlatformContext::takeScreenshotFromViewTag(size_t viewTag) { + return [_screenshotService + screenshotOfViewWithTag:[NSNumber numberWithLong:viewTag]]; } void RNSkiOSPlatformContext::startDrawLoop() { - if(_displayLink == nullptr) { + if (_displayLink == nullptr) { _displayLink = [[DisplayLink alloc] init]; [_displayLink start:^(double time) { notifyDrawLoop(false); @@ -42,11 +84,10 @@ } void RNSkiOSPlatformContext::stopDrawLoop() { - if(_displayLink != nullptr) { + if (_displayLink != nullptr) { [_displayLink stop]; _displayLink = nullptr; - } -} - + } } +} // namespace RNSkia diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomViewManager.mm b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomViewManager.mm index 94693c37af3c7..b1d7ae39a9e50 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomViewManager.mm +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDomViewManager.mm @@ -1,51 +1,51 @@ -#include #include +#include -#include #include #include +#include -#include #include +#include #include - - @implementation SkiaDomViewManager RCT_EXPORT_MODULE(SkiaDomView) -- (SkiaManager*) skiaManager { +- (SkiaManager *)skiaManager { auto bridge = [RCTBridge currentBridge]; - auto skiaModule = (RNSkiaModule*)[bridge moduleForName:@"RNSkia"]; + auto skiaModule = (RNSkiaModule *)[bridge moduleForName:@"RNSkia"]; return [skiaModule manager]; } RCT_CUSTOM_VIEW_PROPERTY(nativeID, NSNumber, SkiaUIView) { // Get parameter int nativeId = [[RCTConvert NSString:json] intValue]; - [(SkiaUIView*)view setNativeId:nativeId]; + [(SkiaUIView *)view setNativeId:nativeId]; } RCT_CUSTOM_VIEW_PROPERTY(mode, NSString, SkiaUIView) { - std::string mode = json != NULL ? [[RCTConvert NSString:json] UTF8String] : "default"; - [(SkiaUIView*)view setDrawingMode: mode]; + std::string mode = + json != NULL ? [[RCTConvert NSString:json] UTF8String] : "default"; + [(SkiaUIView *)view setDrawingMode:mode]; } RCT_CUSTOM_VIEW_PROPERTY(debug, BOOL, SkiaUIView) { bool debug = json != NULL ? [RCTConvert BOOL:json] : false; - [(SkiaUIView*)view setDebugMode: debug]; + [(SkiaUIView *)view setDebugMode:debug]; } -- (UIView *)view -{ +- (UIView *)view { auto skManager = [[self skiaManager] skManager]; // Pass SkManager as a raw pointer to avoid circular dependenciesr - return [[SkiaUIView alloc] initWithManager: skManager.get() - factory: [](std::shared_ptr context) { - return std::make_shared>(context); - }]; + return [[SkiaUIView alloc] + initWithManager:skManager.get() + factory:[](std::shared_ptr context) { + return std::make_shared>( + context); + }]; } @end diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDrawViewManager.mm b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDrawViewManager.mm index 532643fbb6762..44bf5b16a7f4b 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDrawViewManager.mm +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaDrawViewManager.mm @@ -1,50 +1,50 @@ #include "SkiaDrawViewManager.h" #include -#include -#include #include +#include +#include #include "SkiaManager.h" -#include #include "SkiaUIView.h" - - +#include @implementation SkiaDrawViewManager RCT_EXPORT_MODULE(SkiaDrawView) -- (SkiaManager*) skiaManager { +- (SkiaManager *)skiaManager { auto bridge = [RCTBridge currentBridge]; - auto skiaModule = (RNSkiaModule*)[bridge moduleForName:@"RNSkia"]; + auto skiaModule = (RNSkiaModule *)[bridge moduleForName:@"RNSkia"]; return [skiaModule manager]; } RCT_CUSTOM_VIEW_PROPERTY(nativeID, NSNumber, SkiaUIView) { // Get parameter int nativeId = [[RCTConvert NSString:json] intValue]; - [(SkiaUIView*)view setNativeId:nativeId]; + [(SkiaUIView *)view setNativeId:nativeId]; } RCT_CUSTOM_VIEW_PROPERTY(mode, NSString, SkiaUIView) { - std::string mode = json != NULL ? [[RCTConvert NSString:json] UTF8String] : "default"; - [(SkiaUIView*)view setDrawingMode: mode]; + std::string mode = + json != NULL ? [[RCTConvert NSString:json] UTF8String] : "default"; + [(SkiaUIView *)view setDrawingMode:mode]; } RCT_CUSTOM_VIEW_PROPERTY(debug, BOOL, SkiaUIView) { bool debug = json != NULL ? [RCTConvert BOOL:json] : false; - [(SkiaUIView*)view setDebugMode: debug]; + [(SkiaUIView *)view setDebugMode:debug]; } -- (UIView *)view -{ +- (UIView *)view { auto skManager = [[self skiaManager] skManager]; // Pass SkManager as a raw pointer to avoid circular dependenciesr - return [[SkiaUIView alloc] initWithManager: skManager.get() - factory: [](std::shared_ptr context) { - return std::make_shared>(context); - }]; + return [[SkiaUIView alloc] + initWithManager:skManager.get() + factory:[](std::shared_ptr context) { + return std::make_shared>( + context); + }]; } @end diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.mm b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.mm index 9c2fb89ac0e3a..8c3d291dc7bcb 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.mm +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaManager.mm @@ -2,8 +2,9 @@ #import -#import #import +#import +#import #import @@ -11,37 +12,33 @@ @implementation SkiaManager { std::shared_ptr _skManager; - std::shared_ptr _platformContext; - __weak RCTBridge* weakBridge; + __weak RCTBridge *weakBridge; } -- (std::shared_ptr) skManager { +- (std::shared_ptr)skManager { return _skManager; } -- (void) invalidate { - if(_skManager != nullptr) { +- (void)invalidate { + if (_skManager != nullptr) { _skManager->invalidate(); } _skManager = nullptr; - _platformContext = nullptr; } -- (instancetype) initWithBridge:(RCTBridge*)bridge { +- (instancetype)initWithBridge:(RCTBridge *)bridge { self = [super init]; if (self) { RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge; if (cxxBridge.runtime) { - auto callInvoker = bridge.jsCallInvoker; - facebook::jsi::Runtime* jsRuntime = (facebook::jsi::Runtime*)cxxBridge.runtime; - - // Create platform context - _platformContext = std::make_shared(jsRuntime, callInvoker); + facebook::jsi::Runtime *jsRuntime = + (facebook::jsi::Runtime *)cxxBridge.runtime; // Create the RNSkiaManager (cross platform) - _skManager = std::make_shared(jsRuntime, callInvoker, _platformContext); - + _skManager = std::make_shared( + jsRuntime, bridge.jsCallInvoker, + std::make_shared(jsRuntime, bridge)); } } return self; diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaMetalRenderer.h b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaMetalRenderer.h new file mode 100644 index 0000000000000..350c585aff5db --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaMetalRenderer.h @@ -0,0 +1,5 @@ +#pragma once + +#include "SkSurface.h" + +sk_sp MakeOffscreenMetalSurface(int width, int height); \ No newline at end of file diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaMetalRenderer.mm b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaMetalRenderer.mm new file mode 100644 index 0000000000000..0cbc4041a3377 --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaMetalRenderer.mm @@ -0,0 +1,53 @@ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdocumentation" + +#import "SkCanvas.h" +#import "SkColorSpace.h" +#import "SkSurface.h" + +#import + +#pragma clang diagnostic pop + +#import + +struct OffscreenRenderContext { + id device; + id commandQueue; + sk_sp skiaContext; + id texture; + + OffscreenRenderContext(int width, int height) { + device = MTLCreateSystemDefaultDevice(); + commandQueue = + id(CFRetain((GrMTLHandle)[device newCommandQueue])); + skiaContext = GrDirectContext::MakeMetal((__bridge void *)device, + (__bridge void *)commandQueue); + // Create a Metal texture descriptor + MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor + texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm + width:width + height:height + mipmapped:NO]; + textureDescriptor.usage = + MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead; + texture = [device newTextureWithDescriptor:textureDescriptor]; + } +}; + +sk_sp MakeOffscreenMetalSurface(int width, int height) { + auto ctx = new OffscreenRenderContext(width, height); + + // Create a GrBackendTexture from the Metal texture + GrMtlTextureInfo info; + info.fTexture.retain((__bridge void *)ctx->texture); + GrBackendTexture backendTexture(width, height, GrMipMapped::kNo, info); + + // Create a SkSurface from the GrBackendTexture + auto surface = SkSurface::MakeFromBackendTexture( + ctx->skiaContext.get(), backendTexture, kTopLeft_GrSurfaceOrigin, 0, + kBGRA_8888_SkColorType, nullptr, nullptr, + [](void *addr) { delete (OffscreenRenderContext *)addr; }, ctx); + + return surface; +} diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureViewManager.mm b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureViewManager.mm index db3e4febf7fcf..6cd26fde20ea2 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureViewManager.mm +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaPictureViewManager.mm @@ -2,50 +2,50 @@ #include "SkiaPictureViewManager.h" #include -#include -#include #include +#include +#include #include "SkiaManager.h" -#include #include "SkiaUIView.h" - - +#include @implementation SkiaPictureViewManager RCT_EXPORT_MODULE(SkiaPictureView) -- (SkiaManager*) skiaManager { +- (SkiaManager *)skiaManager { auto bridge = [RCTBridge currentBridge]; - auto skiaModule = (RNSkiaModule*)[bridge moduleForName:@"RNSkia"]; + auto skiaModule = (RNSkiaModule *)[bridge moduleForName:@"RNSkia"]; return [skiaModule manager]; } RCT_CUSTOM_VIEW_PROPERTY(nativeID, NSNumber, SkiaUIView) { // Get parameter int nativeId = [[RCTConvert NSString:json] intValue]; - [(SkiaUIView*)view setNativeId:nativeId]; + [(SkiaUIView *)view setNativeId:nativeId]; } RCT_CUSTOM_VIEW_PROPERTY(mode, NSString, SkiaUIView) { - std::string mode = json != NULL ? [[RCTConvert NSString:json] UTF8String] : "default"; - [(SkiaUIView*)view setDrawingMode: mode]; + std::string mode = + json != NULL ? [[RCTConvert NSString:json] UTF8String] : "default"; + [(SkiaUIView *)view setDrawingMode:mode]; } RCT_CUSTOM_VIEW_PROPERTY(debug, BOOL, SkiaUIView) { bool debug = json != NULL ? [RCTConvert BOOL:json] : false; - [(SkiaUIView*)view setDebugMode: debug]; + [(SkiaUIView *)view setDebugMode:debug]; } -- (UIView *)view -{ +- (UIView *)view { auto skManager = [[self skiaManager] skManager]; // Pass SkManager as a raw pointer to avoid circular dependenciesr - return [[SkiaUIView alloc] initWithManager: skManager.get() - factory: [](std::shared_ptr context) { - return std::make_shared>(context); - }]; + return [[SkiaUIView alloc] + initWithManager:skManager.get() + factory:[](std::shared_ptr context) { + return std::make_shared>( + context); + }]; } @end diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.mm b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.mm index 054195c3be121..4a7a4745c8dfc 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.mm +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/SkiaUIView.mm @@ -9,19 +9,22 @@ @implementation SkiaUIView { std::shared_ptr _impl; - RNSkia::RNSkManager* _manager; + RNSkia::RNSkManager *_manager; RNSkia::RNSkDrawingMode _drawingMode; - std::function(std::shared_ptr)> _factory; + std::function( + std::shared_ptr)> + _factory; bool _debugMode; size_t _nativeId; } #pragma mark Initialization and destruction -- (instancetype) initWithManager: (RNSkia::RNSkManager*)manager - factory: (std::function( - std::shared_ptr)>)factory -{ +- (instancetype)initWithManager:(RNSkia::RNSkManager *)manager + factory: + (std::function( + std::shared_ptr)>) + factory { self = [super init]; if (self) { _manager = manager; @@ -31,28 +34,29 @@ - (instancetype) initWithManager: (RNSkia::RNSkManager*)manager _factory = factory; // Listen to notifications about module invalidation - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(willInvalidateModules) - name:RCTBridgeWillInvalidateModulesNotification - object:nil]; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(willInvalidateModules) + name:RCTBridgeWillInvalidateModulesNotification + object:nil]; } return self; } -- (void) willInvalidateModules { +- (void)willInvalidateModules { _impl = nullptr; _manager = nullptr; } #pragma mark Lifecycle -- (void) willMoveToSuperview:(UIView *)newWindow { +- (void)willMoveToSuperview:(UIView *)newWindow { if (newWindow == NULL) { // Remove implementation view when the parent view is not set - if(_impl != nullptr) { + if (_impl != nullptr) { [_impl->getLayer() removeFromSuperlayer]; - if(_nativeId != 0 && _manager != nullptr) { + if (_nativeId != 0 && _manager != nullptr) { _manager->setSkiaView(_nativeId, nullptr); } @@ -60,13 +64,14 @@ - (void) willMoveToSuperview:(UIView *)newWindow { } } else { // Create implementation view when the parent view is set - if(_impl == nullptr && _manager != nullptr) { + if (_impl == nullptr && _manager != nullptr) { _impl = _factory(_manager->getPlatformContext()); - if(_impl == nullptr) { - throw std::runtime_error("Expected Skia view implementation, got nullptr."); + if (_impl == nullptr) { + throw std::runtime_error( + "Expected Skia view implementation, got nullptr."); } - [self.layer addSublayer: _impl->getLayer()]; - if(_nativeId != 0) { + [self.layer addSublayer:_impl->getLayer()]; + if (_nativeId != 0) { _manager->setSkiaView(_nativeId, _impl->getDrawView()); } _impl->getDrawView()->setDrawingMode(_drawingMode); @@ -75,71 +80,76 @@ - (void) willMoveToSuperview:(UIView *)newWindow { } } -- (void) dealloc { - if(_manager != nullptr && _nativeId != 0) { +- (void)dealloc { + if (_manager != nullptr && _nativeId != 0) { _manager->unregisterSkiaView(_nativeId); } - [[NSNotificationCenter defaultCenter] removeObserver:self name:RCTBridgeWillInvalidateModulesNotification object:nil]; + [[NSNotificationCenter defaultCenter] + removeObserver:self + name:RCTBridgeWillInvalidateModulesNotification + object:nil]; assert(_impl == nullptr); } #pragma mark Layout -- (void) layoutSubviews { +- (void)layoutSubviews { [super layoutSubviews]; - if(_impl != nullptr) { + if (_impl != nullptr) { _impl->setSize(self.bounds.size.width, self.bounds.size.height); } } #pragma mark Properties --(void) setDrawingMode:(std::string) mode { - _drawingMode = mode.compare("continuous") == 0 ? RNSkia::RNSkDrawingMode::Continuous : RNSkia::RNSkDrawingMode::Default; +- (void)setDrawingMode:(std::string)mode { + _drawingMode = mode.compare("continuous") == 0 + ? RNSkia::RNSkDrawingMode::Continuous + : RNSkia::RNSkDrawingMode::Default; - if(_impl != nullptr) { + if (_impl != nullptr) { _impl->getDrawView()->setDrawingMode(_drawingMode); } } --(void) setDebugMode:(bool) debugMode { +- (void)setDebugMode:(bool)debugMode { _debugMode = debugMode; - if(_impl != nullptr) { + if (_impl != nullptr) { _impl->getDrawView()->setShowDebugOverlays(debugMode); } } -- (void) setNativeId:(size_t) nativeId { +- (void)setNativeId:(size_t)nativeId { _nativeId = nativeId; - if(_impl != nullptr) { + if (_impl != nullptr) { _manager->registerSkiaView(nativeId, _impl->getDrawView()); } } #pragma mark External API -- (std::shared_ptr) impl { +- (std::shared_ptr)impl { return _impl; } #pragma mark Touch handling -- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self handleTouches:touches withEvent:event]; } --(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [self handleTouches:touches withEvent:event]; } --(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self handleTouches:touches withEvent:event]; } -- (void) handleTouches:(NSSet*) touches withEvent:(UIEvent*) event { +- (void)handleTouches:(NSSet *)touches withEvent:(UIEvent *)event { if (event.type == UIEventTypeTouches) { std::vector nextTouches; for (UITouch *touch in touches) { @@ -150,27 +160,27 @@ - (void) handleTouches:(NSSet*) touches withEvent:(UIEvent*) event { nextTouch.force = [touch force]; nextTouch.id = [touch hash]; auto phase = [touch phase]; - switch(phase) { - case UITouchPhaseBegan: - nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Start; - break; - case UITouchPhaseMoved: - nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Active; - break; - case UITouchPhaseEnded: - nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::End; - break; - case UITouchPhaseCancelled: - nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Cancelled; - break; - default: - nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Active; - break; + switch (phase) { + case UITouchPhaseBegan: + nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Start; + break; + case UITouchPhaseMoved: + nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Active; + break; + case UITouchPhaseEnded: + nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::End; + break; + case UITouchPhaseCancelled: + nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Cancelled; + break; + default: + nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Active; + break; } nextTouches.push_back(nextTouch); } - if(_impl != nullptr) { + if (_impl != nullptr) { _impl->getDrawView()->updateTouchState(nextTouches); } } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/ViewScreenshotService.h b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/ViewScreenshotService.h new file mode 100644 index 0000000000000..0bda42b21f14a --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/ViewScreenshotService.h @@ -0,0 +1,21 @@ +#pragma once + +#import +#import + +#import + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdocumentation" + +#include "SkImage.h" + +#pragma clang diagnostic pop + +@interface ViewScreenshotService : NSObject { +} + +- (instancetype)initWithUiManager:(RCTUIManager *)uiManager; +- (sk_sp)screenshotOfViewWithTag:(NSNumber *)viewTag; + +@end diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/ViewScreenshotService.mm b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/ViewScreenshotService.mm new file mode 100644 index 0000000000000..0ff7d742edf4f --- /dev/null +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkia-iOS/ViewScreenshotService.mm @@ -0,0 +1,91 @@ +#import "ViewScreenshotService.h" +#import + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdocumentation" + +#include "SkData.h" + +#pragma clang diagnostic pop + +@implementation ViewScreenshotService { + RCTUIManager *_uiManager; +} + +- (instancetype)initWithUiManager:(RCTUIManager *)uiManager { + if (self = [super init]) { + _uiManager = uiManager; + } + return self; +} + +- (sk_sp)screenshotOfViewWithTag:(NSNumber *)viewTag { + // Find view corresponding to the tag + auto view = [_uiManager viewForReactTag:viewTag]; + if (view == NULL) { + RCTFatal(RCTErrorWithMessage(@"Could not find view with tag")); + } + + // Get size + CGSize size = view.frame.size; + + // Setup context + UIGraphicsImageRendererFormat *format = + [UIGraphicsImageRendererFormat defaultFormat]; + format.opaque = NO; + + // Explicitly ask for the standard format to get ARGB 32bits and not 64bits. + if (@available(iOS 12.0, *)) { + format.preferredRange = UIGraphicsImageRendererFormatRangeStandard; + } else { + // Fallback on earlier versions + format.prefersExtendedRange = false; + } + + UIGraphicsImageRenderer *renderer = + [[UIGraphicsImageRenderer alloc] initWithSize:size format:format]; + + // Render to context - this is now the only part of this function that shows + // up in the profiler! + UIImage *image = [renderer + imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull context) { + [view drawViewHierarchyInRect:(CGRect){CGPointZero, size} + afterScreenUpdates:YES]; + }]; + + // Convert from UIImage -> CGImage -> SkImage + CGImageRef cgImage = image.CGImage; + + // Get some info about the image + auto width = CGImageGetWidth(cgImage); + auto height = CGImageGetHeight(cgImage); + auto bytesPerRow = CGImageGetBytesPerRow(cgImage); + + // Convert from UIImage -> SkImage, start by getting the pixels directly from + // the CGImage: + auto dataRef = CGDataProviderCopyData(CGImageGetDataProvider(cgImage)); + auto length = CFDataGetLength(dataRef); + void *data = CFDataGetMutableBytePtr((CFMutableDataRef)dataRef); + + // Now we'll capture the data in an SkData object and control releasing it: + auto skData = SkData::MakeWithProc( + data, length, + [](const void *ptr, void *context) { + CFDataRef dataRef = (CFDataRef)context; + CFRelease(dataRef); + }, + (void *)dataRef); + + // Make SkImageInfo + // We're using kBGRA_8888_SkColorType since this is what we get when the + // UIGraphicsImageRenderer uses the standard format (the extended is using + // 64bits so it is not suitable for us). + SkImageInfo info = + SkImageInfo::Make(static_cast(width), static_cast(height), + kBGRA_8888_SkColorType, kPremul_SkAlphaType); + + // ... and then create the SkImage itself! + return SkImages::RasterFromData(info, skData, bytesPerRow); +} + +@end diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkiaModule.mm b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkiaModule.mm index aeb33e8a95ea6..84b960d00ec8a 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkiaModule.mm +++ b/ios/vendored/unversioned/@shopify/react-native-skia/ios/RNSkiaModule.mm @@ -3,14 +3,14 @@ #import @implementation RNSkiaModule { - SkiaManager* skiaManager; + SkiaManager *skiaManager; } RCT_EXPORT_MODULE(RNSkia) #pragma Accessors --(SkiaManager*) manager { +- (SkiaManager *)manager { return skiaManager; } @@ -20,21 +20,19 @@ + (BOOL)requiresMainQueueSetup { return YES; } -- (void)invalidate -{ +- (void)invalidate { if (skiaManager != nil) { [skiaManager invalidate]; } skiaManager = nil; } -RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) -{ +RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) { if (skiaManager != nil) { // Already initialized, ignore call. return @true; } - RCTBridge* bridge = [RCTBridge currentBridge]; + RCTBridge *bridge = [RCTBridge currentBridge]; skiaManager = [[SkiaManager alloc] initWithBridge:bridge]; return @true; } diff --git a/ios/vendored/unversioned/@shopify/react-native-skia/react-native-skia.podspec.json b/ios/vendored/unversioned/@shopify/react-native-skia/react-native-skia.podspec.json index ebcbf0afbc672..aa72f68f927a8 100644 --- a/ios/vendored/unversioned/@shopify/react-native-skia/react-native-skia.podspec.json +++ b/ios/vendored/unversioned/@shopify/react-native-skia/react-native-skia.podspec.json @@ -1,6 +1,6 @@ { "name": "react-native-skia", - "version": "0.1.172", + "version": "0.1.193", "summary": "High-performance React Native Graphics using Skia", "description": "@shopify/react-native-skia", "homepage": "https://github.com/shopify/react-native-skia", @@ -13,14 +13,14 @@ }, "source": { "git": "https://github.com/shopify/react-native-skia/react-native-skia.git", - "tag": "0.1.172" + "tag": "0.1.193" }, "requires_arc": true, "pod_target_xcconfig": { - "GCC_PREPROCESSOR_DEFINITIONS": "$(inherited) SK_GL=1 SK_METAL=1", + "GCC_PREPROCESSOR_DEFINITIONS": "$(inherited) SK_METAL=1 SK_GANESH=1", "CLANG_CXX_LANGUAGE_STANDARD": "c++17", "DEFINES_MODULE": "YES", - "HEADER_SEARCH_PATHS": "\"$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers\"" + "HEADER_SEARCH_PATHS": "\"$(PODS_TARGET_SRCROOT)/cpp/\"/** \"$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers\"" }, "frameworks": [ "GLKit", @@ -34,38 +34,12 @@ ] }, "source_files": [ - "ios/**/*.{h,c,cc,cpp,m,mm,swift}" + "ios/**/*.{h,c,cc,cpp,m,mm,swift}", + "cpp/**/*.{h,cpp}" ], "dependencies": { "React": [], "React-callinvoker": [], "React-Core": [] - }, - "subspecs": [ - { - "name": "SkiaHeaders", - "header_mappings_dir": "cpp/skia", - "source_files": "cpp/skia/**/*.{h,cpp}" - }, - { - "name": "Utils", - "header_mappings_dir": "cpp/utils", - "source_files": "cpp/utils/**/*.{h,cpp}" - }, - { - "name": "Jsi", - "header_mappings_dir": "cpp/jsi", - "source_files": "cpp/jsi/**/*.{h,cpp}" - }, - { - "name": "Api", - "header_mappings_dir": "cpp/api", - "source_files": "cpp/api/**/*.{h,cpp}" - }, - { - "name": "RNSkia", - "header_mappings_dir": "cpp/rnskia", - "source_files": "cpp/rnskia/**/*.{h,cpp}" - } - ] + } } diff --git a/packages/expo/bundledNativeModules.json b/packages/expo/bundledNativeModules.json index f69cd5e9077a1..384f817a53501 100644 --- a/packages/expo/bundledNativeModules.json +++ b/packages/expo/bundledNativeModules.json @@ -99,7 +99,7 @@ "sentry-expo": "~6.2.0", "unimodules-app-loader": "~4.1.2", "unimodules-image-loader-interface": "~6.1.0", - "@shopify/react-native-skia": "0.1.172", + "@shopify/react-native-skia": "0.1.193", "@shopify/flash-list": "1.4.3", "@sentry/react-native": "4.15.2" } diff --git a/tools/src/vendoring/config/expoGoConfig.ts b/tools/src/vendoring/config/expoGoConfig.ts index 9489528ab19cb..8e90d63000a30 100644 --- a/tools/src/vendoring/config/expoGoConfig.ts +++ b/tools/src/vendoring/config/expoGoConfig.ts @@ -431,7 +431,7 @@ const config: VendoringTargetConfig = { podspec.pod_target_xcconfig = {}; } podspec.pod_target_xcconfig['HEADER_SEARCH_PATHS'] = - '"$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging" "$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers"'; + '"$(PODS_TARGET_SRCROOT)/cpp/"/** "$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging" "$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers"'; }, }, android: { diff --git a/tools/src/vendoring/config/react-native-skia.patch b/tools/src/vendoring/config/react-native-skia.patch index 4fff3ccd1f33b..7a8d024123dce 100644 --- a/tools/src/vendoring/config/react-native-skia.patch +++ b/tools/src/vendoring/config/react-native-skia.patch @@ -1,14 +1,18 @@ --- android/CMakeLists.txt +++ android/CMakeLists.txt -@@ -47,17 +47,17 @@ +@@ -47,20 +47,20 @@ "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp" "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/SkiaOpenGLRenderer.cpp" - + - "${PROJECT_SOURCE_DIR}/cpp/jsi/JsiHostObject.cpp" - "${PROJECT_SOURCE_DIR}/cpp/jsi/JsiValue.cpp" +- "${PROJECT_SOURCE_DIR}/cpp/jsi/RuntimeLifecycleMonitor.cpp" +- "${PROJECT_SOURCE_DIR}/cpp/jsi/RuntimeAwareCache.cpp" + "${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiHostObject.cpp" + "${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiValue.cpp" - ++ "${PROJECT_SOURCE_DIR}/../cpp/jsi/RuntimeLifecycleMonitor.cpp" ++ "${PROJECT_SOURCE_DIR}/../cpp/jsi/RuntimeAwareCache.cpp" + - "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkManager.cpp" - "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkJsView.cpp" - "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkDomView.cpp" @@ -19,14 +23,16 @@ + "${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkDispatchQueue.cpp" - "${PROJECT_SOURCE_DIR}/cpp/rnskia/dom/base/DrawingContext.cpp" +- "${PROJECT_SOURCE_DIR}/cpp/rnskia/dom/base/ConcatablePaint.cpp" + "${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base/DrawingContext.cpp" ++ "${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base/ConcatablePaint.cpp" - "${PROJECT_SOURCE_DIR}/cpp/api/third_party/CSSColorParser.cpp" + "${PROJECT_SOURCE_DIR}/../cpp/api/third_party/CSSColorParser.cpp" - + ) -@@ -71,33 +71,33 @@ +@@ -74,33 +74,33 @@ "${NODE_MODULES_DIR}/react-native/ReactCommon/react/nativemodule/core" "${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni" @@ -58,7 +64,7 @@ - cpp/rnskia/dom/base - cpp/rnskia/dom/nodes - cpp/rnskia/dom/props -- cpp/utils +- cpp/utils + ${PROJECT_SOURCE_DIR}/../cpp/api + ${PROJECT_SOURCE_DIR}/../cpp/jsi + ${PROJECT_SOURCE_DIR}/cpp/jni/include @@ -69,7 +75,7 @@ + ${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base + ${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/nodes + ${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/props -+ ${PROJECT_SOURCE_DIR}/../cpp/utils ++ ${PROJECT_SOURCE_DIR}/../cpp/utils ${libfbjni_include_DIRS} ) @@ -80,16 +86,9 @@ add_library(skia STATIC IMPORTED) set_property(TARGET skia PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskia.a") -@@ -204,4 +204,4 @@ - -lGLESv2 - -lEGL - -landroid -- ) -\ No newline at end of file -+ ) --- android/build.gradle +++ android/build.gradle -@@ -43,7 +43,7 @@ +@@ -48,7 +48,7 @@ throw new GradleException("React-Native-Skia: Failed to find node_modules/ path!") } @@ -98,8 +97,8 @@ logger.warn("react-native-skia: node_modules/ found at: ${nodeModules}") def sourceBuild = false -@@ -51,9 +51,9 @@ def defaultDir - +@@ -56,9 +56,9 @@ + if (rootProject.ext.has('reactNativeAndroidRoot')) { defaultDir = rootProject.ext.get('reactNativeAndroidRoot') -} else if (findProject(':ReactAndroid') != null) { @@ -110,31 +109,31 @@ } else { defaultDir = file("$nodeModules/react-native") } -@@ -76,6 +76,11 @@ - buildType = "debug" +@@ -222,27 +222,6 @@ + } } -+def reactNativeArchitectures() { -+ def value = project.getProperties().get("reactNativeArchitectures") -+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] -+} -+ - def reactProperties = new Properties() - file("$nodeModules/react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) } - def FULL_RN_VERSION = (System.getenv("REACT_NATIVE_OVERRIDE_VERSION") ?: reactProperties.getProperty("VERSION_NAME")) -@@ -117,7 +122,7 @@ - externalNativeBuild { - cmake { - cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID" -- abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' -+ abiFilters (*reactNativeArchitectures()) - arguments '-DANDROID_STL=c++_shared', - "-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION}", - "-DNODE_MODULES_DIR=${nodeModules}", -@@ -267,4 +272,4 @@ - afterEvaluate { - nativeBuildDependsOn(extractAARHeaders, null) - nativeBuildDependsOn(extractJNIFiles, null) +-afterEvaluate { project -> +- task androidSourcesJar(type: Jar) { +- classifier = 'sources' +- from android.sourceSets.main.java.srcDirs +- include '**/*.java' +- } +- +- android.libraryVariants.all { variant -> +- def name = variant.name.capitalize() +- def javaCompileTask = variant.javaCompileProvider.get() +- +- task "jar${name}"(type: Jar, dependsOn: javaCompileTask) { +- from javaCompileTask.destinationDir +- } +- } +- +- artifacts { +- archives androidSourcesJar +- } -} -\ No newline at end of file -+} +- + task extractAARHeaders { + doLast { + configurations.extractHeaders.files.each { diff --git a/yarn.lock b/yarn.lock index ed1a962d86e13..ef8a29076bc4a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3522,19 +3522,13 @@ recyclerlistview "4.2.0" tslib "2.4.0" -"@shopify/react-native-skia@0.1.172": - version "0.1.172" - resolved "https://registry.yarnpkg.com/@shopify/react-native-skia/-/react-native-skia-0.1.172.tgz#658fb9d90aebaf706d567c331d8bb125175431da" - integrity sha512-XpuertepKP/IlCc7Wq6qT+yfhGxSEekq7y+AfTuIVPTwWGEjF/aCAcwHE65zfLJDhjqswYZEk+O+T3XMA7MrwA== - dependencies: - "@types/pixelmatch" "^5.2.4" - "@types/pngjs" "^6.0.1" - "@types/ws" "^8.5.3" +"@shopify/react-native-skia@0.1.193": + version "0.1.193" + resolved "https://registry.yarnpkg.com/@shopify/react-native-skia/-/react-native-skia-0.1.193.tgz#f03e5ec1afb7a97fb31c391369abeccadb2ada76" + integrity sha512-Y8aM8jFbV4F7HB8prnizA1fS7ILCqsgH/EcxtIlz3JTFMHeUHQb7MuCZL8PaqWPcUCFXwPM3EHWob4ynckpzCQ== + dependencies: canvaskit-wasm "0.38.0" - pixelmatch "^5.3.0" - pngjs "^6.0.0" react-reconciler "^0.27.0" - ws "^8.11.0" "@sideway/address@^4.1.3": version "4.1.4" @@ -4246,25 +4240,11 @@ resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA== -"@types/pixelmatch@^5.2.4": - version "5.2.4" - resolved "https://registry.yarnpkg.com/@types/pixelmatch/-/pixelmatch-5.2.4.tgz#ca145cc5ede1388c71c68edf2d1f5190e5ddd0f6" - integrity sha512-HDaSHIAv9kwpMN7zlmwfTv6gax0PiporJOipcrGsVNF3Ba+kryOZc0Pio5pn6NhisgWr7TaajlPEKTbTAypIBQ== - dependencies: - "@types/node" "*" - "@types/pixi.js@^4.8.6": version "4.8.9" resolved "https://registry.yarnpkg.com/@types/pixi.js/-/pixi.js-4.8.9.tgz#207d8719f655d84eaa28adcfb3c62e414450dc56" integrity sha512-PCqd9/TaGOAqg73u8cQKH2sg8pdkRzU6VKu8lWrV+/+p5QiDRtrT8chY5yveVM8A/hWLNtvIQlWpojDomTSNQQ== -"@types/pngjs@^6.0.1": - version "6.0.1" - resolved "https://registry.yarnpkg.com/@types/pngjs/-/pngjs-6.0.1.tgz#c711ec3fbbf077fed274ecccaf85dd4673130072" - integrity sha512-J39njbdW1U/6YyVXvC9+1iflZghP8jgRf2ndYghdJb5xL49LYDB+1EuAxfbuJ2IBbWIL3AjHPQhgaTxT3YaYeg== - dependencies: - "@types/node" "*" - "@types/prettier@^2.1.5": version "2.4.4" resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.4.4.tgz#5d9b63132df54d8909fce1c3f8ca260fdd693e17" @@ -4542,7 +4522,7 @@ resolved "https://registry.yarnpkg.com/@types/wrap-ansi/-/wrap-ansi-8.0.1.tgz#59dc91b83a2e949971da8617592d9eaaf6592774" integrity sha512-cjwgM6WWy9YakrQ36Pq0vg5XoNblVEaNq+/pHngKl4GyyDIxTeskPoG+tp4LsRk0lHrA4LaLJqlvYridi7mzlw== -"@types/ws@^8.0.0", "@types/ws@^8.5.3", "@types/ws@^8.5.4": +"@types/ws@^8.0.0", "@types/ws@^8.5.4": version "8.5.4" resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.4.tgz#bb10e36116d6e570dd943735f86c933c1587b8a5" integrity sha512-zdQDHKUgcX/zBc4GrwsE/7dVdAD8JR4EuiAXiiUhhfyIJXXb2+PrGshFyeXWQPMmmZ2XxgaqclgpIC7eTXc1mg== @@ -14819,13 +14799,6 @@ pirates@^4.0.1, pirates@^4.0.4, pirates@^4.0.5: resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.5.tgz#feec352ea5c3268fb23a37c702ab1699f35a5f3b" integrity sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ== -pixelmatch@^5.3.0: - version "5.3.0" - resolved "https://registry.yarnpkg.com/pixelmatch/-/pixelmatch-5.3.0.tgz#5e5321a7abedfb7962d60dbf345deda87cb9560a" - integrity sha512-o8mkY4E/+LNUf6LzX96ht6k6CEDi65k9G2rjMtBe9Oo+VPKSvl+0GKHuH/AlG+GA5LPG/i5hrekkxUc3s2HU+Q== - dependencies: - pngjs "^6.0.0" - pixi-gl-core@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/pixi-gl-core/-/pixi-gl-core-1.1.4.tgz#8b4b5c433b31e419bc379dc565ce1b835a91b372" @@ -14884,11 +14857,6 @@ pngjs@^5.0.0: resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-5.0.0.tgz#e79dd2b215767fd9c04561c01236df960bce7fbb" integrity sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw== -pngjs@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-6.0.0.tgz#ca9e5d2aa48db0228a52c419c3308e87720da821" - integrity sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg== - pnp-webpack-plugin@^1.5.0: version "1.7.0" resolved "https://registry.yarnpkg.com/pnp-webpack-plugin/-/pnp-webpack-plugin-1.7.0.tgz#65741384f6d8056f36e2255a8d67ffc20866f5c9"