@shopify/react-native-skia 0.1.192 → 0.1.193
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +1 -1
- package/android/build.gradle +1 -0
- package/android/cpp/jni/JniPlatformContext.cpp +1 -1
- package/cpp/api/JsiSkImage.h +25 -4
- package/cpp/api/JsiSkImageFactory.h +2 -2
- package/cpp/api/JsiSkPath.h +8 -6
- package/cpp/rnskia/dom/base/Declaration.h +5 -7
- package/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +1 -0
- package/cpp/rnskia/dom/nodes/JsiPathNode.h +2 -2
- package/cpp/rnskia/dom/props/BoxShadowProps.h +2 -0
- package/cpp/skia/include/android/SkAndroidFrameworkUtils.h +2 -8
- package/cpp/skia/include/android/SkImageAndroid.h +101 -0
- package/cpp/skia/include/codec/SkAndroidCodec.h +26 -8
- package/cpp/skia/include/codec/SkCodec.h +31 -17
- package/cpp/skia/include/codec/SkEncodedImageFormat.h +36 -0
- package/cpp/skia/include/codec/SkPixmapUtils.h +31 -0
- package/cpp/skia/include/config/SkUserConfig.h +61 -29
- package/cpp/skia/include/core/SkBitmap.h +25 -25
- package/cpp/skia/include/core/SkBlurTypes.h +0 -2
- package/cpp/skia/include/core/SkCanvas.h +32 -15
- package/cpp/skia/include/core/SkCapabilities.h +2 -2
- package/cpp/skia/include/core/SkColor.h +2 -0
- package/cpp/skia/include/core/SkColorPriv.h +19 -4
- package/cpp/skia/include/core/SkColorSpace.h +14 -17
- package/cpp/skia/include/core/SkColorType.h +1 -0
- package/cpp/skia/include/core/SkContourMeasure.h +1 -1
- package/cpp/skia/include/core/SkCoverageMode.h +0 -2
- package/cpp/skia/include/core/SkCubicMap.h +2 -0
- package/cpp/skia/include/core/SkData.h +5 -2
- package/cpp/skia/include/core/SkDataTable.h +6 -2
- package/cpp/skia/include/core/SkDeferredDisplayList.h +11 -10
- package/cpp/skia/include/core/SkDeferredDisplayListRecorder.h +9 -8
- package/cpp/skia/include/core/SkDrawable.h +10 -2
- package/cpp/skia/include/core/SkEncodedImageFormat.h +3 -30
- package/cpp/skia/include/core/SkFlattenable.h +4 -2
- package/cpp/skia/include/core/SkFont.h +1 -0
- package/cpp/skia/include/core/SkFontMetrics.h +1 -0
- package/cpp/skia/include/core/SkFontMgr.h +20 -29
- package/cpp/skia/include/core/SkFontStyle.h +4 -1
- package/cpp/skia/include/core/SkGraphics.h +21 -18
- package/cpp/skia/include/core/SkICC.h +3 -13
- package/cpp/skia/include/core/SkImage.h +395 -717
- package/cpp/skia/include/core/SkImageGenerator.h +19 -74
- package/cpp/skia/include/core/SkImageInfo.h +7 -5
- package/cpp/skia/include/core/SkM44.h +11 -0
- package/cpp/skia/include/core/SkMaskFilter.h +6 -3
- package/cpp/skia/include/core/SkMatrix.h +14 -4
- package/cpp/skia/include/core/SkMesh.h +52 -18
- package/cpp/skia/include/core/SkMilestone.h +1 -1
- package/cpp/skia/include/core/SkPaint.h +11 -34
- package/cpp/skia/include/core/SkPath.h +23 -4
- package/cpp/skia/include/core/SkPathBuilder.h +13 -5
- package/cpp/skia/include/core/SkPathMeasure.h +1 -1
- package/cpp/skia/include/core/SkPathTypes.h +0 -2
- package/cpp/skia/include/core/SkPathUtils.h +42 -0
- package/cpp/skia/include/core/SkPicture.h +3 -2
- package/cpp/skia/include/core/SkPictureRecorder.h +2 -0
- package/cpp/skia/include/core/SkPixelRef.h +4 -8
- package/cpp/skia/include/core/SkPixmap.h +12 -20
- package/cpp/skia/include/core/SkPoint.h +4 -2
- package/cpp/skia/include/core/SkPromiseImageTexture.h +2 -2
- package/cpp/skia/include/core/SkRRect.h +5 -1
- package/cpp/skia/include/core/SkRect.h +6 -3
- package/cpp/skia/include/core/SkRefCnt.h +9 -14
- package/cpp/skia/include/core/SkRegion.h +1 -1
- package/cpp/skia/include/core/SkScalar.h +2 -4
- package/cpp/skia/include/core/SkSerialProcs.h +18 -10
- package/cpp/skia/include/core/SkShader.h +1 -64
- package/cpp/skia/include/core/SkSize.h +2 -0
- package/cpp/skia/include/core/SkSpan.h +4 -112
- package/cpp/skia/include/core/SkStream.h +11 -12
- package/cpp/skia/include/core/SkString.h +9 -25
- package/cpp/skia/include/core/SkStrokeRec.h +1 -1
- package/cpp/skia/include/core/SkSurface.h +83 -61
- package/cpp/skia/include/core/SkSurfaceCharacterization.h +3 -3
- package/cpp/skia/include/core/SkSurfaceProps.h +9 -1
- package/cpp/skia/include/core/SkTextBlob.h +2 -2
- package/cpp/skia/include/core/SkTextureCompressionType.h +30 -0
- package/cpp/skia/include/core/SkTime.h +1 -1
- package/cpp/skia/include/core/SkTypeface.h +9 -2
- package/cpp/skia/include/core/SkTypes.h +37 -466
- package/cpp/skia/include/core/SkVertices.h +2 -0
- package/cpp/skia/include/core/SkYUVAInfo.h +4 -0
- package/cpp/skia/include/core/SkYUVAPixmaps.h +7 -1
- package/cpp/skia/include/docs/SkPDFDocument.h +12 -1
- package/cpp/skia/include/effects/SkColorMatrix.h +2 -1
- package/cpp/skia/include/effects/SkGradientShader.h +65 -14
- package/cpp/skia/include/effects/SkImageFilters.h +0 -11
- package/cpp/skia/include/effects/SkRuntimeEffect.h +41 -11
- package/cpp/skia/include/encode/SkEncoder.h +7 -3
- package/cpp/skia/include/encode/SkICC.h +36 -0
- package/cpp/skia/include/encode/SkJpegEncoder.h +102 -71
- package/cpp/skia/include/encode/SkPngEncoder.h +89 -71
- package/cpp/skia/include/encode/SkWebpEncoder.h +65 -38
- package/cpp/skia/include/gpu/GpuTypes.h +23 -1
- package/cpp/skia/include/gpu/GrBackendSurface.h +9 -7
- package/cpp/skia/include/gpu/GrContextOptions.h +28 -9
- package/cpp/skia/include/gpu/GrContextThreadSafeProxy.h +6 -4
- package/cpp/skia/include/gpu/GrDirectContext.h +84 -63
- package/cpp/skia/include/gpu/GrDriverBugWorkarounds.h +2 -1
- package/cpp/skia/include/gpu/GrRecordingContext.h +9 -5
- package/cpp/skia/include/gpu/GrTypes.h +18 -18
- package/cpp/skia/include/gpu/d3d/GrD3DTypes.h +4 -4
- package/cpp/skia/include/gpu/dawn/GrDawnTypes.h +3 -3
- package/cpp/skia/include/gpu/ganesh/GrTextureGenerator.h +77 -0
- package/cpp/skia/include/gpu/ganesh/SkImageGanesh.h +385 -0
- package/cpp/skia/include/gpu/gl/GrGLExtensions.h +3 -3
- package/cpp/skia/include/gpu/gl/GrGLFunctions.h +1 -1
- package/cpp/skia/include/gpu/gl/GrGLInterface.h +0 -3
- package/cpp/skia/include/gpu/gl/GrGLTypes.h +2 -1
- package/cpp/skia/include/gpu/graphite/BackendTexture.h +72 -3
- package/cpp/skia/include/gpu/graphite/Context.h +85 -32
- package/cpp/skia/include/gpu/graphite/ContextOptions.h +15 -11
- package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +55 -5
- package/cpp/skia/include/gpu/graphite/ImageProvider.h +6 -4
- package/cpp/skia/include/gpu/graphite/Recorder.h +41 -11
- package/cpp/skia/include/gpu/graphite/Recording.h +50 -3
- package/cpp/skia/include/gpu/graphite/TextureInfo.h +47 -8
- package/cpp/skia/include/gpu/graphite/YUVABackendTextures.h +139 -0
- package/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h +40 -0
- package/cpp/skia/include/gpu/graphite/dawn/DawnUtils.h +28 -0
- package/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h +1 -1
- package/cpp/skia/include/gpu/graphite/mtl/{MtlTypes.h → MtlGraphiteTypes.h} +7 -6
- package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteUtils.h +27 -0
- package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +4 -9
- package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteUtils.h +28 -0
- package/cpp/skia/include/gpu/mock/GrMockTypes.h +17 -13
- package/cpp/skia/include/gpu/mtl/GrMtlTypes.h +2 -2
- package/cpp/skia/include/gpu/vk/GrVkBackendContext.h +1 -1
- package/cpp/skia/include/gpu/vk/GrVkTypes.h +3 -3
- package/cpp/skia/include/gpu/vk/VulkanExtensions.h +3 -3
- package/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h +5 -7
- package/cpp/skia/include/pathops/SkPathOps.h +3 -3
- package/cpp/skia/include/ports/SkFontMgr_data.h +22 -0
- package/cpp/skia/include/ports/SkFontMgr_indirect.h +14 -14
- package/cpp/skia/include/ports/SkRemotableFontMgr.h +2 -2
- package/cpp/skia/include/ports/SkTypeface_win.h +2 -1
- package/cpp/skia/include/private/SkChecksum.h +32 -7
- package/cpp/skia/include/private/SkColorData.h +1 -26
- package/cpp/skia/include/private/SkGainmapInfo.h +97 -0
- package/cpp/skia/include/private/SkGainmapShader.h +53 -0
- package/cpp/skia/include/private/SkIDChangeListener.h +4 -3
- package/cpp/skia/include/private/SkJpegGainmapEncoder.h +71 -0
- package/cpp/skia/include/private/SkJpegMetadataDecoder.h +61 -0
- package/cpp/skia/include/private/SkOpts_spi.h +3 -1
- package/cpp/skia/include/private/SkPathRef.h +64 -47
- package/cpp/skia/include/private/SkSLDefines.h +5 -5
- package/cpp/skia/include/private/SkSLSampleUsage.h +0 -4
- package/cpp/skia/include/private/SkSpinlock.h +1 -1
- package/cpp/skia/include/private/SkWeakRefCnt.h +3 -0
- package/cpp/skia/include/private/{SingleOwner.h → base/SingleOwner.h} +8 -5
- package/cpp/skia/include/private/base/SkAPI.h +52 -0
- package/cpp/skia/include/private/base/SkAlign.h +39 -0
- package/cpp/skia/include/private/base/SkAlignedStorage.h +32 -0
- package/cpp/skia/include/private/base/SkAssert.h +92 -0
- package/cpp/skia/include/private/base/SkAttributes.h +102 -0
- package/cpp/skia/include/private/base/SkCPUTypes.h +25 -0
- package/cpp/skia/include/private/base/SkContainers.h +46 -0
- package/cpp/skia/include/private/base/SkDebug.h +27 -0
- package/cpp/skia/include/private/{SkDeque.h → base/SkDeque.h} +3 -1
- package/cpp/skia/include/private/base/SkFeatures.h +151 -0
- package/cpp/skia/include/private/{SkFixed.h → base/SkFixed.h} +9 -7
- package/cpp/skia/include/private/{SkFloatBits.h → base/SkFloatBits.h} +2 -3
- package/cpp/skia/include/private/{SkFloatingPoint.h → base/SkFloatingPoint.h} +18 -9
- package/cpp/skia/include/private/base/SkLoadUserConfig.h +63 -0
- package/cpp/skia/include/private/{SkMacros.h → base/SkMacros.h} +17 -2
- package/cpp/skia/include/private/{SkMalloc.h → base/SkMalloc.h} +4 -7
- package/cpp/skia/include/{core → private/base}/SkMath.h +25 -2
- package/cpp/skia/include/private/{SkMutex.h → base/SkMutex.h} +5 -5
- package/cpp/skia/include/private/{SkNoncopyable.h → base/SkNoncopyable.h} +2 -2
- package/cpp/skia/include/private/{SkOnce.h → base/SkOnce.h} +3 -1
- package/cpp/skia/include/private/base/SkPathEnums.h +25 -0
- package/cpp/skia/include/private/{SkSafe32.h → base/SkSafe32.h} +16 -1
- package/cpp/skia/include/private/{SkSemaphore.h → base/SkSemaphore.h} +4 -3
- package/cpp/skia/include/private/base/SkSpan_impl.h +129 -0
- package/cpp/skia/include/private/base/SkTArray.h +694 -0
- package/cpp/skia/include/private/{SkTDArray.h → base/SkTDArray.h} +17 -54
- package/cpp/skia/include/private/{SkTFitsIn.h → base/SkTFitsIn.h} +14 -8
- package/cpp/skia/include/private/{SkTLogic.h → base/SkTLogic.h} +1 -1
- package/cpp/skia/include/private/{SkTemplates.h → base/SkTemplates.h} +63 -88
- package/cpp/skia/include/private/{SkThreadID.h → base/SkThreadID.h} +5 -2
- package/cpp/skia/include/private/{SkTo.h → base/SkTo.h} +13 -2
- package/cpp/skia/include/private/base/SkTypeTraits.h +33 -0
- package/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h +130 -0
- package/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h +5 -9
- package/cpp/skia/include/private/chromium/SkDiscardableMemory.h +70 -0
- package/cpp/skia/include/private/chromium/Slug.h +0 -9
- package/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +2 -1
- package/cpp/skia/include/private/gpu/ganesh/GrD3DTypesMinimal.h +1 -1
- package/cpp/skia/include/private/gpu/ganesh/GrDawnTypesPriv.h +1 -1
- package/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h +1 -1
- package/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +1 -1
- package/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h +3 -2
- package/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h +1 -1
- package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +17 -23
- package/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h +2 -2
- package/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h +38 -0
- package/cpp/skia/include/private/gpu/graphite/{MtlTypesPriv.h → MtlGraphiteTypesPriv.h} +5 -5
- package/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h +1 -9
- package/cpp/skia/include/private/gpu/vk/SkiaVulkan.h +4 -0
- package/cpp/skia/include/utils/SkCamera.h +1 -1
- package/cpp/skia/include/utils/SkCustomTypeface.h +7 -1
- package/cpp/skia/include/utils/SkNWayCanvas.h +6 -6
- package/cpp/skia/include/utils/SkOrderedFontMgr.h +7 -6
- package/cpp/skia/include/utils/SkPaintFilterCanvas.h +2 -2
- package/cpp/skia/include/utils/SkParsePath.h +1 -1
- package/cpp/skia/modules/skcms/skcms.h +14 -0
- package/cpp/skia/modules/skcms/src/Transform_inl.h +19 -0
- package/cpp/skia/modules/skparagraph/include/FontCollection.h +2 -2
- package/cpp/skia/modules/skparagraph/include/Paragraph.h +72 -2
- package/cpp/skia/modules/skparagraph/include/ParagraphCache.h +1 -11
- package/cpp/skia/modules/skparagraph/include/ParagraphPainter.h +63 -0
- package/cpp/skia/modules/skparagraph/include/TextStyle.h +27 -4
- package/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +13 -13
- package/cpp/skia/modules/skresources/include/SkResources.h +18 -4
- package/cpp/skia/modules/svg/include/SkSVGAttribute.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGAttributeParser.h +2 -2
- package/cpp/skia/modules/svg/include/SkSVGContainer.h +2 -2
- package/cpp/skia/modules/svg/include/SkSVGDOM.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFilterContext.h +2 -2
- package/cpp/skia/modules/svg/include/SkSVGGradient.h +2 -2
- package/cpp/skia/modules/svg/include/SkSVGIDMapper.h +2 -2
- package/cpp/skia/modules/svg/include/SkSVGRenderContext.h +3 -3
- package/cpp/skia/modules/svg/include/SkSVGSVG.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGTypes.h +22 -21
- package/cpp/skia/modules/svg/include/SkSVGValue.h +1 -1
- package/cpp/skia/{include/private → src/core}/SkTHash.h +41 -37
- package/ios/RNSkia-iOS/ViewScreenshotService.mm +1 -1
- package/libs/android/arm64-v8a/libskia.a +0 -0
- package/libs/android/arm64-v8a/libskottie.a +0 -0
- package/libs/android/arm64-v8a/libsksg.a +0 -0
- package/libs/android/arm64-v8a/libskshaper.a +0 -0
- package/libs/android/arm64-v8a/libsvg.a +0 -0
- package/libs/android/armeabi-v7a/libskia.a +0 -0
- package/libs/android/armeabi-v7a/libskottie.a +0 -0
- package/libs/android/armeabi-v7a/libsksg.a +0 -0
- package/libs/android/armeabi-v7a/libskshaper.a +0 -0
- package/libs/android/armeabi-v7a/libsvg.a +0 -0
- package/libs/android/x86/libskia.a +0 -0
- package/libs/android/x86/libskottie.a +0 -0
- package/libs/android/x86/libsksg.a +0 -0
- package/libs/android/x86/libskshaper.a +0 -0
- package/libs/android/x86/libsvg.a +0 -0
- package/libs/android/x86_64/libskia.a +0 -0
- package/libs/android/x86_64/libskottie.a +0 -0
- package/libs/android/x86_64/libsksg.a +0 -0
- package/libs/android/x86_64/libskshaper.a +0 -0
- package/libs/android/x86_64/libsvg.a +0 -0
- package/libs/ios/libskia.xcframework/Info.plist +5 -5
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +1 -1
- package/react-native-skia.podspec +1 -1
- package/scripts/install-npm.js +11 -1
- package/cpp/skia/include/core/SkImageEncoder.h +0 -71
- package/cpp/skia/include/gpu/GrConfig.h +0 -53
- package/cpp/skia/include/gpu/graphite/CombinationBuilder.h +0 -195
- package/cpp/skia/include/private/SkHalf.h +0 -38
- package/cpp/skia/include/private/SkImageInfoPriv.h +0 -199
- package/cpp/skia/include/private/SkSLIRNode.h +0 -64
- package/cpp/skia/include/private/SkSLLayout.h +0 -144
- package/cpp/skia/include/private/SkSLModifiers.h +0 -178
- package/cpp/skia/include/private/SkSLProgramElement.h +0 -77
- package/cpp/skia/include/private/SkSLProgramKind.h +0 -35
- package/cpp/skia/include/private/SkSLStatement.h +0 -86
- package/cpp/skia/include/private/SkSLString.h +0 -41
- package/cpp/skia/include/private/SkSLSymbol.h +0 -94
- package/cpp/skia/include/private/SkSafe_math.h +0 -52
- package/cpp/skia/include/private/SkStringView.h +0 -51
- package/cpp/skia/include/private/SkTArray.h +0 -655
- package/cpp/skia/include/private/SkUniquePaintParamsID.h +0 -35
- package/cpp/skia/include/private/SkVx.h +0 -1026
- package/cpp/skia/include/sksl/DSL.h +0 -37
- package/cpp/skia/include/sksl/DSLBlock.h +0 -58
- package/cpp/skia/include/sksl/DSLCase.h +0 -62
- package/cpp/skia/include/sksl/DSLCore.h +0 -492
- package/cpp/skia/include/sksl/DSLExpression.h +0 -241
- package/cpp/skia/include/sksl/DSLFunction.h +0 -113
- package/cpp/skia/include/sksl/DSLLayout.h +0 -92
- package/cpp/skia/include/sksl/DSLModifiers.h +0 -69
- package/cpp/skia/include/sksl/DSLStatement.h +0 -82
- package/cpp/skia/include/sksl/DSLSymbols.h +0 -61
- package/cpp/skia/include/sksl/DSLType.h +0 -271
- package/cpp/skia/include/sksl/DSLVar.h +0 -231
- package/cpp/skia/include/sksl/SkSLErrorReporter.h +0 -65
- package/cpp/skia/include/sksl/SkSLOperator.h +0 -154
- package/cpp/skia/include/sksl/SkSLPosition.h +0 -104
- package/cpp/skia/include/utils/SkRandom.h +0 -169
- package/cpp/skia/src/core/SkLRUCache.h +0 -126
- package/cpp/skia/src/core/SkTInternalLList.h +0 -302
- /package/cpp/skia/include/{core → codec}/SkPngChunkReader.h +0 -0
- /package/cpp/skia/include/private/{SkTPin.h → base/SkTPin.h} +0 -0
- /package/cpp/skia/include/private/{SkThreadAnnotations.h → base/SkThreadAnnotations.h} +0 -0
@@ -0,0 +1,694 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2011 Google Inc.
|
3
|
+
*
|
4
|
+
* Use of this source code is governed by a BSD-style license that can be
|
5
|
+
* found in the LICENSE file.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#ifndef SkTArray_DEFINED
|
9
|
+
#define SkTArray_DEFINED
|
10
|
+
|
11
|
+
#include "include/private/base/SkAlignedStorage.h"
|
12
|
+
#include "include/private/base/SkAssert.h"
|
13
|
+
#include "include/private/base/SkAttributes.h"
|
14
|
+
#include "include/private/base/SkContainers.h"
|
15
|
+
#include "include/private/base/SkMalloc.h"
|
16
|
+
#include "include/private/base/SkMath.h"
|
17
|
+
#include "include/private/base/SkSpan_impl.h"
|
18
|
+
#include "include/private/base/SkTo.h"
|
19
|
+
#include "include/private/base/SkTypeTraits.h" // IWYU pragma: keep
|
20
|
+
|
21
|
+
#include <algorithm>
|
22
|
+
#include <climits>
|
23
|
+
#include <cstddef>
|
24
|
+
#include <cstdint>
|
25
|
+
#include <cstring>
|
26
|
+
#include <initializer_list>
|
27
|
+
#include <new>
|
28
|
+
#include <utility>
|
29
|
+
|
30
|
+
namespace skia_private {
|
31
|
+
/** TArray<T> implements a typical, mostly std::vector-like array.
|
32
|
+
Each T will be default-initialized on allocation, and ~T will be called on destruction.
|
33
|
+
|
34
|
+
MEM_MOVE controls the behavior when a T needs to be moved (e.g. when the array is resized)
|
35
|
+
- true: T will be bit-copied via memcpy.
|
36
|
+
- false: T will be moved via move-constructors.
|
37
|
+
*/
|
38
|
+
template <typename T, bool MEM_MOVE = sk_is_trivially_relocatable_v<T>> class TArray {
|
39
|
+
public:
|
40
|
+
using value_type = T;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Creates an empty array with no initial storage
|
44
|
+
*/
|
45
|
+
TArray() : fOwnMemory(true), fCapacity{0} {}
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Creates an empty array that will preallocate space for reserveCount
|
49
|
+
* elements.
|
50
|
+
*/
|
51
|
+
explicit TArray(int reserveCount) : TArray() { this->reserve_back(reserveCount); }
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Copies one array to another. The new array will be heap allocated.
|
55
|
+
*/
|
56
|
+
TArray(const TArray& that) : TArray(that.fData, that.fSize) {}
|
57
|
+
|
58
|
+
TArray(TArray&& that) {
|
59
|
+
if (that.fOwnMemory) {
|
60
|
+
this->setData(that);
|
61
|
+
that.setData({});
|
62
|
+
} else {
|
63
|
+
this->initData(that.fSize);
|
64
|
+
that.move(fData);
|
65
|
+
}
|
66
|
+
fSize = std::exchange(that.fSize, 0);
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Creates a TArray by copying contents of a standard C array. The new
|
71
|
+
* array will be heap allocated. Be careful not to use this constructor
|
72
|
+
* when you really want the (void*, int) version.
|
73
|
+
*/
|
74
|
+
TArray(const T* array, int count) {
|
75
|
+
this->initData(count);
|
76
|
+
this->copy(array);
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Creates a TArray by copying contents of an initializer list.
|
81
|
+
*/
|
82
|
+
TArray(std::initializer_list<T> data) : TArray(data.begin(), data.size()) {}
|
83
|
+
|
84
|
+
TArray& operator=(const TArray& that) {
|
85
|
+
if (this == &that) {
|
86
|
+
return *this;
|
87
|
+
}
|
88
|
+
this->clear();
|
89
|
+
this->checkRealloc(that.size(), kExactFit);
|
90
|
+
fSize = that.fSize;
|
91
|
+
this->copy(that.fData);
|
92
|
+
return *this;
|
93
|
+
}
|
94
|
+
TArray& operator=(TArray&& that) {
|
95
|
+
if (this != &that) {
|
96
|
+
this->clear();
|
97
|
+
if (that.fOwnMemory) {
|
98
|
+
// The storage is on the heap, so move the data pointer.
|
99
|
+
if (fOwnMemory) {
|
100
|
+
sk_free(fData);
|
101
|
+
}
|
102
|
+
|
103
|
+
fData = std::exchange(that.fData, nullptr);
|
104
|
+
|
105
|
+
// Can't use exchange with bitfields.
|
106
|
+
fCapacity = that.fCapacity;
|
107
|
+
that.fCapacity = 0;
|
108
|
+
|
109
|
+
fOwnMemory = true;
|
110
|
+
} else {
|
111
|
+
// The data is stored inline in that, so move it element-by-element.
|
112
|
+
this->checkRealloc(that.size(), kExactFit);
|
113
|
+
that.move(fData);
|
114
|
+
}
|
115
|
+
fSize = std::exchange(that.fSize, 0);
|
116
|
+
}
|
117
|
+
return *this;
|
118
|
+
}
|
119
|
+
|
120
|
+
~TArray() {
|
121
|
+
this->destroyAll();
|
122
|
+
if (fOwnMemory) {
|
123
|
+
sk_free(fData);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Resets to size() = n newly constructed T objects and resets any reserve count.
|
129
|
+
*/
|
130
|
+
void reset(int n) {
|
131
|
+
SkASSERT(n >= 0);
|
132
|
+
this->clear();
|
133
|
+
this->checkRealloc(n, kExactFit);
|
134
|
+
fSize = n;
|
135
|
+
for (int i = 0; i < this->size(); ++i) {
|
136
|
+
new (fData + i) T;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Resets to a copy of a C array and resets any reserve count.
|
142
|
+
*/
|
143
|
+
void reset(const T* array, int count) {
|
144
|
+
SkASSERT(count >= 0);
|
145
|
+
this->clear();
|
146
|
+
this->checkRealloc(count, kExactFit);
|
147
|
+
fSize = count;
|
148
|
+
this->copy(array);
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* Ensures there is enough reserved space for n elements.
|
153
|
+
*/
|
154
|
+
void reserve(int n) {
|
155
|
+
SkASSERT(n >= 0);
|
156
|
+
if (n > this->size()) {
|
157
|
+
this->checkRealloc(n - this->size(), kGrowing);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
/**
|
162
|
+
* Ensures there is enough reserved space for n additional elements. The is guaranteed at least
|
163
|
+
* until the array size grows above n and subsequently shrinks below n, any version of reset()
|
164
|
+
* is called, or reserve_back() is called again.
|
165
|
+
*/
|
166
|
+
void reserve_back(int n) {
|
167
|
+
SkASSERT(n >= 0);
|
168
|
+
if (n > 0) {
|
169
|
+
this->checkRealloc(n, kExactFit);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
void removeShuffle(int n) {
|
174
|
+
SkASSERT(n < this->size());
|
175
|
+
int newCount = fSize - 1;
|
176
|
+
fSize = newCount;
|
177
|
+
fData[n].~T();
|
178
|
+
if (n != newCount) {
|
179
|
+
this->move(n, newCount);
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
// Is the array empty.
|
184
|
+
bool empty() const { return fSize == 0; }
|
185
|
+
|
186
|
+
/**
|
187
|
+
* Adds 1 new default-initialized T value and returns it by reference. Note
|
188
|
+
* the reference only remains valid until the next call that adds or removes
|
189
|
+
* elements.
|
190
|
+
*/
|
191
|
+
T& push_back() {
|
192
|
+
void* newT = this->push_back_raw(1);
|
193
|
+
return *new (newT) T;
|
194
|
+
}
|
195
|
+
|
196
|
+
/**
|
197
|
+
* Version of above that uses a copy constructor to initialize the new item
|
198
|
+
*/
|
199
|
+
T& push_back(const T& t) {
|
200
|
+
void* newT = this->push_back_raw(1);
|
201
|
+
return *new (newT) T(t);
|
202
|
+
}
|
203
|
+
|
204
|
+
/**
|
205
|
+
* Version of above that uses a move constructor to initialize the new item
|
206
|
+
*/
|
207
|
+
T& push_back(T&& t) {
|
208
|
+
void* newT = this->push_back_raw(1);
|
209
|
+
return *new (newT) T(std::move(t));
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Construct a new T at the back of this array.
|
214
|
+
*/
|
215
|
+
template<class... Args> T& emplace_back(Args&&... args) {
|
216
|
+
void* newT = this->push_back_raw(1);
|
217
|
+
return *new (newT) T(std::forward<Args>(args)...);
|
218
|
+
}
|
219
|
+
|
220
|
+
/**
|
221
|
+
* Allocates n more default-initialized T values, and returns the address of
|
222
|
+
* the start of that new range. Note: this address is only valid until the
|
223
|
+
* next API call made on the array that might add or remove elements.
|
224
|
+
*/
|
225
|
+
T* push_back_n(int n) {
|
226
|
+
SkASSERT(n >= 0);
|
227
|
+
T* newTs = TCast(this->push_back_raw(n));
|
228
|
+
for (int i = 0; i < n; ++i) {
|
229
|
+
new (&newTs[i]) T;
|
230
|
+
}
|
231
|
+
return newTs;
|
232
|
+
}
|
233
|
+
|
234
|
+
/**
|
235
|
+
* Version of above that uses a copy constructor to initialize all n items
|
236
|
+
* to the same T.
|
237
|
+
*/
|
238
|
+
T* push_back_n(int n, const T& t) {
|
239
|
+
SkASSERT(n >= 0);
|
240
|
+
T* newTs = TCast(this->push_back_raw(n));
|
241
|
+
for (int i = 0; i < n; ++i) {
|
242
|
+
new (&newTs[i]) T(t);
|
243
|
+
}
|
244
|
+
return static_cast<T*>(newTs);
|
245
|
+
}
|
246
|
+
|
247
|
+
/**
|
248
|
+
* Version of above that uses a copy constructor to initialize the n items
|
249
|
+
* to separate T values.
|
250
|
+
*/
|
251
|
+
T* push_back_n(int n, const T t[]) {
|
252
|
+
SkASSERT(n >= 0);
|
253
|
+
this->checkRealloc(n, kGrowing);
|
254
|
+
T* end = this->end();
|
255
|
+
for (int i = 0; i < n; ++i) {
|
256
|
+
new (end + i) T(t[i]);
|
257
|
+
}
|
258
|
+
fSize += n;
|
259
|
+
return end;
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* Version of above that uses the move constructor to set n items.
|
264
|
+
*/
|
265
|
+
T* move_back_n(int n, T* t) {
|
266
|
+
SkASSERT(n >= 0);
|
267
|
+
this->checkRealloc(n, kGrowing);
|
268
|
+
T* end = this->end();
|
269
|
+
for (int i = 0; i < n; ++i) {
|
270
|
+
new (end + i) T(std::move(t[i]));
|
271
|
+
}
|
272
|
+
fSize += n;
|
273
|
+
return end;
|
274
|
+
}
|
275
|
+
|
276
|
+
/**
|
277
|
+
* Removes the last element. Not safe to call when size() == 0.
|
278
|
+
*/
|
279
|
+
void pop_back() {
|
280
|
+
SkASSERT(fSize > 0);
|
281
|
+
--fSize;
|
282
|
+
fData[fSize].~T();
|
283
|
+
}
|
284
|
+
|
285
|
+
/**
|
286
|
+
* Removes the last n elements. Not safe to call when size() < n.
|
287
|
+
*/
|
288
|
+
void pop_back_n(int n) {
|
289
|
+
SkASSERT(n >= 0);
|
290
|
+
SkASSERT(this->size() >= n);
|
291
|
+
int i = fSize;
|
292
|
+
while (i-- > fSize - n) {
|
293
|
+
(*this)[i].~T();
|
294
|
+
}
|
295
|
+
fSize -= n;
|
296
|
+
}
|
297
|
+
|
298
|
+
/**
|
299
|
+
* Pushes or pops from the back to resize. Pushes will be default
|
300
|
+
* initialized.
|
301
|
+
*/
|
302
|
+
void resize_back(int newCount) {
|
303
|
+
SkASSERT(newCount >= 0);
|
304
|
+
|
305
|
+
if (newCount > this->size()) {
|
306
|
+
this->push_back_n(newCount - fSize);
|
307
|
+
} else if (newCount < this->size()) {
|
308
|
+
this->pop_back_n(fSize - newCount);
|
309
|
+
}
|
310
|
+
}
|
311
|
+
|
312
|
+
/** Swaps the contents of this array with that array. Does a pointer swap if possible,
|
313
|
+
otherwise copies the T values. */
|
314
|
+
void swap(TArray& that) {
|
315
|
+
using std::swap;
|
316
|
+
if (this == &that) {
|
317
|
+
return;
|
318
|
+
}
|
319
|
+
if (fOwnMemory && that.fOwnMemory) {
|
320
|
+
swap(fData, that.fData);
|
321
|
+
swap(fSize, that.fSize);
|
322
|
+
|
323
|
+
// Can't use swap because fCapacity is a bit field.
|
324
|
+
auto allocCount = fCapacity;
|
325
|
+
fCapacity = that.fCapacity;
|
326
|
+
that.fCapacity = allocCount;
|
327
|
+
} else {
|
328
|
+
// This could be more optimal...
|
329
|
+
TArray copy(std::move(that));
|
330
|
+
that = std::move(*this);
|
331
|
+
*this = std::move(copy);
|
332
|
+
}
|
333
|
+
}
|
334
|
+
|
335
|
+
T* begin() {
|
336
|
+
return fData;
|
337
|
+
}
|
338
|
+
const T* begin() const {
|
339
|
+
return fData;
|
340
|
+
}
|
341
|
+
|
342
|
+
// It's safe to use fItemArray + fSize because if fItemArray is nullptr then adding 0 is
|
343
|
+
// valid and returns nullptr. See [expr.add] in the C++ standard.
|
344
|
+
T* end() {
|
345
|
+
if (fData == nullptr) {
|
346
|
+
SkASSERT(fSize == 0);
|
347
|
+
}
|
348
|
+
return fData + fSize;
|
349
|
+
}
|
350
|
+
const T* end() const {
|
351
|
+
if (fData == nullptr) {
|
352
|
+
SkASSERT(fSize == 0);
|
353
|
+
}
|
354
|
+
return fData + fSize;
|
355
|
+
}
|
356
|
+
T* data() { return fData; }
|
357
|
+
const T* data() const { return fData; }
|
358
|
+
int size() const { return fSize; }
|
359
|
+
size_t size_bytes() const { return this->bytes(fSize); }
|
360
|
+
void resize(size_t count) { this->resize_back((int)count); }
|
361
|
+
|
362
|
+
void clear() {
|
363
|
+
this->destroyAll();
|
364
|
+
fSize = 0;
|
365
|
+
}
|
366
|
+
|
367
|
+
void shrink_to_fit() {
|
368
|
+
if (!fOwnMemory || fSize == fCapacity) {
|
369
|
+
return;
|
370
|
+
}
|
371
|
+
if (fSize == 0) {
|
372
|
+
sk_free(fData);
|
373
|
+
fData = nullptr;
|
374
|
+
fCapacity = 0;
|
375
|
+
} else {
|
376
|
+
SkSpan<std::byte> allocation = Allocate(fSize);
|
377
|
+
this->move(TCast(allocation.data()));
|
378
|
+
if (fOwnMemory) {
|
379
|
+
sk_free(fData);
|
380
|
+
}
|
381
|
+
this->setDataFromBytes(allocation);
|
382
|
+
}
|
383
|
+
}
|
384
|
+
|
385
|
+
/**
|
386
|
+
* Get the i^th element.
|
387
|
+
*/
|
388
|
+
T& operator[] (int i) {
|
389
|
+
SkASSERT(i < this->size());
|
390
|
+
SkASSERT(i >= 0);
|
391
|
+
return fData[i];
|
392
|
+
}
|
393
|
+
|
394
|
+
const T& operator[] (int i) const {
|
395
|
+
SkASSERT(i < this->size());
|
396
|
+
SkASSERT(i >= 0);
|
397
|
+
return fData[i];
|
398
|
+
}
|
399
|
+
|
400
|
+
T& at(int i) { return (*this)[i]; }
|
401
|
+
const T& at(int i) const { return (*this)[i]; }
|
402
|
+
|
403
|
+
/**
|
404
|
+
* equivalent to operator[](0)
|
405
|
+
*/
|
406
|
+
T& front() { SkASSERT(fSize > 0); return fData[0];}
|
407
|
+
|
408
|
+
const T& front() const { SkASSERT(fSize > 0); return fData[0];}
|
409
|
+
|
410
|
+
/**
|
411
|
+
* equivalent to operator[](size() - 1)
|
412
|
+
*/
|
413
|
+
T& back() { SkASSERT(fSize); return fData[fSize - 1];}
|
414
|
+
|
415
|
+
const T& back() const { SkASSERT(fSize > 0); return fData[fSize - 1];}
|
416
|
+
|
417
|
+
/**
|
418
|
+
* equivalent to operator[](size()-1-i)
|
419
|
+
*/
|
420
|
+
T& fromBack(int i) {
|
421
|
+
SkASSERT(i >= 0);
|
422
|
+
SkASSERT(i < this->size());
|
423
|
+
return fData[fSize - i - 1];
|
424
|
+
}
|
425
|
+
|
426
|
+
const T& fromBack(int i) const {
|
427
|
+
SkASSERT(i >= 0);
|
428
|
+
SkASSERT(i < this->size());
|
429
|
+
return fData[fSize - i - 1];
|
430
|
+
}
|
431
|
+
|
432
|
+
bool operator==(const TArray<T, MEM_MOVE>& right) const {
|
433
|
+
int leftCount = this->size();
|
434
|
+
if (leftCount != right.size()) {
|
435
|
+
return false;
|
436
|
+
}
|
437
|
+
for (int index = 0; index < leftCount; ++index) {
|
438
|
+
if (fData[index] != right.fData[index]) {
|
439
|
+
return false;
|
440
|
+
}
|
441
|
+
}
|
442
|
+
return true;
|
443
|
+
}
|
444
|
+
|
445
|
+
bool operator!=(const TArray<T, MEM_MOVE>& right) const {
|
446
|
+
return !(*this == right);
|
447
|
+
}
|
448
|
+
|
449
|
+
int capacity() const {
|
450
|
+
return fCapacity;
|
451
|
+
}
|
452
|
+
|
453
|
+
protected:
|
454
|
+
// Creates an empty array that will use the passed storage block until it is insufficiently
|
455
|
+
// large to hold the entire array.
|
456
|
+
template <int InitialCapacity>
|
457
|
+
TArray(SkAlignedSTStorage<InitialCapacity, T>* storage, int size = 0) {
|
458
|
+
static_assert(InitialCapacity >= 0);
|
459
|
+
SkASSERT(size >= 0);
|
460
|
+
SkASSERT(storage->get() != nullptr);
|
461
|
+
if (size > InitialCapacity) {
|
462
|
+
this->initData(size);
|
463
|
+
} else {
|
464
|
+
this->setDataFromBytes(*storage);
|
465
|
+
fSize = size;
|
466
|
+
|
467
|
+
// setDataFromBytes always sets fOwnMemory to true, but we are actually using static
|
468
|
+
// storage here, which shouldn't ever be freed.
|
469
|
+
fOwnMemory = false;
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
// Copy a C array, using pre-allocated storage if preAllocCount >= count. Otherwise, storage
|
474
|
+
// will only be used when array shrinks to fit.
|
475
|
+
template <int InitialCapacity>
|
476
|
+
TArray(const T* array, int size, SkAlignedSTStorage<InitialCapacity, T>* storage)
|
477
|
+
: TArray{storage, size}
|
478
|
+
{
|
479
|
+
this->copy(array);
|
480
|
+
}
|
481
|
+
|
482
|
+
private:
|
483
|
+
// Growth factors for checkRealloc.
|
484
|
+
static constexpr double kExactFit = 1.0;
|
485
|
+
static constexpr double kGrowing = 1.5;
|
486
|
+
|
487
|
+
static constexpr int kMinHeapAllocCount = 8;
|
488
|
+
static_assert(SkIsPow2(kMinHeapAllocCount), "min alloc count not power of two.");
|
489
|
+
|
490
|
+
// Note for 32-bit machines kMaxCapacity will be <= SIZE_MAX. For 64-bit machines it will
|
491
|
+
// just be INT_MAX if the sizeof(T) < 2^32.
|
492
|
+
static constexpr int kMaxCapacity = SkToInt(std::min(SIZE_MAX / sizeof(T), (size_t)INT_MAX));
|
493
|
+
|
494
|
+
void setDataFromBytes(SkSpan<std::byte> allocation) {
|
495
|
+
T* data = TCast(allocation.data());
|
496
|
+
// We have gotten extra bytes back from the allocation limit, pin to kMaxCapacity. It
|
497
|
+
// would seem like the SkContainerAllocator should handle the divide, but it would have
|
498
|
+
// to a full divide instruction. If done here the size is known at compile, and usually
|
499
|
+
// can be implemented by a right shift. The full divide takes ~50X longer than the shift.
|
500
|
+
size_t size = std::min(allocation.size() / sizeof(T), SkToSizeT(kMaxCapacity));
|
501
|
+
setData(SkSpan<T>(data, size));
|
502
|
+
}
|
503
|
+
|
504
|
+
void setData(SkSpan<T> array) {
|
505
|
+
fData = array.data();
|
506
|
+
fCapacity = SkToU32(array.size());
|
507
|
+
fOwnMemory = true;
|
508
|
+
}
|
509
|
+
|
510
|
+
// We disable Control-Flow Integrity sanitization (go/cfi) when casting item-array buffers.
|
511
|
+
// CFI flags this code as dangerous because we are casting `buffer` to a T* while the buffer's
|
512
|
+
// contents might still be uninitialized memory. When T has a vtable, this is especially risky
|
513
|
+
// because we could hypothetically access a virtual method on fItemArray and jump to an
|
514
|
+
// unpredictable location in memory. Of course, TArray won't actually use fItemArray in this
|
515
|
+
// way, and we don't want to construct a T before the user requests one. There's no real risk
|
516
|
+
// here, so disable CFI when doing these casts.
|
517
|
+
SK_CLANG_NO_SANITIZE("cfi")
|
518
|
+
static T* TCast(void* buffer) {
|
519
|
+
return (T*)buffer;
|
520
|
+
}
|
521
|
+
|
522
|
+
size_t bytes(int n) const {
|
523
|
+
SkASSERT(n <= kMaxCapacity);
|
524
|
+
return SkToSizeT(n) * sizeof(T);
|
525
|
+
}
|
526
|
+
|
527
|
+
static SkSpan<std::byte> Allocate(int capacity, double growthFactor = 1.0) {
|
528
|
+
return SkContainerAllocator{sizeof(T), kMaxCapacity}.allocate(capacity, growthFactor);
|
529
|
+
}
|
530
|
+
|
531
|
+
void initData(int count) {
|
532
|
+
this->setDataFromBytes(Allocate(count));
|
533
|
+
fSize = count;
|
534
|
+
}
|
535
|
+
|
536
|
+
void destroyAll() {
|
537
|
+
if (!this->empty()) {
|
538
|
+
T* cursor = this->begin();
|
539
|
+
T* const end = this->end();
|
540
|
+
do {
|
541
|
+
cursor->~T();
|
542
|
+
cursor++;
|
543
|
+
} while (cursor < end);
|
544
|
+
}
|
545
|
+
}
|
546
|
+
|
547
|
+
/** In the following move and copy methods, 'dst' is assumed to be uninitialized raw storage.
|
548
|
+
* In the following move methods, 'src' is destroyed leaving behind uninitialized raw storage.
|
549
|
+
*/
|
550
|
+
void copy(const T* src) {
|
551
|
+
if constexpr (std::is_trivially_copyable_v<T>) {
|
552
|
+
if (!this->empty() && src != nullptr) {
|
553
|
+
sk_careful_memcpy(fData, src, this->size_bytes());
|
554
|
+
}
|
555
|
+
} else {
|
556
|
+
for (int i = 0; i < this->size(); ++i) {
|
557
|
+
new (fData + i) T(src[i]);
|
558
|
+
}
|
559
|
+
}
|
560
|
+
}
|
561
|
+
|
562
|
+
void move(int dst, int src) {
|
563
|
+
if constexpr (MEM_MOVE) {
|
564
|
+
memcpy(static_cast<void*>(&fData[dst]),
|
565
|
+
static_cast<const void*>(&fData[src]),
|
566
|
+
sizeof(T));
|
567
|
+
} else {
|
568
|
+
new (&fData[dst]) T(std::move(fData[src]));
|
569
|
+
fData[src].~T();
|
570
|
+
}
|
571
|
+
}
|
572
|
+
|
573
|
+
void move(void* dst) {
|
574
|
+
if constexpr (MEM_MOVE) {
|
575
|
+
sk_careful_memcpy(dst, fData, this->bytes(fSize));
|
576
|
+
} else {
|
577
|
+
for (int i = 0; i < this->size(); ++i) {
|
578
|
+
new (static_cast<char*>(dst) + this->bytes(i)) T(std::move(fData[i]));
|
579
|
+
fData[i].~T();
|
580
|
+
}
|
581
|
+
}
|
582
|
+
}
|
583
|
+
|
584
|
+
// Helper function that makes space for n objects, adjusts the count, but does not initialize
|
585
|
+
// the new objects.
|
586
|
+
void* push_back_raw(int n) {
|
587
|
+
this->checkRealloc(n, kGrowing);
|
588
|
+
void* ptr = fData + fSize;
|
589
|
+
fSize += n;
|
590
|
+
return ptr;
|
591
|
+
}
|
592
|
+
|
593
|
+
void checkRealloc(int delta, double growthFactor) {
|
594
|
+
// This constant needs to be declared in the function where it is used to work around
|
595
|
+
// MSVC's persnickety nature about template definitions.
|
596
|
+
SkASSERT(delta >= 0);
|
597
|
+
SkASSERT(fSize >= 0);
|
598
|
+
SkASSERT(fCapacity >= 0);
|
599
|
+
|
600
|
+
// Return if there are enough remaining allocated elements to satisfy the request.
|
601
|
+
if (this->capacity() - fSize >= delta) {
|
602
|
+
return;
|
603
|
+
}
|
604
|
+
|
605
|
+
// Don't overflow fSize or size_t later in the memory allocation. Overflowing memory
|
606
|
+
// allocation really only applies to fSizes on 32-bit machines; on 64-bit machines this
|
607
|
+
// will probably never produce a check. Since kMaxCapacity is bounded above by INT_MAX,
|
608
|
+
// this also checks the bounds of fSize.
|
609
|
+
if (delta > kMaxCapacity - fSize) {
|
610
|
+
sk_report_container_overflow_and_die();
|
611
|
+
}
|
612
|
+
const int newCount = fSize + delta;
|
613
|
+
|
614
|
+
SkSpan<std::byte> allocation = Allocate(newCount, growthFactor);
|
615
|
+
|
616
|
+
this->move(TCast(allocation.data()));
|
617
|
+
if (fOwnMemory) {
|
618
|
+
sk_free(fData);
|
619
|
+
}
|
620
|
+
this->setDataFromBytes(allocation);
|
621
|
+
SkASSERT(this->capacity() >= newCount);
|
622
|
+
SkASSERT(fData != nullptr);
|
623
|
+
}
|
624
|
+
|
625
|
+
T* fData{nullptr};
|
626
|
+
int fSize{0};
|
627
|
+
uint32_t fOwnMemory : 1;
|
628
|
+
uint32_t fCapacity : 31;
|
629
|
+
};
|
630
|
+
|
631
|
+
template <typename T, bool M> static inline void swap(TArray<T, M>& a, TArray<T, M>& b) {
|
632
|
+
a.swap(b);
|
633
|
+
}
|
634
|
+
|
635
|
+
// Subclass of TArray that contains a pre-allocated memory block for the array.
|
636
|
+
template <int N, typename T, bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
|
637
|
+
class STArray : private SkAlignedSTStorage<N,T>, public TArray<T, MEM_MOVE> {
|
638
|
+
static_assert(N > 0);
|
639
|
+
using Storage = SkAlignedSTStorage<N,T>;
|
640
|
+
|
641
|
+
public:
|
642
|
+
STArray()
|
643
|
+
: Storage{}
|
644
|
+
, TArray<T, MEM_MOVE>(this) {} // Must use () to avoid confusion with initializer_list
|
645
|
+
// when T=bool because * are convertable to bool.
|
646
|
+
|
647
|
+
STArray(const T* array, int count)
|
648
|
+
: Storage{}
|
649
|
+
, TArray<T, MEM_MOVE>{array, count, this} {}
|
650
|
+
|
651
|
+
STArray(std::initializer_list<T> data)
|
652
|
+
: STArray{data.begin(), SkToInt(data.size())} {}
|
653
|
+
|
654
|
+
explicit STArray(int reserveCount)
|
655
|
+
: STArray() { this->reserve_back(reserveCount); }
|
656
|
+
|
657
|
+
STArray(const STArray& that)
|
658
|
+
: STArray() { *this = that; }
|
659
|
+
|
660
|
+
explicit STArray(const TArray<T, MEM_MOVE>& that)
|
661
|
+
: STArray() { *this = that; }
|
662
|
+
|
663
|
+
STArray(STArray&& that)
|
664
|
+
: STArray() { *this = std::move(that); }
|
665
|
+
|
666
|
+
explicit STArray(TArray<T, MEM_MOVE>&& that)
|
667
|
+
: STArray() { *this = std::move(that); }
|
668
|
+
|
669
|
+
STArray& operator=(const STArray& that) {
|
670
|
+
TArray<T, MEM_MOVE>::operator=(that);
|
671
|
+
return *this;
|
672
|
+
}
|
673
|
+
|
674
|
+
STArray& operator=(const TArray<T, MEM_MOVE>& that) {
|
675
|
+
TArray<T, MEM_MOVE>::operator=(that);
|
676
|
+
return *this;
|
677
|
+
}
|
678
|
+
|
679
|
+
STArray& operator=(STArray&& that) {
|
680
|
+
TArray<T, MEM_MOVE>::operator=(std::move(that));
|
681
|
+
return *this;
|
682
|
+
}
|
683
|
+
|
684
|
+
STArray& operator=(TArray<T, MEM_MOVE>&& that) {
|
685
|
+
TArray<T, MEM_MOVE>::operator=(std::move(that));
|
686
|
+
return *this;
|
687
|
+
}
|
688
|
+
|
689
|
+
// Force the use of TArray for data() and size().
|
690
|
+
using TArray<T, MEM_MOVE>::data;
|
691
|
+
using TArray<T, MEM_MOVE>::size;
|
692
|
+
};
|
693
|
+
} // namespace skia_private
|
694
|
+
#endif // SkTArray_DEFINED
|