@shopify/react-native-skia 0.1.196 → 0.1.199
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +32 -31
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +4 -2
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +3 -0
- package/cpp/api/JsiSkImage.h +1 -1
- package/cpp/api/JsiSkShaderFactory.h +4 -4
- package/cpp/api/JsiSkSurface.h +0 -1
- package/cpp/api/JsiSkSurfaceFactory.h +2 -1
- package/cpp/rnskia/RNSkView.h +20 -40
- package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +2 -2
- package/cpp/rnskia/values/RNSkReadonlyValue.h +6 -7
- package/cpp/skia/include/android/SkCanvasAndroid.h +20 -0
- package/cpp/skia/include/android/SkHeifDecoder.h +43 -0
- package/cpp/skia/include/android/SkSurfaceAndroid.h +50 -0
- package/cpp/skia/include/codec/SkAvifDecoder.h +43 -0
- package/cpp/skia/include/codec/SkBmpDecoder.h +43 -0
- package/cpp/skia/include/codec/SkCodec.h +25 -1
- package/cpp/skia/include/codec/SkGifDecoder.h +43 -0
- package/cpp/skia/include/codec/SkIcoDecoder.h +43 -0
- package/cpp/skia/include/codec/SkJpegDecoder.h +43 -0
- package/cpp/skia/include/codec/SkJpegxlDecoder.h +43 -0
- package/cpp/skia/include/codec/SkPngDecoder.h +43 -0
- package/cpp/skia/include/codec/SkRawDecoder.h +49 -0
- package/cpp/skia/include/codec/SkWbmpDecoder.h +43 -0
- package/cpp/skia/include/codec/SkWebpDecoder.h +43 -0
- package/cpp/skia/include/core/SkBBHFactory.h +5 -1
- package/cpp/skia/include/core/SkBlender.h +0 -2
- package/cpp/skia/include/core/SkCanvas.h +4 -23
- package/cpp/skia/include/core/SkColorFilter.h +14 -1
- package/cpp/skia/include/core/SkColorTable.h +59 -0
- package/cpp/skia/include/core/SkContourMeasure.h +3 -0
- package/cpp/skia/include/core/SkDeferredDisplayList.h +8 -104
- package/cpp/skia/include/core/SkDeferredDisplayListRecorder.h +8 -91
- package/cpp/skia/include/core/SkDrawable.h +5 -2
- package/cpp/skia/include/core/SkGraphics.h +7 -19
- package/cpp/skia/include/core/SkImage.h +157 -249
- package/cpp/skia/include/core/SkImageGenerator.h +0 -31
- package/cpp/skia/include/core/SkMilestone.h +1 -1
- package/cpp/skia/include/core/SkPathMeasure.h +3 -3
- package/cpp/skia/include/core/SkPictureRecorder.h +1 -1
- package/cpp/skia/include/core/SkPoint.h +5 -563
- package/cpp/skia/include/core/SkPoint3.h +1 -0
- package/cpp/skia/include/core/SkPromiseImageTexture.h +4 -30
- package/cpp/skia/include/core/SkRect.h +8 -8
- package/cpp/skia/include/core/SkSamplingOptions.h +4 -2
- package/cpp/skia/include/core/SkScalar.h +1 -1
- package/cpp/skia/include/core/SkSerialProcs.h +5 -1
- package/cpp/skia/include/core/SkShader.h +14 -21
- package/cpp/skia/include/core/SkString.h +2 -0
- package/cpp/skia/include/core/SkSurface.h +169 -701
- package/cpp/skia/include/core/SkSurfaceCharacterization.h +8 -256
- package/cpp/skia/include/core/SkTiledImageUtils.h +97 -0
- package/cpp/skia/include/core/SkTypes.h +4 -2
- package/cpp/skia/include/core/SkYUVAPixmaps.h +0 -5
- package/cpp/skia/include/effects/SkGradientShader.h +10 -1
- package/cpp/skia/include/effects/SkImageFilters.h +62 -37
- package/cpp/skia/include/effects/SkPerlinNoiseShader.h +28 -29
- package/cpp/skia/include/effects/SkRuntimeEffect.h +17 -12
- package/cpp/skia/include/gpu/GrBackendSurface.h +12 -39
- package/cpp/skia/include/gpu/GrBackendSurfaceMutableState.h +6 -0
- package/cpp/skia/include/gpu/GrContextThreadSafeProxy.h +3 -3
- package/cpp/skia/include/gpu/GrDirectContext.h +103 -3
- package/cpp/skia/include/gpu/GrRecordingContext.h +10 -19
- package/cpp/skia/include/gpu/MutableTextureState.h +4 -0
- package/cpp/skia/include/gpu/ganesh/GrExternalTextureGenerator.h +54 -0
- package/cpp/skia/include/gpu/ganesh/SkImageGanesh.h +20 -76
- package/cpp/skia/include/gpu/ganesh/SkSurfaceGanesh.h +217 -0
- package/cpp/skia/include/gpu/ganesh/mtl/SkSurfaceMetal.h +73 -0
- package/cpp/skia/include/gpu/gl/GrGLTypes.h +13 -2
- package/cpp/skia/include/gpu/graphite/BackendSemaphore.h +78 -0
- package/cpp/skia/include/gpu/graphite/BackendTexture.h +1 -0
- package/cpp/skia/include/gpu/graphite/Image.h +277 -0
- package/cpp/skia/include/gpu/graphite/ImageProvider.h +1 -1
- package/cpp/skia/include/gpu/graphite/Recording.h +1 -4
- package/cpp/skia/include/gpu/graphite/Surface.h +81 -0
- package/cpp/skia/include/gpu/graphite/TextureInfo.h +5 -7
- package/cpp/skia/include/gpu/graphite/YUVABackendTextures.h +2 -2
- package/cpp/skia/include/gpu/mock/GrMockTypes.h +23 -8
- package/cpp/skia/include/ports/SkTypeface_fontations.h +21 -0
- package/cpp/skia/include/private/SkGainmapInfo.h +2 -0
- package/cpp/skia/include/private/SkGainmapShader.h +1 -0
- package/cpp/skia/include/private/SkJpegMetadataDecoder.h +19 -1
- package/cpp/skia/include/private/SkPathRef.h +13 -15
- package/cpp/skia/include/private/SkXmp.h +53 -0
- package/cpp/skia/include/private/base/SkFeatures.h +0 -4
- package/cpp/skia/include/private/base/SkFloatingPoint.h +11 -5
- package/cpp/skia/include/private/base/SkPoint_impl.h +569 -0
- package/cpp/skia/include/private/base/SkSpan_impl.h +3 -7
- package/cpp/skia/include/private/base/SkTArray.h +11 -11
- package/cpp/skia/include/private/chromium/GrDeferredDisplayList.h +120 -0
- package/cpp/skia/include/private/chromium/GrDeferredDisplayListRecorder.h +98 -0
- package/cpp/skia/include/private/chromium/GrPromiseImageTexture.h +43 -0
- package/cpp/skia/include/private/chromium/GrSurfaceCharacterization.h +215 -0
- package/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h +6 -6
- package/cpp/skia/include/private/chromium/SkImageChromium.h +104 -0
- package/cpp/skia/include/private/chromium/Slug.h +7 -3
- package/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +7 -3
- package/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h +2 -0
- package/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +3 -2
- package/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h +10 -2
- package/cpp/skia/include/{gpu → private/gpu}/ganesh/GrTextureGenerator.h +2 -13
- package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +1 -1
- package/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h +7 -0
- package/cpp/skia/include/private/gpu/graphite/MtlGraphiteTypesPriv.h +19 -6
- package/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h +13 -0
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan.h +0 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_android.h +14 -1
- package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_core.h +999 -79
- package/cpp/skia/modules/skcms/src/Transform_inl.h +36 -236
- package/cpp/skia/modules/skparagraph/include/Paragraph.h +2 -0
- package/cpp/skia/modules/skparagraph/include/ParagraphBuilder.h +16 -0
- package/cpp/skia/modules/skparagraph/include/TextStyle.h +6 -2
- package/cpp/skia/modules/skresources/include/SkResources.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGCircle.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGClipPath.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGContainer.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGDOM.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGDefs.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGEllipse.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFe.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeBlend.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeColorMatrix.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeComposite.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeDisplacementMap.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeFlood.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeGaussianBlur.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeImage.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeLightSource.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeLighting.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeOffset.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFeTurbulence.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGFilter.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGG.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGGradient.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGHiddenContainer.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGImage.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGLine.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGLinearGradient.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGMask.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGNode.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGPath.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGPattern.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGPoly.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGRadialGradient.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGRect.h +1 -1
- 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/SkSVGShape.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGStop.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGText.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGTransformableNode.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGTypes.h +21 -21
- package/cpp/skia/modules/svg/include/SkSVGUse.h +1 -1
- package/cpp/skia/modules/svg/include/SkSVGValue.h +2 -2
- package/cpp/skia/{include/private → src/core}/SkChecksum.h +32 -17
- package/cpp/skia/src/core/SkTHash.h +1 -1
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +3 -1
- package/ios/RNSkia-iOS/SkiaMetalRenderer.mm +3 -1
- package/lib/commonjs/renderer/Canvas.js +24 -13
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/core/Data.d.ts +2 -2
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/commonjs/skia/core/RRect.js +5 -1
- package/lib/commonjs/skia/core/RRect.js.map +1 -1
- package/lib/commonjs/skia/core/Rect.js +32 -6
- package/lib/commonjs/skia/core/Rect.js.map +1 -1
- package/lib/commonjs/skia/types/Color.js.map +1 -1
- package/lib/commonjs/skia/types/JsiInstance.d.ts +2 -4
- package/lib/commonjs/skia/types/JsiInstance.js.map +1 -1
- package/lib/module/renderer/Canvas.js +25 -14
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/core/Data.d.ts +2 -2
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/RRect.js +5 -1
- package/lib/module/skia/core/RRect.js.map +1 -1
- package/lib/module/skia/core/Rect.js +32 -6
- package/lib/module/skia/core/Rect.js.map +1 -1
- package/lib/module/skia/types/Color.js.map +1 -1
- package/lib/module/skia/types/JsiInstance.d.ts +2 -4
- package/lib/module/skia/types/JsiInstance.js.map +1 -1
- package/lib/typescript/src/skia/core/Data.d.ts +2 -2
- package/lib/typescript/src/skia/types/JsiInstance.d.ts +2 -4
- 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/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/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/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/libsvg.a +0 -0
- 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/Info.plist +5 -5
- 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/Info.plist +5 -5
- 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 +3 -4
- package/src/renderer/Canvas.tsx +25 -19
- package/src/skia/core/Data.ts +3 -3
- package/src/skia/core/RRect.tsx +4 -2
- package/src/skia/core/Rect.ts +29 -12
- package/src/skia/types/Color.ts +1 -1
- package/src/skia/types/JsiInstance.ts +2 -5
- package/cpp/skia/include/effects/SkTableColorFilter.h +0 -29
- package/cpp/skia/include/private/SkOpts_spi.h +0 -23
- package/cpp/skia/include/private/SkSpinlock.h +0 -57
- package/cpp/skia/include/private/chromium/GrSlug.h +0 -16
- package/scripts/install-npm.js +0 -33
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2023 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 SkXmp_DEFINED
|
9
|
+
#define SkXmp_DEFINED
|
10
|
+
|
11
|
+
#include "include/core/SkRefCnt.h"
|
12
|
+
#include "include/private/base/SkAPI.h"
|
13
|
+
|
14
|
+
class SkData;
|
15
|
+
struct SkGainmapInfo;
|
16
|
+
|
17
|
+
#include <cstddef>
|
18
|
+
#include <memory>
|
19
|
+
|
20
|
+
/*
|
21
|
+
* An interface to extract information from XMP metadata.
|
22
|
+
*/
|
23
|
+
class SK_API SkXmp {
|
24
|
+
public:
|
25
|
+
SkXmp() = default;
|
26
|
+
virtual ~SkXmp() = default;
|
27
|
+
// Make noncopyable
|
28
|
+
SkXmp(const SkXmp&) = delete;
|
29
|
+
SkXmp& operator= (const SkXmp&) = delete;
|
30
|
+
|
31
|
+
// Create from XMP data.
|
32
|
+
static std::unique_ptr<SkXmp> Make(sk_sp<SkData> xmpData);
|
33
|
+
// Create from standard XMP + extended XMP data, see XMP Specification Part 3: Storage in files,
|
34
|
+
// Section 1.1.3.1: Extended XMP in JPEG
|
35
|
+
static std::unique_ptr<SkXmp> Make(sk_sp<SkData> xmpStandard, sk_sp<SkData> xmpExtended);
|
36
|
+
|
37
|
+
// Extract HDRGM gainmap parameters.
|
38
|
+
virtual bool getGainmapInfoHDRGM(SkGainmapInfo* info) const = 0;
|
39
|
+
|
40
|
+
// Extract HDRGainMap gainmap parameters.
|
41
|
+
virtual bool getGainmapInfoHDRGainMap(SkGainmapInfo* info) const = 0;
|
42
|
+
|
43
|
+
// If this includes GContainer metadata and the GContainer contains an item with semantic
|
44
|
+
// GainMap and Mime of image/jpeg, then return true, and populate |offset| and |size| with
|
45
|
+
// that item's offset (from the end of the primary JPEG image's EndOfImage), and the size of
|
46
|
+
// the gainmap.
|
47
|
+
virtual bool getContainerGainmapLocation(size_t* offset, size_t* size) const = 0;
|
48
|
+
|
49
|
+
// Return the GUID of an Extended XMP if present, or null otherwise.
|
50
|
+
virtual const char* getExtendedXmpGuid() const = 0;
|
51
|
+
};
|
52
|
+
|
53
|
+
#endif
|
@@ -49,6 +49,10 @@ static inline float sk_float_pow(float base, float exp) {
|
|
49
49
|
#define sk_float_exp(x) expf(x)
|
50
50
|
#define sk_float_log(x) logf(x)
|
51
51
|
|
52
|
+
constexpr int sk_float_sgn(float x) {
|
53
|
+
return (0.0f < x) - (x < 0.0f);
|
54
|
+
}
|
55
|
+
|
52
56
|
constexpr float sk_float_degrees_to_radians(float degrees) {
|
53
57
|
return degrees * (SK_FloatPI / 180);
|
54
58
|
}
|
@@ -222,10 +226,12 @@ static inline float sk_fmaf(float f, float m, float a) {
|
|
222
226
|
// Returns true iff the provided number is within a small epsilon of 0.
|
223
227
|
bool sk_double_nearly_zero(double a);
|
224
228
|
|
225
|
-
//
|
226
|
-
//
|
227
|
-
//
|
228
|
-
//
|
229
|
-
|
229
|
+
// Compare two doubles and return true if they are within maxUlpsDiff of each other.
|
230
|
+
// * nan as a or b - returns false.
|
231
|
+
// * infinity, infinity or -infinity, -infinity - returns true.
|
232
|
+
// * infinity and any other number - returns false.
|
233
|
+
//
|
234
|
+
// ulp is an initialism for Units in the Last Place.
|
235
|
+
bool sk_doubles_nearly_equal_ulps(double a, double b, uint8_t maxUlpsDiff=16);
|
230
236
|
|
231
237
|
#endif
|
@@ -0,0 +1,569 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2006 The Android Open Source Project
|
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 SkPoint_DEFINED
|
9
|
+
#define SkPoint_DEFINED
|
10
|
+
|
11
|
+
#include "include/private/base/SkAPI.h"
|
12
|
+
#include "include/private/base/SkAssert.h"
|
13
|
+
#include "include/private/base/SkSafe32.h"
|
14
|
+
|
15
|
+
#include <cmath>
|
16
|
+
#include <cstdint>
|
17
|
+
|
18
|
+
struct SkIPoint;
|
19
|
+
|
20
|
+
/** SkIVector provides an alternative name for SkIPoint. SkIVector and SkIPoint
|
21
|
+
can be used interchangeably for all purposes.
|
22
|
+
*/
|
23
|
+
typedef SkIPoint SkIVector;
|
24
|
+
|
25
|
+
/** \struct SkIPoint
|
26
|
+
SkIPoint holds two 32-bit integer coordinates.
|
27
|
+
*/
|
28
|
+
struct SkIPoint {
|
29
|
+
int32_t fX; //!< x-axis value
|
30
|
+
int32_t fY; //!< y-axis value
|
31
|
+
|
32
|
+
/** Sets fX to x, fY to y.
|
33
|
+
|
34
|
+
@param x integer x-axis value of constructed SkIPoint
|
35
|
+
@param y integer y-axis value of constructed SkIPoint
|
36
|
+
@return SkIPoint (x, y)
|
37
|
+
*/
|
38
|
+
static constexpr SkIPoint Make(int32_t x, int32_t y) {
|
39
|
+
return {x, y};
|
40
|
+
}
|
41
|
+
|
42
|
+
/** Returns x-axis value of SkIPoint.
|
43
|
+
|
44
|
+
@return fX
|
45
|
+
*/
|
46
|
+
constexpr int32_t x() const { return fX; }
|
47
|
+
|
48
|
+
/** Returns y-axis value of SkIPoint.
|
49
|
+
|
50
|
+
@return fY
|
51
|
+
*/
|
52
|
+
constexpr int32_t y() const { return fY; }
|
53
|
+
|
54
|
+
/** Returns true if fX and fY are both zero.
|
55
|
+
|
56
|
+
@return true if fX is zero and fY is zero
|
57
|
+
*/
|
58
|
+
bool isZero() const { return (fX | fY) == 0; }
|
59
|
+
|
60
|
+
/** Sets fX to x and fY to y.
|
61
|
+
|
62
|
+
@param x new value for fX
|
63
|
+
@param y new value for fY
|
64
|
+
*/
|
65
|
+
void set(int32_t x, int32_t y) {
|
66
|
+
fX = x;
|
67
|
+
fY = y;
|
68
|
+
}
|
69
|
+
|
70
|
+
/** Returns SkIPoint changing the signs of fX and fY.
|
71
|
+
|
72
|
+
@return SkIPoint as (-fX, -fY)
|
73
|
+
*/
|
74
|
+
SkIPoint operator-() const {
|
75
|
+
return {-fX, -fY};
|
76
|
+
}
|
77
|
+
|
78
|
+
/** Offsets SkIPoint by ivector v. Sets SkIPoint to (fX + v.fX, fY + v.fY).
|
79
|
+
|
80
|
+
@param v ivector to add
|
81
|
+
*/
|
82
|
+
void operator+=(const SkIVector& v) {
|
83
|
+
fX = Sk32_sat_add(fX, v.fX);
|
84
|
+
fY = Sk32_sat_add(fY, v.fY);
|
85
|
+
}
|
86
|
+
|
87
|
+
/** Subtracts ivector v from SkIPoint. Sets SkIPoint to: (fX - v.fX, fY - v.fY).
|
88
|
+
|
89
|
+
@param v ivector to subtract
|
90
|
+
*/
|
91
|
+
void operator-=(const SkIVector& v) {
|
92
|
+
fX = Sk32_sat_sub(fX, v.fX);
|
93
|
+
fY = Sk32_sat_sub(fY, v.fY);
|
94
|
+
}
|
95
|
+
|
96
|
+
/** Returns true if SkIPoint is equivalent to SkIPoint constructed from (x, y).
|
97
|
+
|
98
|
+
@param x value compared with fX
|
99
|
+
@param y value compared with fY
|
100
|
+
@return true if SkIPoint equals (x, y)
|
101
|
+
*/
|
102
|
+
bool equals(int32_t x, int32_t y) const {
|
103
|
+
return fX == x && fY == y;
|
104
|
+
}
|
105
|
+
|
106
|
+
/** Returns true if a is equivalent to b.
|
107
|
+
|
108
|
+
@param a SkIPoint to compare
|
109
|
+
@param b SkIPoint to compare
|
110
|
+
@return true if a.fX == b.fX and a.fY == b.fY
|
111
|
+
*/
|
112
|
+
friend bool operator==(const SkIPoint& a, const SkIPoint& b) {
|
113
|
+
return a.fX == b.fX && a.fY == b.fY;
|
114
|
+
}
|
115
|
+
|
116
|
+
/** Returns true if a is not equivalent to b.
|
117
|
+
|
118
|
+
@param a SkIPoint to compare
|
119
|
+
@param b SkIPoint to compare
|
120
|
+
@return true if a.fX != b.fX or a.fY != b.fY
|
121
|
+
*/
|
122
|
+
friend bool operator!=(const SkIPoint& a, const SkIPoint& b) {
|
123
|
+
return a.fX != b.fX || a.fY != b.fY;
|
124
|
+
}
|
125
|
+
|
126
|
+
/** Returns ivector from b to a; computed as (a.fX - b.fX, a.fY - b.fY).
|
127
|
+
|
128
|
+
Can also be used to subtract ivector from ivector, returning ivector.
|
129
|
+
|
130
|
+
@param a SkIPoint or ivector to subtract from
|
131
|
+
@param b ivector to subtract
|
132
|
+
@return ivector from b to a
|
133
|
+
*/
|
134
|
+
friend SkIVector operator-(const SkIPoint& a, const SkIPoint& b) {
|
135
|
+
return { Sk32_sat_sub(a.fX, b.fX), Sk32_sat_sub(a.fY, b.fY) };
|
136
|
+
}
|
137
|
+
|
138
|
+
/** Returns SkIPoint resulting from SkIPoint a offset by ivector b, computed as:
|
139
|
+
(a.fX + b.fX, a.fY + b.fY).
|
140
|
+
|
141
|
+
Can also be used to offset SkIPoint b by ivector a, returning SkIPoint.
|
142
|
+
Can also be used to add ivector to ivector, returning ivector.
|
143
|
+
|
144
|
+
@param a SkIPoint or ivector to add to
|
145
|
+
@param b SkIPoint or ivector to add
|
146
|
+
@return SkIPoint equal to a offset by b
|
147
|
+
*/
|
148
|
+
friend SkIPoint operator+(const SkIPoint& a, const SkIVector& b) {
|
149
|
+
return { Sk32_sat_add(a.fX, b.fX), Sk32_sat_add(a.fY, b.fY) };
|
150
|
+
}
|
151
|
+
};
|
152
|
+
|
153
|
+
struct SkPoint;
|
154
|
+
|
155
|
+
/** SkVector provides an alternative name for SkPoint. SkVector and SkPoint can
|
156
|
+
be used interchangeably for all purposes.
|
157
|
+
*/
|
158
|
+
typedef SkPoint SkVector;
|
159
|
+
|
160
|
+
/** \struct SkPoint
|
161
|
+
SkPoint holds two 32-bit floating point coordinates.
|
162
|
+
*/
|
163
|
+
struct SK_API SkPoint {
|
164
|
+
float fX; //!< x-axis value
|
165
|
+
float fY; //!< y-axis value
|
166
|
+
|
167
|
+
/** Sets fX to x, fY to y. Used both to set SkPoint and vector.
|
168
|
+
|
169
|
+
@param x float x-axis value of constructed SkPoint or vector
|
170
|
+
@param y float y-axis value of constructed SkPoint or vector
|
171
|
+
@return SkPoint (x, y)
|
172
|
+
*/
|
173
|
+
static constexpr SkPoint Make(float x, float y) {
|
174
|
+
return {x, y};
|
175
|
+
}
|
176
|
+
|
177
|
+
/** Returns x-axis value of SkPoint or vector.
|
178
|
+
|
179
|
+
@return fX
|
180
|
+
*/
|
181
|
+
constexpr float x() const { return fX; }
|
182
|
+
|
183
|
+
/** Returns y-axis value of SkPoint or vector.
|
184
|
+
|
185
|
+
@return fY
|
186
|
+
*/
|
187
|
+
constexpr float y() const { return fY; }
|
188
|
+
|
189
|
+
/** Returns true if fX and fY are both zero.
|
190
|
+
|
191
|
+
@return true if fX is zero and fY is zero
|
192
|
+
*/
|
193
|
+
bool isZero() const { return (0 == fX) & (0 == fY); }
|
194
|
+
|
195
|
+
/** Sets fX to x and fY to y.
|
196
|
+
|
197
|
+
@param x new value for fX
|
198
|
+
@param y new value for fY
|
199
|
+
*/
|
200
|
+
void set(float x, float y) {
|
201
|
+
fX = x;
|
202
|
+
fY = y;
|
203
|
+
}
|
204
|
+
|
205
|
+
/** Sets fX to x and fY to y, promoting integers to float values.
|
206
|
+
|
207
|
+
Assigning a large integer value directly to fX or fY may cause a compiler
|
208
|
+
error, triggered by narrowing conversion of int to float. This safely
|
209
|
+
casts x and y to avoid the error.
|
210
|
+
|
211
|
+
@param x new value for fX
|
212
|
+
@param y new value for fY
|
213
|
+
*/
|
214
|
+
void iset(int32_t x, int32_t y) {
|
215
|
+
fX = static_cast<float>(x);
|
216
|
+
fY = static_cast<float>(y);
|
217
|
+
}
|
218
|
+
|
219
|
+
/** Sets fX to p.fX and fY to p.fY, promoting integers to float values.
|
220
|
+
|
221
|
+
Assigning an SkIPoint containing a large integer value directly to fX or fY may
|
222
|
+
cause a compiler error, triggered by narrowing conversion of int to float.
|
223
|
+
This safely casts p.fX and p.fY to avoid the error.
|
224
|
+
|
225
|
+
@param p SkIPoint members promoted to float
|
226
|
+
*/
|
227
|
+
void iset(const SkIPoint& p) {
|
228
|
+
fX = static_cast<float>(p.fX);
|
229
|
+
fY = static_cast<float>(p.fY);
|
230
|
+
}
|
231
|
+
|
232
|
+
/** Sets fX to absolute value of pt.fX; and fY to absolute value of pt.fY.
|
233
|
+
|
234
|
+
@param pt members providing magnitude for fX and fY
|
235
|
+
*/
|
236
|
+
void setAbs(const SkPoint& pt) {
|
237
|
+
fX = std::abs(pt.fX);
|
238
|
+
fY = std::abs(pt.fY);
|
239
|
+
}
|
240
|
+
|
241
|
+
/** Adds offset to each SkPoint in points array with count entries.
|
242
|
+
|
243
|
+
@param points SkPoint array
|
244
|
+
@param count entries in array
|
245
|
+
@param offset vector added to points
|
246
|
+
*/
|
247
|
+
static void Offset(SkPoint points[], int count, const SkVector& offset) {
|
248
|
+
Offset(points, count, offset.fX, offset.fY);
|
249
|
+
}
|
250
|
+
|
251
|
+
/** Adds offset (dx, dy) to each SkPoint in points array of length count.
|
252
|
+
|
253
|
+
@param points SkPoint array
|
254
|
+
@param count entries in array
|
255
|
+
@param dx added to fX in points
|
256
|
+
@param dy added to fY in points
|
257
|
+
*/
|
258
|
+
static void Offset(SkPoint points[], int count, float dx, float dy) {
|
259
|
+
for (int i = 0; i < count; ++i) {
|
260
|
+
points[i].offset(dx, dy);
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
/** Adds offset (dx, dy) to SkPoint.
|
265
|
+
|
266
|
+
@param dx added to fX
|
267
|
+
@param dy added to fY
|
268
|
+
*/
|
269
|
+
void offset(float dx, float dy) {
|
270
|
+
fX += dx;
|
271
|
+
fY += dy;
|
272
|
+
}
|
273
|
+
|
274
|
+
/** Returns the Euclidean distance from origin, computed as:
|
275
|
+
|
276
|
+
sqrt(fX * fX + fY * fY)
|
277
|
+
|
278
|
+
.
|
279
|
+
|
280
|
+
@return straight-line distance to origin
|
281
|
+
*/
|
282
|
+
float length() const { return SkPoint::Length(fX, fY); }
|
283
|
+
|
284
|
+
/** Returns the Euclidean distance from origin, computed as:
|
285
|
+
|
286
|
+
sqrt(fX * fX + fY * fY)
|
287
|
+
|
288
|
+
.
|
289
|
+
|
290
|
+
@return straight-line distance to origin
|
291
|
+
*/
|
292
|
+
float distanceToOrigin() const { return this->length(); }
|
293
|
+
|
294
|
+
/** Scales (fX, fY) so that length() returns one, while preserving ratio of fX to fY,
|
295
|
+
if possible. If prior length is nearly zero, sets vector to (0, 0) and returns
|
296
|
+
false; otherwise returns true.
|
297
|
+
|
298
|
+
@return true if former length is not zero or nearly zero
|
299
|
+
|
300
|
+
example: https://fiddle.skia.org/c/@Point_normalize_2
|
301
|
+
*/
|
302
|
+
bool normalize();
|
303
|
+
|
304
|
+
/** Sets vector to (x, y) scaled so length() returns one, and so that
|
305
|
+
(fX, fY) is proportional to (x, y). If (x, y) length is nearly zero,
|
306
|
+
sets vector to (0, 0) and returns false; otherwise returns true.
|
307
|
+
|
308
|
+
@param x proportional value for fX
|
309
|
+
@param y proportional value for fY
|
310
|
+
@return true if (x, y) length is not zero or nearly zero
|
311
|
+
|
312
|
+
example: https://fiddle.skia.org/c/@Point_setNormalize
|
313
|
+
*/
|
314
|
+
bool setNormalize(float x, float y);
|
315
|
+
|
316
|
+
/** Scales vector so that distanceToOrigin() returns length, if possible. If former
|
317
|
+
length is nearly zero, sets vector to (0, 0) and return false; otherwise returns
|
318
|
+
true.
|
319
|
+
|
320
|
+
@param length straight-line distance to origin
|
321
|
+
@return true if former length is not zero or nearly zero
|
322
|
+
|
323
|
+
example: https://fiddle.skia.org/c/@Point_setLength
|
324
|
+
*/
|
325
|
+
bool setLength(float length);
|
326
|
+
|
327
|
+
/** Sets vector to (x, y) scaled to length, if possible. If former
|
328
|
+
length is nearly zero, sets vector to (0, 0) and return false; otherwise returns
|
329
|
+
true.
|
330
|
+
|
331
|
+
@param x proportional value for fX
|
332
|
+
@param y proportional value for fY
|
333
|
+
@param length straight-line distance to origin
|
334
|
+
@return true if (x, y) length is not zero or nearly zero
|
335
|
+
|
336
|
+
example: https://fiddle.skia.org/c/@Point_setLength_2
|
337
|
+
*/
|
338
|
+
bool setLength(float x, float y, float length);
|
339
|
+
|
340
|
+
/** Sets dst to SkPoint times scale. dst may be SkPoint to modify SkPoint in place.
|
341
|
+
|
342
|
+
@param scale factor to multiply SkPoint by
|
343
|
+
@param dst storage for scaled SkPoint
|
344
|
+
|
345
|
+
example: https://fiddle.skia.org/c/@Point_scale
|
346
|
+
*/
|
347
|
+
void scale(float scale, SkPoint* dst) const;
|
348
|
+
|
349
|
+
/** Scales SkPoint in place by scale.
|
350
|
+
|
351
|
+
@param value factor to multiply SkPoint by
|
352
|
+
*/
|
353
|
+
void scale(float value) { this->scale(value, this); }
|
354
|
+
|
355
|
+
/** Changes the sign of fX and fY.
|
356
|
+
*/
|
357
|
+
void negate() {
|
358
|
+
fX = -fX;
|
359
|
+
fY = -fY;
|
360
|
+
}
|
361
|
+
|
362
|
+
/** Returns SkPoint changing the signs of fX and fY.
|
363
|
+
|
364
|
+
@return SkPoint as (-fX, -fY)
|
365
|
+
*/
|
366
|
+
SkPoint operator-() const {
|
367
|
+
return {-fX, -fY};
|
368
|
+
}
|
369
|
+
|
370
|
+
/** Adds vector v to SkPoint. Sets SkPoint to: (fX + v.fX, fY + v.fY).
|
371
|
+
|
372
|
+
@param v vector to add
|
373
|
+
*/
|
374
|
+
void operator+=(const SkVector& v) {
|
375
|
+
fX += v.fX;
|
376
|
+
fY += v.fY;
|
377
|
+
}
|
378
|
+
|
379
|
+
/** Subtracts vector v from SkPoint. Sets SkPoint to: (fX - v.fX, fY - v.fY).
|
380
|
+
|
381
|
+
@param v vector to subtract
|
382
|
+
*/
|
383
|
+
void operator-=(const SkVector& v) {
|
384
|
+
fX -= v.fX;
|
385
|
+
fY -= v.fY;
|
386
|
+
}
|
387
|
+
|
388
|
+
/** Returns SkPoint multiplied by scale.
|
389
|
+
|
390
|
+
@param scale float to multiply by
|
391
|
+
@return SkPoint as (fX * scale, fY * scale)
|
392
|
+
*/
|
393
|
+
SkPoint operator*(float scale) const {
|
394
|
+
return {fX * scale, fY * scale};
|
395
|
+
}
|
396
|
+
|
397
|
+
/** Multiplies SkPoint by scale. Sets SkPoint to: (fX * scale, fY * scale).
|
398
|
+
|
399
|
+
@param scale float to multiply by
|
400
|
+
@return reference to SkPoint
|
401
|
+
*/
|
402
|
+
SkPoint& operator*=(float scale) {
|
403
|
+
fX *= scale;
|
404
|
+
fY *= scale;
|
405
|
+
return *this;
|
406
|
+
}
|
407
|
+
|
408
|
+
/** Returns true if both fX and fY are measurable values.
|
409
|
+
|
410
|
+
@return true for values other than infinities and NaN
|
411
|
+
*/
|
412
|
+
bool isFinite() const {
|
413
|
+
float accum = 0;
|
414
|
+
accum *= fX;
|
415
|
+
accum *= fY;
|
416
|
+
|
417
|
+
// accum is either NaN or it is finite (zero).
|
418
|
+
SkASSERT(0 == accum || std::isnan(accum));
|
419
|
+
|
420
|
+
// value==value will be true iff value is not NaN
|
421
|
+
// TODO: is it faster to say !accum or accum==accum?
|
422
|
+
return !std::isnan(accum);
|
423
|
+
}
|
424
|
+
|
425
|
+
/** Returns true if SkPoint is equivalent to SkPoint constructed from (x, y).
|
426
|
+
|
427
|
+
@param x value compared with fX
|
428
|
+
@param y value compared with fY
|
429
|
+
@return true if SkPoint equals (x, y)
|
430
|
+
*/
|
431
|
+
bool equals(float x, float y) const {
|
432
|
+
return fX == x && fY == y;
|
433
|
+
}
|
434
|
+
|
435
|
+
/** Returns true if a is equivalent to b.
|
436
|
+
|
437
|
+
@param a SkPoint to compare
|
438
|
+
@param b SkPoint to compare
|
439
|
+
@return true if a.fX == b.fX and a.fY == b.fY
|
440
|
+
*/
|
441
|
+
friend bool operator==(const SkPoint& a, const SkPoint& b) {
|
442
|
+
return a.fX == b.fX && a.fY == b.fY;
|
443
|
+
}
|
444
|
+
|
445
|
+
/** Returns true if a is not equivalent to b.
|
446
|
+
|
447
|
+
@param a SkPoint to compare
|
448
|
+
@param b SkPoint to compare
|
449
|
+
@return true if a.fX != b.fX or a.fY != b.fY
|
450
|
+
*/
|
451
|
+
friend bool operator!=(const SkPoint& a, const SkPoint& b) {
|
452
|
+
return a.fX != b.fX || a.fY != b.fY;
|
453
|
+
}
|
454
|
+
|
455
|
+
/** Returns vector from b to a, computed as (a.fX - b.fX, a.fY - b.fY).
|
456
|
+
|
457
|
+
Can also be used to subtract vector from SkPoint, returning SkPoint.
|
458
|
+
Can also be used to subtract vector from vector, returning vector.
|
459
|
+
|
460
|
+
@param a SkPoint to subtract from
|
461
|
+
@param b SkPoint to subtract
|
462
|
+
@return vector from b to a
|
463
|
+
*/
|
464
|
+
friend SkVector operator-(const SkPoint& a, const SkPoint& b) {
|
465
|
+
return {a.fX - b.fX, a.fY - b.fY};
|
466
|
+
}
|
467
|
+
|
468
|
+
/** Returns SkPoint resulting from SkPoint a offset by vector b, computed as:
|
469
|
+
(a.fX + b.fX, a.fY + b.fY).
|
470
|
+
|
471
|
+
Can also be used to offset SkPoint b by vector a, returning SkPoint.
|
472
|
+
Can also be used to add vector to vector, returning vector.
|
473
|
+
|
474
|
+
@param a SkPoint or vector to add to
|
475
|
+
@param b SkPoint or vector to add
|
476
|
+
@return SkPoint equal to a offset by b
|
477
|
+
*/
|
478
|
+
friend SkPoint operator+(const SkPoint& a, const SkVector& b) {
|
479
|
+
return {a.fX + b.fX, a.fY + b.fY};
|
480
|
+
}
|
481
|
+
|
482
|
+
/** Returns the Euclidean distance from origin, computed as:
|
483
|
+
|
484
|
+
sqrt(x * x + y * y)
|
485
|
+
|
486
|
+
.
|
487
|
+
|
488
|
+
@param x component of length
|
489
|
+
@param y component of length
|
490
|
+
@return straight-line distance to origin
|
491
|
+
|
492
|
+
example: https://fiddle.skia.org/c/@Point_Length
|
493
|
+
*/
|
494
|
+
static float Length(float x, float y);
|
495
|
+
|
496
|
+
/** Scales (vec->fX, vec->fY) so that length() returns one, while preserving ratio of vec->fX
|
497
|
+
to vec->fY, if possible. If original length is nearly zero, sets vec to (0, 0) and returns
|
498
|
+
zero; otherwise, returns length of vec before vec is scaled.
|
499
|
+
|
500
|
+
Returned prior length may be INFINITY if it can not be represented by float.
|
501
|
+
|
502
|
+
Note that normalize() is faster if prior length is not required.
|
503
|
+
|
504
|
+
@param vec normalized to unit length
|
505
|
+
@return original vec length
|
506
|
+
|
507
|
+
example: https://fiddle.skia.org/c/@Point_Normalize
|
508
|
+
*/
|
509
|
+
static float Normalize(SkVector* vec);
|
510
|
+
|
511
|
+
/** Returns the Euclidean distance between a and b.
|
512
|
+
|
513
|
+
@param a line end point
|
514
|
+
@param b line end point
|
515
|
+
@return straight-line distance from a to b
|
516
|
+
*/
|
517
|
+
static float Distance(const SkPoint& a, const SkPoint& b) {
|
518
|
+
return Length(a.fX - b.fX, a.fY - b.fY);
|
519
|
+
}
|
520
|
+
|
521
|
+
/** Returns the dot product of vector a and vector b.
|
522
|
+
|
523
|
+
@param a left side of dot product
|
524
|
+
@param b right side of dot product
|
525
|
+
@return product of input magnitudes and cosine of the angle between them
|
526
|
+
*/
|
527
|
+
static float DotProduct(const SkVector& a, const SkVector& b) {
|
528
|
+
return a.fX * b.fX + a.fY * b.fY;
|
529
|
+
}
|
530
|
+
|
531
|
+
/** Returns the cross product of vector a and vector b.
|
532
|
+
|
533
|
+
a and b form three-dimensional vectors with z-axis value equal to zero. The
|
534
|
+
cross product is a three-dimensional vector with x-axis and y-axis values equal
|
535
|
+
to zero. The cross product z-axis component is returned.
|
536
|
+
|
537
|
+
@param a left side of cross product
|
538
|
+
@param b right side of cross product
|
539
|
+
@return area spanned by vectors signed by angle direction
|
540
|
+
*/
|
541
|
+
static float CrossProduct(const SkVector& a, const SkVector& b) {
|
542
|
+
return a.fX * b.fY - a.fY * b.fX;
|
543
|
+
}
|
544
|
+
|
545
|
+
/** Returns the cross product of vector and vec.
|
546
|
+
|
547
|
+
Vector and vec form three-dimensional vectors with z-axis value equal to zero.
|
548
|
+
The cross product is a three-dimensional vector with x-axis and y-axis values
|
549
|
+
equal to zero. The cross product z-axis component is returned.
|
550
|
+
|
551
|
+
@param vec right side of cross product
|
552
|
+
@return area spanned by vectors signed by angle direction
|
553
|
+
*/
|
554
|
+
float cross(const SkVector& vec) const {
|
555
|
+
return CrossProduct(*this, vec);
|
556
|
+
}
|
557
|
+
|
558
|
+
/** Returns the dot product of vector and vector vec.
|
559
|
+
|
560
|
+
@param vec right side of dot product
|
561
|
+
@return product of input magnitudes and cosine of the angle between them
|
562
|
+
*/
|
563
|
+
float dot(const SkVector& vec) const {
|
564
|
+
return DotProduct(*this, vec);
|
565
|
+
}
|
566
|
+
|
567
|
+
};
|
568
|
+
|
569
|
+
#endif
|
@@ -75,7 +75,7 @@ public:
|
|
75
75
|
constexpr SkSpan(const SkSpan& o) = default;
|
76
76
|
template<size_t N> constexpr SkSpan(T(&a)[N]) : SkSpan(a, N) { }
|
77
77
|
template<typename Container>
|
78
|
-
constexpr SkSpan(Container
|
78
|
+
constexpr SkSpan(Container&& c) : SkSpan(std::data(c), std::size(c)) { }
|
79
79
|
SkSpan(std::initializer_list<T> il SK_CHECK_IL_LIFETIME)
|
80
80
|
: SkSpan(std::data(il), std::size(il)) {}
|
81
81
|
|
@@ -119,11 +119,7 @@ private:
|
|
119
119
|
};
|
120
120
|
|
121
121
|
template <typename Container>
|
122
|
-
SkSpan(Container
|
123
|
-
SkSpan<std::remove_pointer_t<decltype(std::data(std::declval<Container
|
124
|
-
|
125
|
-
template <typename T>
|
126
|
-
SkSpan(std::initializer_list<T>) ->
|
127
|
-
SkSpan<std::remove_pointer_t<decltype(std::data(std::declval<std::initializer_list<T>>()))>>;
|
122
|
+
SkSpan(Container&&) ->
|
123
|
+
SkSpan<std::remove_pointer_t<decltype(std::data(std::declval<Container>()))>>;
|
128
124
|
|
129
125
|
#endif // SkSpan_DEFINED
|