@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
@@ -1,655 +0,0 @@
|
|
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/core/SkMath.h"
|
12
|
-
#include "include/core/SkTypes.h"
|
13
|
-
#include "include/private/SkMalloc.h"
|
14
|
-
#include "include/private/SkSafe32.h"
|
15
|
-
#include "include/private/SkTLogic.h"
|
16
|
-
#include "include/private/SkTemplates.h"
|
17
|
-
#include "include/private/SkTo.h"
|
18
|
-
|
19
|
-
#include <algorithm>
|
20
|
-
#include <string.h>
|
21
|
-
#include <initializer_list>
|
22
|
-
#include <memory>
|
23
|
-
#include <new>
|
24
|
-
#include <utility>
|
25
|
-
|
26
|
-
/** SkTArray<T> implements a typical, mostly std::vector-like array.
|
27
|
-
Each T will be default-initialized on allocation, and ~T will be called on destruction.
|
28
|
-
|
29
|
-
MEM_MOVE controls the behavior when a T needs to be moved (e.g. when the array is resized)
|
30
|
-
- true: T will be bit-copied via memcpy.
|
31
|
-
- false: T will be moved via move-constructors.
|
32
|
-
|
33
|
-
Modern implementations of std::vector<T> will generally provide similar performance
|
34
|
-
characteristics when used with appropriate care. Consider using std::vector<T> in new code.
|
35
|
-
*/
|
36
|
-
template <typename T, bool MEM_MOVE = sk_is_trivially_relocatable<T>::value> class SkTArray {
|
37
|
-
private:
|
38
|
-
enum ReallocType { kExactFit, kGrowing, kShrinking };
|
39
|
-
|
40
|
-
public:
|
41
|
-
using value_type = T;
|
42
|
-
|
43
|
-
/**
|
44
|
-
* Creates an empty array with no initial storage
|
45
|
-
*/
|
46
|
-
SkTArray() { this->init(0); }
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Creates an empty array that will preallocate space for reserveCount
|
50
|
-
* elements.
|
51
|
-
*/
|
52
|
-
explicit SkTArray(int reserveCount) : SkTArray() { this->reserve_back(reserveCount); }
|
53
|
-
|
54
|
-
/**
|
55
|
-
* Copies one array to another. The new array will be heap allocated.
|
56
|
-
*/
|
57
|
-
SkTArray(const SkTArray& that)
|
58
|
-
: SkTArray(that.fItemArray, that.fCount) {}
|
59
|
-
|
60
|
-
SkTArray(SkTArray&& that) {
|
61
|
-
if (that.fOwnMemory) {
|
62
|
-
fItemArray = that.fItemArray;
|
63
|
-
fCount = that.fCount;
|
64
|
-
fAllocCount = that.fAllocCount;
|
65
|
-
fOwnMemory = true;
|
66
|
-
fReserved = that.fReserved;
|
67
|
-
|
68
|
-
that.fItemArray = nullptr;
|
69
|
-
that.fCount = 0;
|
70
|
-
that.fAllocCount = 0;
|
71
|
-
that.fOwnMemory = true;
|
72
|
-
that.fReserved = false;
|
73
|
-
} else {
|
74
|
-
this->init(that.fCount);
|
75
|
-
that.move(fItemArray);
|
76
|
-
that.fCount = 0;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
/**
|
81
|
-
* Creates a SkTArray by copying contents of a standard C array. The new
|
82
|
-
* array will be heap allocated. Be careful not to use this constructor
|
83
|
-
* when you really want the (void*, int) version.
|
84
|
-
*/
|
85
|
-
SkTArray(const T* array, int count) {
|
86
|
-
this->init(count);
|
87
|
-
this->copy(array);
|
88
|
-
}
|
89
|
-
/**
|
90
|
-
* Creates a SkTArray by copying contents of an initializer list.
|
91
|
-
*/
|
92
|
-
SkTArray(std::initializer_list<T> data)
|
93
|
-
: SkTArray(data.begin(), data.size()) {}
|
94
|
-
|
95
|
-
SkTArray& operator=(const SkTArray& that) {
|
96
|
-
if (this == &that) {
|
97
|
-
return *this;
|
98
|
-
}
|
99
|
-
for (int i = 0; i < this->count(); ++i) {
|
100
|
-
fItemArray[i].~T();
|
101
|
-
}
|
102
|
-
fCount = 0;
|
103
|
-
this->checkRealloc(that.count(), kExactFit);
|
104
|
-
fCount = that.fCount;
|
105
|
-
this->copy(that.fItemArray);
|
106
|
-
return *this;
|
107
|
-
}
|
108
|
-
SkTArray& operator=(SkTArray&& that) {
|
109
|
-
if (this == &that) {
|
110
|
-
return *this;
|
111
|
-
}
|
112
|
-
for (int i = 0; i < this->count(); ++i) {
|
113
|
-
fItemArray[i].~T();
|
114
|
-
}
|
115
|
-
fCount = 0;
|
116
|
-
this->checkRealloc(that.count(), kExactFit);
|
117
|
-
fCount = that.fCount;
|
118
|
-
that.move(fItemArray);
|
119
|
-
that.fCount = 0;
|
120
|
-
return *this;
|
121
|
-
}
|
122
|
-
|
123
|
-
~SkTArray() {
|
124
|
-
for (int i = 0; i < this->count(); ++i) {
|
125
|
-
fItemArray[i].~T();
|
126
|
-
}
|
127
|
-
if (fOwnMemory) {
|
128
|
-
sk_free(fItemArray);
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
132
|
-
/**
|
133
|
-
* Resets to count() == 0 and resets any reserve count.
|
134
|
-
*/
|
135
|
-
void reset() {
|
136
|
-
this->pop_back_n(fCount);
|
137
|
-
fReserved = false;
|
138
|
-
}
|
139
|
-
|
140
|
-
/**
|
141
|
-
* Resets to count() = n newly constructed T objects and resets any reserve count.
|
142
|
-
*/
|
143
|
-
void reset(int n) {
|
144
|
-
SkASSERT(n >= 0);
|
145
|
-
for (int i = 0; i < this->count(); ++i) {
|
146
|
-
fItemArray[i].~T();
|
147
|
-
}
|
148
|
-
// Set fCount to 0 before calling checkRealloc so that no elements are moved.
|
149
|
-
fCount = 0;
|
150
|
-
this->checkRealloc(n, kExactFit);
|
151
|
-
fCount = n;
|
152
|
-
for (int i = 0; i < this->count(); ++i) {
|
153
|
-
new (fItemArray + i) T;
|
154
|
-
}
|
155
|
-
fReserved = false;
|
156
|
-
}
|
157
|
-
|
158
|
-
/**
|
159
|
-
* Resets to a copy of a C array and resets any reserve count.
|
160
|
-
*/
|
161
|
-
void reset(const T* array, int count) {
|
162
|
-
for (int i = 0; i < this->count(); ++i) {
|
163
|
-
fItemArray[i].~T();
|
164
|
-
}
|
165
|
-
fCount = 0;
|
166
|
-
this->checkRealloc(count, kExactFit);
|
167
|
-
fCount = count;
|
168
|
-
this->copy(array);
|
169
|
-
fReserved = false;
|
170
|
-
}
|
171
|
-
|
172
|
-
/**
|
173
|
-
* Ensures there is enough reserved space for n additional elements. The is guaranteed at least
|
174
|
-
* until the array size grows above n and subsequently shrinks below n, any version of reset()
|
175
|
-
* is called, or reserve_back() is called again.
|
176
|
-
*/
|
177
|
-
void reserve_back(int n) {
|
178
|
-
SkASSERT(n >= 0);
|
179
|
-
if (n > 0) {
|
180
|
-
this->checkRealloc(n, kExactFit);
|
181
|
-
fReserved = fOwnMemory;
|
182
|
-
} else {
|
183
|
-
fReserved = false;
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
void removeShuffle(int n) {
|
188
|
-
SkASSERT(n < this->count());
|
189
|
-
int newCount = fCount - 1;
|
190
|
-
fCount = newCount;
|
191
|
-
fItemArray[n].~T();
|
192
|
-
if (n != newCount) {
|
193
|
-
this->move(n, newCount);
|
194
|
-
}
|
195
|
-
}
|
196
|
-
|
197
|
-
/**
|
198
|
-
* Number of elements in the array.
|
199
|
-
*/
|
200
|
-
int count() const { return fCount; }
|
201
|
-
|
202
|
-
/**
|
203
|
-
* Is the array empty.
|
204
|
-
*/
|
205
|
-
bool empty() const { return !fCount; }
|
206
|
-
|
207
|
-
/**
|
208
|
-
* Adds 1 new default-initialized T value and returns it by reference. Note
|
209
|
-
* the reference only remains valid until the next call that adds or removes
|
210
|
-
* elements.
|
211
|
-
*/
|
212
|
-
T& push_back() {
|
213
|
-
void* newT = this->push_back_raw(1);
|
214
|
-
return *new (newT) T;
|
215
|
-
}
|
216
|
-
|
217
|
-
/**
|
218
|
-
* Version of above that uses a copy constructor to initialize the new item
|
219
|
-
*/
|
220
|
-
T& push_back(const T& t) {
|
221
|
-
void* newT = this->push_back_raw(1);
|
222
|
-
return *new (newT) T(t);
|
223
|
-
}
|
224
|
-
|
225
|
-
/**
|
226
|
-
* Version of above that uses a move constructor to initialize the new item
|
227
|
-
*/
|
228
|
-
T& push_back(T&& t) {
|
229
|
-
void* newT = this->push_back_raw(1);
|
230
|
-
return *new (newT) T(std::move(t));
|
231
|
-
}
|
232
|
-
|
233
|
-
/**
|
234
|
-
* Construct a new T at the back of this array.
|
235
|
-
*/
|
236
|
-
template<class... Args> T& emplace_back(Args&&... args) {
|
237
|
-
void* newT = this->push_back_raw(1);
|
238
|
-
return *new (newT) T(std::forward<Args>(args)...);
|
239
|
-
}
|
240
|
-
|
241
|
-
/**
|
242
|
-
* Allocates n more default-initialized T values, and returns the address of
|
243
|
-
* the start of that new range. Note: this address is only valid until the
|
244
|
-
* next API call made on the array that might add or remove elements.
|
245
|
-
*/
|
246
|
-
T* push_back_n(int n) {
|
247
|
-
SkASSERT(n >= 0);
|
248
|
-
void* newTs = this->push_back_raw(n);
|
249
|
-
for (int i = 0; i < n; ++i) {
|
250
|
-
new (static_cast<char*>(newTs) + i * sizeof(T)) T;
|
251
|
-
}
|
252
|
-
return static_cast<T*>(newTs);
|
253
|
-
}
|
254
|
-
|
255
|
-
/**
|
256
|
-
* Version of above that uses a copy constructor to initialize all n items
|
257
|
-
* to the same T.
|
258
|
-
*/
|
259
|
-
T* push_back_n(int n, const T& t) {
|
260
|
-
SkASSERT(n >= 0);
|
261
|
-
void* newTs = this->push_back_raw(n);
|
262
|
-
for (int i = 0; i < n; ++i) {
|
263
|
-
new (static_cast<char*>(newTs) + i * sizeof(T)) T(t);
|
264
|
-
}
|
265
|
-
return static_cast<T*>(newTs);
|
266
|
-
}
|
267
|
-
|
268
|
-
/**
|
269
|
-
* Version of above that uses a copy constructor to initialize the n items
|
270
|
-
* to separate T values.
|
271
|
-
*/
|
272
|
-
T* push_back_n(int n, const T t[]) {
|
273
|
-
SkASSERT(n >= 0);
|
274
|
-
this->checkRealloc(n, kGrowing);
|
275
|
-
for (int i = 0; i < n; ++i) {
|
276
|
-
new (fItemArray + fCount + i) T(t[i]);
|
277
|
-
}
|
278
|
-
fCount += n;
|
279
|
-
return fItemArray + fCount - n;
|
280
|
-
}
|
281
|
-
|
282
|
-
/**
|
283
|
-
* Version of above that uses the move constructor to set n items.
|
284
|
-
*/
|
285
|
-
T* move_back_n(int n, T* t) {
|
286
|
-
SkASSERT(n >= 0);
|
287
|
-
this->checkRealloc(n, kGrowing);
|
288
|
-
for (int i = 0; i < n; ++i) {
|
289
|
-
new (fItemArray + fCount + i) T(std::move(t[i]));
|
290
|
-
}
|
291
|
-
fCount += n;
|
292
|
-
return fItemArray + fCount - n;
|
293
|
-
}
|
294
|
-
|
295
|
-
/**
|
296
|
-
* Removes the last element. Not safe to call when count() == 0.
|
297
|
-
*/
|
298
|
-
void pop_back() {
|
299
|
-
SkASSERT(fCount > 0);
|
300
|
-
--fCount;
|
301
|
-
fItemArray[fCount].~T();
|
302
|
-
this->checkRealloc(0, kShrinking);
|
303
|
-
}
|
304
|
-
|
305
|
-
/**
|
306
|
-
* Removes the last n elements. Not safe to call when count() < n.
|
307
|
-
*/
|
308
|
-
void pop_back_n(int n) {
|
309
|
-
SkASSERT(n >= 0);
|
310
|
-
SkASSERT(this->count() >= n);
|
311
|
-
fCount -= n;
|
312
|
-
for (int i = 0; i < n; ++i) {
|
313
|
-
fItemArray[fCount + i].~T();
|
314
|
-
}
|
315
|
-
this->checkRealloc(0, kShrinking);
|
316
|
-
}
|
317
|
-
|
318
|
-
/**
|
319
|
-
* Pushes or pops from the back to resize. Pushes will be default
|
320
|
-
* initialized.
|
321
|
-
*/
|
322
|
-
void resize_back(int newCount) {
|
323
|
-
SkASSERT(newCount >= 0);
|
324
|
-
|
325
|
-
if (newCount > this->count()) {
|
326
|
-
this->push_back_n(newCount - fCount);
|
327
|
-
} else if (newCount < this->count()) {
|
328
|
-
this->pop_back_n(fCount - newCount);
|
329
|
-
}
|
330
|
-
}
|
331
|
-
|
332
|
-
/** Swaps the contents of this array with that array. Does a pointer swap if possible,
|
333
|
-
otherwise copies the T values. */
|
334
|
-
void swap(SkTArray& that) {
|
335
|
-
using std::swap;
|
336
|
-
if (this == &that) {
|
337
|
-
return;
|
338
|
-
}
|
339
|
-
if (fOwnMemory && that.fOwnMemory) {
|
340
|
-
swap(fItemArray, that.fItemArray);
|
341
|
-
|
342
|
-
auto count = fCount;
|
343
|
-
fCount = that.fCount;
|
344
|
-
that.fCount = count;
|
345
|
-
|
346
|
-
auto allocCount = fAllocCount;
|
347
|
-
fAllocCount = that.fAllocCount;
|
348
|
-
that.fAllocCount = allocCount;
|
349
|
-
} else {
|
350
|
-
// This could be more optimal...
|
351
|
-
SkTArray copy(std::move(that));
|
352
|
-
that = std::move(*this);
|
353
|
-
*this = std::move(copy);
|
354
|
-
}
|
355
|
-
}
|
356
|
-
|
357
|
-
T* begin() {
|
358
|
-
return fItemArray;
|
359
|
-
}
|
360
|
-
const T* begin() const {
|
361
|
-
return fItemArray;
|
362
|
-
}
|
363
|
-
T* end() {
|
364
|
-
return fItemArray ? fItemArray + fCount : nullptr;
|
365
|
-
}
|
366
|
-
const T* end() const {
|
367
|
-
return fItemArray ? fItemArray + fCount : nullptr;
|
368
|
-
}
|
369
|
-
T* data() { return fItemArray; }
|
370
|
-
const T* data() const { return fItemArray; }
|
371
|
-
size_t size() const { return (size_t)fCount; }
|
372
|
-
void resize(size_t count) { this->resize_back((int)count); }
|
373
|
-
|
374
|
-
/**
|
375
|
-
* Get the i^th element.
|
376
|
-
*/
|
377
|
-
T& operator[] (int i) {
|
378
|
-
SkASSERT(i < this->count());
|
379
|
-
SkASSERT(i >= 0);
|
380
|
-
return fItemArray[i];
|
381
|
-
}
|
382
|
-
|
383
|
-
const T& operator[] (int i) const {
|
384
|
-
SkASSERT(i < this->count());
|
385
|
-
SkASSERT(i >= 0);
|
386
|
-
return fItemArray[i];
|
387
|
-
}
|
388
|
-
|
389
|
-
T& at(int i) { return (*this)[i]; }
|
390
|
-
const T& at(int i) const { return (*this)[i]; }
|
391
|
-
|
392
|
-
/**
|
393
|
-
* equivalent to operator[](0)
|
394
|
-
*/
|
395
|
-
T& front() { SkASSERT(fCount > 0); return fItemArray[0];}
|
396
|
-
|
397
|
-
const T& front() const { SkASSERT(fCount > 0); return fItemArray[0];}
|
398
|
-
|
399
|
-
/**
|
400
|
-
* equivalent to operator[](count() - 1)
|
401
|
-
*/
|
402
|
-
T& back() { SkASSERT(fCount); return fItemArray[fCount - 1];}
|
403
|
-
|
404
|
-
const T& back() const { SkASSERT(fCount > 0); return fItemArray[fCount - 1];}
|
405
|
-
|
406
|
-
/**
|
407
|
-
* equivalent to operator[](count()-1-i)
|
408
|
-
*/
|
409
|
-
T& fromBack(int i) {
|
410
|
-
SkASSERT(i >= 0);
|
411
|
-
SkASSERT(i < this->count());
|
412
|
-
return fItemArray[fCount - i - 1];
|
413
|
-
}
|
414
|
-
|
415
|
-
const T& fromBack(int i) const {
|
416
|
-
SkASSERT(i >= 0);
|
417
|
-
SkASSERT(i < this->count());
|
418
|
-
return fItemArray[fCount - i - 1];
|
419
|
-
}
|
420
|
-
|
421
|
-
bool operator==(const SkTArray<T, MEM_MOVE>& right) const {
|
422
|
-
int leftCount = this->count();
|
423
|
-
if (leftCount != right.count()) {
|
424
|
-
return false;
|
425
|
-
}
|
426
|
-
for (int index = 0; index < leftCount; ++index) {
|
427
|
-
if (fItemArray[index] != right.fItemArray[index]) {
|
428
|
-
return false;
|
429
|
-
}
|
430
|
-
}
|
431
|
-
return true;
|
432
|
-
}
|
433
|
-
|
434
|
-
bool operator!=(const SkTArray<T, MEM_MOVE>& right) const {
|
435
|
-
return !(*this == right);
|
436
|
-
}
|
437
|
-
|
438
|
-
int capacity() const {
|
439
|
-
return fAllocCount;
|
440
|
-
}
|
441
|
-
|
442
|
-
protected:
|
443
|
-
/**
|
444
|
-
* Creates an empty array that will use the passed storage block until it
|
445
|
-
* is insufficiently large to hold the entire array.
|
446
|
-
*/
|
447
|
-
template <int N>
|
448
|
-
SkTArray(SkAlignedSTStorage<N,T>* storage) {
|
449
|
-
this->initWithPreallocatedStorage(0, storage->get(), N);
|
450
|
-
}
|
451
|
-
|
452
|
-
/**
|
453
|
-
* Copy a C array, using preallocated storage if preAllocCount >=
|
454
|
-
* count. Otherwise storage will only be used when array shrinks
|
455
|
-
* to fit.
|
456
|
-
*/
|
457
|
-
template <int N>
|
458
|
-
SkTArray(const T* array, int count, SkAlignedSTStorage<N,T>* storage) {
|
459
|
-
this->initWithPreallocatedStorage(count, storage->get(), N);
|
460
|
-
this->copy(array);
|
461
|
-
}
|
462
|
-
|
463
|
-
private:
|
464
|
-
// We disable Control-Flow Integrity sanitization (go/cfi) when casting item-array buffers.
|
465
|
-
// CFI flags this code as dangerous because we are casting `buffer` to a T* while the buffer's
|
466
|
-
// contents might still be uninitialized memory. When T has a vtable, this is especially risky
|
467
|
-
// because we could hypothetically access a virtual method on fItemArray and jump to an
|
468
|
-
// unpredictable location in memory. Of course, SkTArray won't actually use fItemArray in this
|
469
|
-
// way, and we don't want to construct a T before the user requests one. There's no real risk
|
470
|
-
// here, so disable CFI when doing these casts.
|
471
|
-
SK_ATTRIBUTE(no_sanitize("cfi"))
|
472
|
-
static T* TCast(void* buffer) {
|
473
|
-
return (T*)buffer;
|
474
|
-
}
|
475
|
-
|
476
|
-
void init(int count) {
|
477
|
-
fCount = SkToU32(count);
|
478
|
-
if (!count) {
|
479
|
-
fAllocCount = 0;
|
480
|
-
fItemArray = nullptr;
|
481
|
-
} else {
|
482
|
-
fAllocCount = SkToU32(std::max(count, kMinHeapAllocCount));
|
483
|
-
fItemArray = TCast(sk_malloc_throw((size_t)fAllocCount, sizeof(T)));
|
484
|
-
}
|
485
|
-
fOwnMemory = true;
|
486
|
-
fReserved = false;
|
487
|
-
}
|
488
|
-
|
489
|
-
void initWithPreallocatedStorage(int count, void* preallocStorage, int preallocCount) {
|
490
|
-
SkASSERT(count >= 0);
|
491
|
-
SkASSERT(preallocCount > 0);
|
492
|
-
SkASSERT(preallocStorage);
|
493
|
-
fCount = SkToU32(count);
|
494
|
-
fItemArray = nullptr;
|
495
|
-
fReserved = false;
|
496
|
-
if (count > preallocCount) {
|
497
|
-
fAllocCount = SkToU32(std::max(count, kMinHeapAllocCount));
|
498
|
-
fItemArray = TCast(sk_malloc_throw(fAllocCount, sizeof(T)));
|
499
|
-
fOwnMemory = true;
|
500
|
-
} else {
|
501
|
-
fAllocCount = SkToU32(preallocCount);
|
502
|
-
fItemArray = TCast(preallocStorage);
|
503
|
-
fOwnMemory = false;
|
504
|
-
}
|
505
|
-
}
|
506
|
-
|
507
|
-
/** In the following move and copy methods, 'dst' is assumed to be uninitialized raw storage.
|
508
|
-
* In the following move methods, 'src' is destroyed leaving behind uninitialized raw storage.
|
509
|
-
*/
|
510
|
-
void copy(const T* src) {
|
511
|
-
// Some types may be trivially copyable, in which case we *could* use memcopy; but
|
512
|
-
// MEM_MOVE == true implies that the type is trivially movable, and not necessarily
|
513
|
-
// trivially copyable (think sk_sp<>). So short of adding another template arg, we
|
514
|
-
// must be conservative and use copy construction.
|
515
|
-
for (int i = 0; i < this->count(); ++i) {
|
516
|
-
new (fItemArray + i) T(src[i]);
|
517
|
-
}
|
518
|
-
}
|
519
|
-
|
520
|
-
template <bool E = MEM_MOVE> std::enable_if_t<E, void> move(int dst, int src) {
|
521
|
-
memcpy(static_cast<void*>(&fItemArray[dst]),
|
522
|
-
static_cast<void*>(&fItemArray[src]),
|
523
|
-
sizeof(T));
|
524
|
-
}
|
525
|
-
template <bool E = MEM_MOVE> std::enable_if_t<E, void> move(void* dst) {
|
526
|
-
sk_careful_memcpy(dst, fItemArray, fCount * sizeof(T));
|
527
|
-
}
|
528
|
-
|
529
|
-
template <bool E = MEM_MOVE> std::enable_if_t<!E, void> move(int dst, int src) {
|
530
|
-
new (&fItemArray[dst]) T(std::move(fItemArray[src]));
|
531
|
-
fItemArray[src].~T();
|
532
|
-
}
|
533
|
-
template <bool E = MEM_MOVE> std::enable_if_t<!E, void> move(void* dst) {
|
534
|
-
for (int i = 0; i < this->count(); ++i) {
|
535
|
-
new (static_cast<char*>(dst) + sizeof(T) * (size_t)i) T(std::move(fItemArray[i]));
|
536
|
-
fItemArray[i].~T();
|
537
|
-
}
|
538
|
-
}
|
539
|
-
|
540
|
-
static constexpr int kMinHeapAllocCount = 8;
|
541
|
-
|
542
|
-
// Helper function that makes space for n objects, adjusts the count, but does not initialize
|
543
|
-
// the new objects.
|
544
|
-
void* push_back_raw(int n) {
|
545
|
-
this->checkRealloc(n, kGrowing);
|
546
|
-
void* ptr = fItemArray + fCount;
|
547
|
-
fCount += n;
|
548
|
-
return ptr;
|
549
|
-
}
|
550
|
-
|
551
|
-
void checkRealloc(int delta, ReallocType reallocType) {
|
552
|
-
SkASSERT(fCount >= 0);
|
553
|
-
SkASSERT(fAllocCount >= 0);
|
554
|
-
SkASSERT(-delta <= this->count());
|
555
|
-
|
556
|
-
// Move into 64bit math temporarily, to avoid local overflows
|
557
|
-
int64_t newCount = fCount + delta;
|
558
|
-
|
559
|
-
// We allow fAllocCount to be in the range [newCount, 3*newCount]. We also never shrink
|
560
|
-
// when we're currently using preallocated memory, would allocate less than
|
561
|
-
// kMinHeapAllocCount, or a reserve count was specified that has yet to be exceeded.
|
562
|
-
bool mustGrow = newCount > fAllocCount;
|
563
|
-
bool shouldShrink = fAllocCount > 3 * newCount && fOwnMemory && !fReserved;
|
564
|
-
if (!mustGrow && !shouldShrink) {
|
565
|
-
return;
|
566
|
-
}
|
567
|
-
|
568
|
-
int64_t newAllocCount = newCount;
|
569
|
-
if (reallocType != kExactFit) {
|
570
|
-
// Whether we're growing or shrinking, leave at least 50% extra space for future growth.
|
571
|
-
newAllocCount += ((newCount + 1) >> 1);
|
572
|
-
// Align the new allocation count to kMinHeapAllocCount.
|
573
|
-
static_assert(SkIsPow2(kMinHeapAllocCount), "min alloc count not power of two.");
|
574
|
-
newAllocCount = (newAllocCount + (kMinHeapAllocCount - 1)) & ~(kMinHeapAllocCount - 1);
|
575
|
-
}
|
576
|
-
|
577
|
-
// At small sizes the old and new alloc count can both be kMinHeapAllocCount.
|
578
|
-
if (newAllocCount == fAllocCount) {
|
579
|
-
return;
|
580
|
-
}
|
581
|
-
|
582
|
-
fAllocCount = SkToU32(Sk64_pin_to_s32(newAllocCount));
|
583
|
-
SkASSERT(fAllocCount >= newCount);
|
584
|
-
T* newItemArray = TCast(sk_malloc_throw((size_t)fAllocCount, sizeof(T)));
|
585
|
-
this->move(newItemArray);
|
586
|
-
if (fOwnMemory) {
|
587
|
-
sk_free(fItemArray);
|
588
|
-
}
|
589
|
-
fItemArray = newItemArray;
|
590
|
-
fOwnMemory = true;
|
591
|
-
fReserved = false;
|
592
|
-
}
|
593
|
-
|
594
|
-
T* fItemArray;
|
595
|
-
uint32_t fOwnMemory : 1;
|
596
|
-
uint32_t fCount : 31;
|
597
|
-
uint32_t fReserved : 1;
|
598
|
-
uint32_t fAllocCount : 31;
|
599
|
-
};
|
600
|
-
|
601
|
-
template <typename T, bool M> static inline void swap(SkTArray<T, M>& a, SkTArray<T, M>& b) {
|
602
|
-
a.swap(b);
|
603
|
-
}
|
604
|
-
|
605
|
-
template<typename T, bool MEM_MOVE> constexpr int SkTArray<T, MEM_MOVE>::kMinHeapAllocCount;
|
606
|
-
|
607
|
-
/**
|
608
|
-
* Subclass of SkTArray that contains a preallocated memory block for the array.
|
609
|
-
*/
|
610
|
-
template <int N, typename T, bool MEM_MOVE = sk_is_trivially_relocatable<T>::value>
|
611
|
-
class SkSTArray : private SkAlignedSTStorage<N,T>, public SkTArray<T, MEM_MOVE> {
|
612
|
-
private:
|
613
|
-
using STORAGE = SkAlignedSTStorage<N,T>;
|
614
|
-
using INHERITED = SkTArray<T, MEM_MOVE>;
|
615
|
-
|
616
|
-
public:
|
617
|
-
SkSTArray()
|
618
|
-
: STORAGE{}, INHERITED(static_cast<STORAGE*>(this)) {}
|
619
|
-
|
620
|
-
SkSTArray(const T* array, int count)
|
621
|
-
: STORAGE{}, INHERITED(array, count, static_cast<STORAGE*>(this)) {}
|
622
|
-
|
623
|
-
SkSTArray(std::initializer_list<T> data)
|
624
|
-
: SkSTArray(data.begin(), data.size()) {}
|
625
|
-
|
626
|
-
explicit SkSTArray(int reserveCount)
|
627
|
-
: SkSTArray() {
|
628
|
-
this->reserve_back(reserveCount);
|
629
|
-
}
|
630
|
-
|
631
|
-
SkSTArray (const SkSTArray& that) : SkSTArray() { *this = that; }
|
632
|
-
explicit SkSTArray(const INHERITED& that) : SkSTArray() { *this = that; }
|
633
|
-
SkSTArray ( SkSTArray&& that) : SkSTArray() { *this = std::move(that); }
|
634
|
-
explicit SkSTArray( INHERITED&& that) : SkSTArray() { *this = std::move(that); }
|
635
|
-
|
636
|
-
SkSTArray& operator=(const SkSTArray& that) {
|
637
|
-
INHERITED::operator=(that);
|
638
|
-
return *this;
|
639
|
-
}
|
640
|
-
SkSTArray& operator=(const INHERITED& that) {
|
641
|
-
INHERITED::operator=(that);
|
642
|
-
return *this;
|
643
|
-
}
|
644
|
-
|
645
|
-
SkSTArray& operator=(SkSTArray&& that) {
|
646
|
-
INHERITED::operator=(std::move(that));
|
647
|
-
return *this;
|
648
|
-
}
|
649
|
-
SkSTArray& operator=(INHERITED&& that) {
|
650
|
-
INHERITED::operator=(std::move(that));
|
651
|
-
return *this;
|
652
|
-
}
|
653
|
-
};
|
654
|
-
|
655
|
-
#endif
|
@@ -1,35 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright 2022 Google LLC
|
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 SkUniquePaintParamsID_DEFINED
|
9
|
-
#define SkUniquePaintParamsID_DEFINED
|
10
|
-
|
11
|
-
#include "include/core/SkTypes.h"
|
12
|
-
|
13
|
-
// This class boils down to a unique uint that can be used instead of a variable length
|
14
|
-
// key derived from a PaintParams.
|
15
|
-
class SkUniquePaintParamsID {
|
16
|
-
public:
|
17
|
-
explicit SkUniquePaintParamsID(uint32_t id) : fID(id) {
|
18
|
-
SkASSERT(id != SK_InvalidUniqueID);
|
19
|
-
}
|
20
|
-
|
21
|
-
static SkUniquePaintParamsID InvalidID() { return SkUniquePaintParamsID(); }
|
22
|
-
|
23
|
-
SkUniquePaintParamsID() : fID(SK_InvalidUniqueID) {}
|
24
|
-
|
25
|
-
bool operator==(const SkUniquePaintParamsID &that) const { return fID == that.fID; }
|
26
|
-
bool operator!=(const SkUniquePaintParamsID &that) const { return !(*this == that); }
|
27
|
-
|
28
|
-
bool isValid() const { return fID != SK_InvalidUniqueID; }
|
29
|
-
uint32_t asUInt() const { return fID; }
|
30
|
-
|
31
|
-
private:
|
32
|
-
uint32_t fID;
|
33
|
-
};
|
34
|
-
|
35
|
-
#endif // SkUniquePaintParamsID_DEFINED
|