@shopify/react-native-skia 2.0.7 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +20 -1
- package/cpp/api/JsiSkApi.h +3 -0
- package/cpp/api/JsiSkImageFilterFactory.h +478 -39
- package/cpp/api/JsiSkSkottie.h +590 -0
- package/cpp/api/JsiSkottieFactory.h +65 -0
- package/cpp/api/recorder/Command.h +1 -0
- package/cpp/api/recorder/Convertor.h +16 -0
- package/cpp/api/recorder/Drawings.h +23 -0
- package/cpp/api/recorder/JsiRecorder.h +6 -0
- package/cpp/api/recorder/RNRecorder.h +9 -0
- package/cpp/api/third_party/SkottieUtils.cpp +333 -0
- package/cpp/api/third_party/SkottieUtils.h +172 -0
- package/cpp/skia/modules/jsonreader/SkJSONReader.cpp +980 -0
- package/cpp/skia/modules/jsonreader/SkJSONReader.h +389 -0
- package/cpp/skia/modules/skottie/include/ExternalLayer.h +56 -0
- package/cpp/skia/modules/skottie/include/Skottie.h +313 -0
- package/cpp/skia/modules/skottie/include/SkottieProperty.h +190 -0
- package/cpp/skia/modules/skottie/include/SlotManager.h +113 -0
- package/cpp/skia/modules/skottie/include/TextShaper.h +200 -0
- package/cpp/skia/modules/skottie/src/SkottieValue.h +56 -0
- package/cpp/skia/modules/skottie/src/animator/Animator.h +89 -0
- package/cpp/skia/modules/skottie/src/text/Font.h +82 -0
- package/cpp/skia/modules/skottie/src/text/TextAdapter.h +155 -0
- package/cpp/skia/modules/skottie/src/text/TextAnimator.h +121 -0
- package/cpp/skia/modules/skottie/src/text/TextValue.h +28 -0
- package/cpp/skia/modules/sksg/include/SkSGClipEffect.h +61 -0
- package/cpp/skia/modules/sksg/include/SkSGColorFilter.h +135 -0
- package/cpp/skia/modules/sksg/include/SkSGDraw.h +57 -0
- package/cpp/skia/modules/sksg/include/SkSGEffectNode.h +50 -0
- package/cpp/skia/modules/sksg/include/SkSGGeometryEffect.h +181 -0
- package/cpp/skia/modules/sksg/include/SkSGGeometryNode.h +54 -0
- package/cpp/skia/modules/sksg/include/SkSGGradient.h +108 -0
- package/cpp/skia/modules/sksg/include/SkSGGroup.h +65 -0
- package/cpp/skia/modules/sksg/include/SkSGImage.h +59 -0
- package/cpp/skia/modules/sksg/include/SkSGInvalidationController.h +46 -0
- package/cpp/skia/modules/sksg/include/SkSGMaskEffect.h +65 -0
- package/cpp/skia/modules/sksg/include/SkSGMerge.h +74 -0
- package/cpp/skia/modules/sksg/include/SkSGNode.h +128 -0
- package/cpp/skia/modules/sksg/include/SkSGOpacityEffect.h +54 -0
- package/cpp/skia/modules/sksg/include/SkSGPaint.h +112 -0
- package/cpp/skia/modules/sksg/include/SkSGPath.h +68 -0
- package/cpp/skia/modules/sksg/include/SkSGPlane.h +47 -0
- package/cpp/skia/modules/sksg/include/SkSGRect.h +122 -0
- package/cpp/skia/modules/sksg/include/SkSGRenderEffect.h +283 -0
- package/cpp/skia/modules/sksg/include/SkSGRenderNode.h +157 -0
- package/cpp/skia/modules/sksg/include/SkSGScene.h +47 -0
- package/cpp/skia/modules/sksg/include/SkSGText.h +82 -0
- package/cpp/skia/modules/sksg/include/SkSGTransform.h +127 -0
- package/cpp/skia/src/base/SkArenaAlloc.h +371 -0
- package/lib/commonjs/dom/nodes/datatypes/Gradient.d.ts +15 -15
- package/lib/commonjs/dom/types/Drawings.d.ts +5 -1
- package/lib/commonjs/dom/types/Drawings.js.map +1 -1
- package/lib/commonjs/dom/types/NodeType.d.ts +2 -1
- package/lib/commonjs/dom/types/NodeType.js +2 -0
- package/lib/commonjs/dom/types/NodeType.js.map +1 -1
- package/lib/commonjs/renderer/__tests__/e2e/AdvancedImageFilters.spec.d.ts +1 -0
- package/lib/commonjs/renderer/__tests__/e2e/Camera.spec.d.ts +21 -0
- package/lib/commonjs/renderer/__tests__/e2e/LightingImageFilters.spec.d.ts +1 -0
- package/lib/commonjs/renderer/__tests__/e2e/Skottie.spec.d.ts +1 -0
- package/lib/commonjs/renderer/__tests__/setup.d.ts +5 -0
- package/lib/commonjs/renderer/components/Skottie.d.ts +4 -0
- package/lib/commonjs/renderer/components/Skottie.js +13 -0
- package/lib/commonjs/renderer/components/Skottie.js.map +1 -0
- package/lib/commonjs/renderer/components/index.d.ts +1 -0
- package/lib/commonjs/renderer/components/index.js +11 -0
- package/lib/commonjs/renderer/components/index.js.map +1 -1
- package/lib/commonjs/skia/types/ImageFilter/ImageFilterFactory.d.ts +252 -15
- package/lib/commonjs/skia/types/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix4.d.ts +11 -2
- package/lib/commonjs/skia/types/Matrix4.js +42 -1
- package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
- package/lib/commonjs/skia/types/Recorder.d.ts +2 -1
- package/lib/commonjs/skia/types/Recorder.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +2 -0
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/Skottie.d.ts +223 -0
- package/lib/commonjs/skia/types/Skottie.js +73 -0
- package/lib/commonjs/skia/types/Skottie.js.map +1 -0
- package/lib/commonjs/skia/types/index.d.ts +1 -0
- package/lib/commonjs/skia/types/index.js +11 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.d.ts +29 -12
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js +88 -19
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +2 -0
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkottieAnimation.d.ts +59 -0
- package/lib/commonjs/skia/web/JsiSkottieAnimation.js +243 -0
- package/lib/commonjs/skia/web/JsiSkottieAnimation.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkottieFactory.d.ts +9 -0
- package/lib/commonjs/skia/web/JsiSkottieFactory.js +26 -0
- package/lib/commonjs/skia/web/JsiSkottieFactory.js.map +1 -0
- package/lib/commonjs/sksg/Elements.d.ts +2 -1
- package/lib/commonjs/sksg/Elements.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Core.d.ts +4 -2
- package/lib/commonjs/sksg/Recorder/Core.js +1 -0
- package/lib/commonjs/sksg/Recorder/Core.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js +2 -0
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +2 -1
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js +4 -0
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Recorder.d.ts +2 -1
- package/lib/commonjs/sksg/Recorder/Recorder.js +6 -0
- package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Visitor.js +3 -0
- package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Drawing.d.ts +2 -2
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js +11 -4
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/module/dom/nodes/datatypes/Gradient.d.ts +15 -15
- package/lib/module/dom/types/Drawings.d.ts +5 -1
- package/lib/module/dom/types/Drawings.js.map +1 -1
- package/lib/module/dom/types/NodeType.d.ts +2 -1
- package/lib/module/dom/types/NodeType.js +2 -0
- package/lib/module/dom/types/NodeType.js.map +1 -1
- package/lib/module/renderer/__tests__/e2e/AdvancedImageFilters.spec.d.ts +1 -0
- package/lib/module/renderer/__tests__/e2e/Camera.spec.d.ts +21 -0
- package/lib/module/renderer/__tests__/e2e/LightingImageFilters.spec.d.ts +1 -0
- package/lib/module/renderer/__tests__/e2e/Skottie.spec.d.ts +1 -0
- package/lib/module/renderer/__tests__/setup.d.ts +5 -0
- package/lib/module/renderer/components/Skottie.d.ts +4 -0
- package/lib/module/renderer/components/Skottie.js +5 -0
- package/lib/module/renderer/components/Skottie.js.map +1 -0
- package/lib/module/renderer/components/index.d.ts +1 -0
- package/lib/module/renderer/components/index.js +1 -0
- package/lib/module/renderer/components/index.js.map +1 -1
- package/lib/module/skia/types/ImageFilter/ImageFilterFactory.d.ts +252 -15
- package/lib/module/skia/types/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/module/skia/types/Matrix4.d.ts +11 -2
- package/lib/module/skia/types/Matrix4.js +40 -0
- package/lib/module/skia/types/Matrix4.js.map +1 -1
- package/lib/module/skia/types/Recorder.d.ts +2 -1
- package/lib/module/skia/types/Recorder.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +2 -0
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/Skottie.d.ts +223 -0
- package/lib/module/skia/types/Skottie.js +74 -0
- package/lib/module/skia/types/Skottie.js.map +1 -0
- package/lib/module/skia/types/index.d.ts +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFilterFactory.d.ts +29 -12
- package/lib/module/skia/web/JsiSkImageFilterFactory.js +88 -19
- package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +2 -0
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/skia/web/JsiSkottieAnimation.d.ts +59 -0
- package/lib/module/skia/web/JsiSkottieAnimation.js +236 -0
- package/lib/module/skia/web/JsiSkottieAnimation.js.map +1 -0
- package/lib/module/skia/web/JsiSkottieFactory.d.ts +9 -0
- package/lib/module/skia/web/JsiSkottieFactory.js +19 -0
- package/lib/module/skia/web/JsiSkottieFactory.js.map +1 -0
- package/lib/module/sksg/Elements.d.ts +2 -1
- package/lib/module/sksg/Elements.js.map +1 -1
- package/lib/module/sksg/Recorder/Core.d.ts +4 -2
- package/lib/module/sksg/Recorder/Core.js +1 -0
- package/lib/module/sksg/Recorder/Core.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.js +3 -1
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +2 -1
- package/lib/module/sksg/Recorder/ReanimatedRecorder.js +4 -0
- package/lib/module/sksg/Recorder/ReanimatedRecorder.js.map +1 -1
- package/lib/module/sksg/Recorder/Recorder.d.ts +2 -1
- package/lib/module/sksg/Recorder/Recorder.js +6 -0
- package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/module/sksg/Recorder/Visitor.js +3 -0
- package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Drawing.d.ts +2 -2
- package/lib/module/sksg/Recorder/commands/Drawing.js +9 -2
- package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/typescript/lib/commonjs/renderer/components/Skottie.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/types/Matrix4.d.ts +1 -0
- package/lib/typescript/lib/commonjs/skia/types/Skottie.d.ts +6 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFilterFactory.d.ts +22 -5
- package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkottieAnimation.d.ts +48 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkottieFactory.d.ts +6 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/commands/Drawing.d.ts +1 -1
- package/lib/typescript/lib/module/mock/index.d.ts +7 -0
- package/lib/typescript/lib/module/renderer/components/Skottie.d.ts +2 -0
- package/lib/typescript/lib/module/renderer/components/index.d.ts +1 -0
- package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/Matrix4.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/Skottie.d.ts +5 -0
- package/lib/typescript/lib/module/skia/types/index.d.ts +1 -0
- package/lib/typescript/lib/module/skia/web/JsiSkImageFilterFactory.d.ts +22 -5
- package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +2 -0
- package/lib/typescript/lib/module/skia/web/JsiSkottieAnimation.d.ts +47 -0
- package/lib/typescript/lib/module/skia/web/JsiSkottieFactory.d.ts +5 -0
- package/lib/typescript/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/Recorder/commands/Drawing.d.ts +1 -1
- package/lib/typescript/src/dom/nodes/datatypes/Gradient.d.ts +15 -15
- package/lib/typescript/src/dom/types/Drawings.d.ts +5 -1
- package/lib/typescript/src/dom/types/NodeType.d.ts +2 -1
- package/lib/typescript/src/renderer/__tests__/e2e/AdvancedImageFilters.spec.d.ts +1 -0
- package/lib/typescript/src/renderer/__tests__/e2e/Camera.spec.d.ts +21 -0
- package/lib/typescript/src/renderer/__tests__/e2e/LightingImageFilters.spec.d.ts +1 -0
- package/lib/typescript/src/renderer/__tests__/e2e/Skottie.spec.d.ts +1 -0
- package/lib/typescript/src/renderer/__tests__/setup.d.ts +5 -0
- package/lib/typescript/src/renderer/components/Skottie.d.ts +4 -0
- package/lib/typescript/src/renderer/components/index.d.ts +1 -0
- package/lib/typescript/src/skia/types/ImageFilter/ImageFilterFactory.d.ts +252 -15
- package/lib/typescript/src/skia/types/Matrix4.d.ts +11 -2
- package/lib/typescript/src/skia/types/Recorder.d.ts +2 -1
- package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
- package/lib/typescript/src/skia/types/Skottie.d.ts +223 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkImageFilterFactory.d.ts +29 -12
- package/lib/typescript/src/skia/web/JsiSkottieAnimation.d.ts +59 -0
- package/lib/typescript/src/skia/web/JsiSkottieFactory.d.ts +9 -0
- package/lib/typescript/src/sksg/Elements.d.ts +2 -1
- package/lib/typescript/src/sksg/Recorder/Core.d.ts +4 -2
- package/lib/typescript/src/sksg/Recorder/ReanimatedRecorder.d.ts +2 -1
- package/lib/typescript/src/sksg/Recorder/Recorder.d.ts +2 -1
- package/lib/typescript/src/sksg/Recorder/commands/Drawing.d.ts +2 -2
- package/libs/android/arm64-v8a/libjsonreader.a +0 -0
- package/libs/android/armeabi-v7a/libjsonreader.a +0 -0
- package/libs/android/x86/libjsonreader.a +0 -0
- package/libs/android/x86_64/libjsonreader.a +0 -0
- package/libs/apple/libpathops.xcframework/Info.plist +8 -8
- package/libs/apple/libskia.xcframework/Info.plist +14 -14
- package/libs/apple/libskottie.xcframework/Info.plist +14 -14
- package/libs/apple/libskparagraph.xcframework/Info.plist +16 -16
- package/libs/apple/libsksg.xcframework/Info.plist +5 -5
- package/libs/apple/libskshaper.xcframework/Info.plist +14 -14
- package/libs/apple/libskunicode_libgrapheme.xcframework/Info.plist +14 -14
- package/libs/apple/libsvg.xcframework/Info.plist +14 -14
- package/package.json +1 -1
- package/react-native-skia.podspec +4 -2
- package/src/__tests__/snapshots/matrix4/camera-corner.png +0 -0
- package/src/__tests__/snapshots/matrix4/camera-offset.png +0 -0
- package/src/__tests__/snapshots/matrix4/camera-top-left-center.png +0 -0
- package/src/__tests__/snapshots/matrix4/camera-zoom-out.png +0 -0
- package/src/__tests__/snapshots/matrix4/full-rect.png +0 -0
- package/src/__tests__/snapshots/matrix4/rect.png +0 -0
- package/src/__tests__/snapshots/matrix4/scaled-rect.png +0 -0
- package/src/__tests__/snapshots/matrix4/test-perspective.png +0 -0
- package/src/__tests__/snapshots/matrix4/test-perspective2.png +0 -0
- package/src/dom/types/Drawings.ts +6 -0
- package/src/dom/types/NodeType.ts +2 -0
- package/src/renderer/__tests__/e2e/AdvancedImageFilters.spec.tsx +492 -0
- package/src/renderer/__tests__/e2e/Camera.spec.tsx +475 -0
- package/src/renderer/__tests__/e2e/LightingImageFilters.spec.tsx +1478 -0
- package/src/renderer/__tests__/e2e/Skottie.spec.tsx +440 -0
- package/src/renderer/__tests__/e2e/setup/skottie/basic_slots.json +1118 -0
- package/src/renderer/__tests__/e2e/setup/skottie/color-props.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/confetti.json +5899 -0
- package/src/renderer/__tests__/e2e/setup/skottie/drinks.json +43857 -0
- package/src/renderer/__tests__/e2e/setup/skottie/fingerprint.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/lego_loader.json +29540 -0
- package/src/renderer/__tests__/e2e/setup/skottie/new-drop.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/onboarding.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/text-layer.json +1 -0
- package/src/renderer/__tests__/setup.tsx +23 -0
- package/src/renderer/components/Skottie.tsx +8 -0
- package/src/renderer/components/index.ts +1 -0
- package/src/skia/__tests__/assets/Avenir-Heavy.ttf +0 -0
- package/src/skia/types/ImageFilter/ImageFilterFactory.ts +391 -21
- package/src/skia/types/Matrix4.ts +108 -2
- package/src/skia/types/Recorder.ts +2 -0
- package/src/skia/types/Skia.ts +2 -0
- package/src/skia/types/Skottie.ts +266 -0
- package/src/skia/types/index.ts +1 -0
- package/src/skia/web/JsiSkImageFilterFactory.ts +266 -31
- package/src/skia/web/JsiSkia.ts +2 -0
- package/src/skia/web/JsiSkottieAnimation.ts +259 -0
- package/src/skia/web/JsiSkottieFactory.ts +25 -0
- package/src/sksg/Elements.tsx +2 -0
- package/src/sksg/Recorder/Core.ts +3 -0
- package/src/sksg/Recorder/Player.ts +3 -0
- package/src/sksg/Recorder/ReanimatedRecorder.ts +6 -0
- package/src/sksg/Recorder/Recorder.ts +5 -0
- package/src/sksg/Recorder/Visitor.ts +3 -0
- package/src/sksg/Recorder/commands/Drawing.ts +7 -3
- package/src/sksg/Recorder/commands/ImageFilters.ts +1 -1
@@ -0,0 +1,82 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2018 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 SkSGText_DEFINED
|
9
|
+
#define SkSGText_DEFINED
|
10
|
+
|
11
|
+
#include "include/core/SkFont.h"
|
12
|
+
#include "include/core/SkFontTypes.h"
|
13
|
+
#include "include/core/SkPath.h"
|
14
|
+
#include "include/core/SkPoint.h"
|
15
|
+
#include "include/core/SkRect.h"
|
16
|
+
#include "include/core/SkRefCnt.h"
|
17
|
+
#include "include/core/SkScalar.h"
|
18
|
+
#include "include/core/SkString.h"
|
19
|
+
#include "include/utils/SkTextUtils.h"
|
20
|
+
#include "modules/sksg/include/SkSGGeometryNode.h"
|
21
|
+
#include "modules/sksg/include/SkSGNode.h"
|
22
|
+
|
23
|
+
class SkCanvas;
|
24
|
+
class SkMatrix;
|
25
|
+
class SkPaint;
|
26
|
+
class SkTextBlob;
|
27
|
+
class SkTypeface;
|
28
|
+
|
29
|
+
namespace sksg {
|
30
|
+
class InvalidationController;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Concrete Geometry node, wrapping a (shaped) SkTextBlob.
|
34
|
+
*/
|
35
|
+
class Text final : public GeometryNode {
|
36
|
+
public:
|
37
|
+
static sk_sp<Text> Make(sk_sp<SkTypeface> tf, const SkString& text);
|
38
|
+
~Text() override;
|
39
|
+
|
40
|
+
SG_ATTRIBUTE(Typeface, sk_sp<SkTypeface> , fTypeface)
|
41
|
+
SG_ATTRIBUTE(Text , SkString , fText )
|
42
|
+
SG_ATTRIBUTE(Position, SkPoint , fPosition)
|
43
|
+
SG_ATTRIBUTE(Size , SkScalar , fSize )
|
44
|
+
SG_ATTRIBUTE(ScaleX , SkScalar , fScaleX )
|
45
|
+
SG_ATTRIBUTE(SkewX , SkScalar , fSkewX )
|
46
|
+
SG_ATTRIBUTE(Align , SkTextUtils::Align, fAlign )
|
47
|
+
SG_ATTRIBUTE(Edging , SkFont::Edging , fEdging )
|
48
|
+
SG_ATTRIBUTE(Hinting , SkFontHinting , fHinting )
|
49
|
+
|
50
|
+
// TODO: add shaping functionality.
|
51
|
+
|
52
|
+
protected:
|
53
|
+
void onClip(SkCanvas*, bool antiAlias) const override;
|
54
|
+
void onDraw(SkCanvas*, const SkPaint&) const override;
|
55
|
+
bool onContains(const SkPoint&) const override;
|
56
|
+
|
57
|
+
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
|
58
|
+
SkPath onAsPath() const override;
|
59
|
+
|
60
|
+
private:
|
61
|
+
Text(sk_sp<SkTypeface>, const SkString&);
|
62
|
+
|
63
|
+
SkPoint alignedPosition(SkScalar advance) const;
|
64
|
+
|
65
|
+
sk_sp<SkTypeface> fTypeface;
|
66
|
+
SkString fText;
|
67
|
+
SkPoint fPosition = SkPoint::Make(0, 0);
|
68
|
+
SkScalar fSize = 12;
|
69
|
+
SkScalar fScaleX = 1;
|
70
|
+
SkScalar fSkewX = 0;
|
71
|
+
SkTextUtils::Align fAlign = SkTextUtils::kLeft_Align;
|
72
|
+
SkFont::Edging fEdging = SkFont::Edging::kAntiAlias;
|
73
|
+
SkFontHinting fHinting = SkFontHinting::kNormal;
|
74
|
+
|
75
|
+
sk_sp<SkTextBlob> fBlob; // cached text blob
|
76
|
+
|
77
|
+
using INHERITED = GeometryNode;
|
78
|
+
};
|
79
|
+
|
80
|
+
} // namespace sksg
|
81
|
+
|
82
|
+
#endif // SkSGText_DEFINED
|
@@ -0,0 +1,127 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2017 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 SkSGTransform_DEFINED
|
9
|
+
#define SkSGTransform_DEFINED
|
10
|
+
|
11
|
+
#include "include/core/SkM44.h"
|
12
|
+
#include "include/core/SkMatrix.h"
|
13
|
+
#include "include/core/SkRect.h"
|
14
|
+
#include "include/core/SkRefCnt.h"
|
15
|
+
#include "modules/sksg/include/SkSGEffectNode.h"
|
16
|
+
#include "modules/sksg/include/SkSGNode.h"
|
17
|
+
#include "modules/sksg/include/SkSGRenderNode.h"
|
18
|
+
|
19
|
+
#include <type_traits>
|
20
|
+
#include <utility>
|
21
|
+
|
22
|
+
class SkCanvas;
|
23
|
+
struct SkPoint;
|
24
|
+
|
25
|
+
namespace sksg {
|
26
|
+
class InvalidationController;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Transformations base class.
|
30
|
+
*/
|
31
|
+
class Transform : public Node {
|
32
|
+
public:
|
33
|
+
// Compose T' = A x B
|
34
|
+
static sk_sp<Transform> MakeConcat(sk_sp<Transform> a, sk_sp<Transform> b);
|
35
|
+
|
36
|
+
// T' = Inv(T)
|
37
|
+
static sk_sp<Transform> MakeInverse(sk_sp<Transform> t);
|
38
|
+
|
39
|
+
protected:
|
40
|
+
Transform();
|
41
|
+
|
42
|
+
virtual bool is44() const = 0;
|
43
|
+
|
44
|
+
virtual SkMatrix asMatrix() const = 0;
|
45
|
+
virtual SkM44 asM44 () const = 0;
|
46
|
+
|
47
|
+
private:
|
48
|
+
friend class TransformPriv;
|
49
|
+
|
50
|
+
using INHERITED = Node;
|
51
|
+
};
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Concrete, matrix-backed Transform.
|
55
|
+
*
|
56
|
+
* Supported instantiations: SkMatrix, SkM44.
|
57
|
+
*
|
58
|
+
* Sample use:
|
59
|
+
*
|
60
|
+
* auto m33 = Matrix<SkMatrix>::Make(SkMatrix::I());
|
61
|
+
* ...
|
62
|
+
* m33->setMatrix(SkMatrix::Translate(10, 10));
|
63
|
+
*
|
64
|
+
*/
|
65
|
+
template <typename T>
|
66
|
+
class Matrix final : public Transform {
|
67
|
+
public:
|
68
|
+
template <typename = std::enable_if<std::is_same<T, SkMatrix>::value ||
|
69
|
+
std::is_same<T, SkM44 >::value>>
|
70
|
+
static sk_sp<Matrix> Make(const T& m) { return sk_sp<Matrix>(new Matrix(m)); }
|
71
|
+
|
72
|
+
SG_ATTRIBUTE(Matrix, T, fMatrix)
|
73
|
+
|
74
|
+
protected:
|
75
|
+
explicit Matrix(const T& m) : fMatrix(m) {}
|
76
|
+
|
77
|
+
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override {
|
78
|
+
return SkRect::MakeEmpty();
|
79
|
+
}
|
80
|
+
|
81
|
+
bool is44() const override { return std::is_same<T, SkM44>::value; }
|
82
|
+
|
83
|
+
SkMatrix asMatrix() const override;
|
84
|
+
SkM44 asM44 () const override;
|
85
|
+
|
86
|
+
private:
|
87
|
+
T fMatrix;
|
88
|
+
|
89
|
+
using INHERITED = Transform;
|
90
|
+
};
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Concrete Effect node, binding a Transform to a RenderNode.
|
94
|
+
*/
|
95
|
+
class TransformEffect final : public EffectNode {
|
96
|
+
public:
|
97
|
+
static sk_sp<TransformEffect> Make(sk_sp<RenderNode> child, sk_sp<Transform> transform) {
|
98
|
+
return child && transform
|
99
|
+
? sk_sp<TransformEffect>(new TransformEffect(std::move(child), std::move(transform)))
|
100
|
+
: nullptr;
|
101
|
+
}
|
102
|
+
|
103
|
+
static sk_sp<TransformEffect> Make(sk_sp<RenderNode> child, const SkMatrix& m) {
|
104
|
+
return Make(std::move(child), Matrix<SkMatrix>::Make(m));
|
105
|
+
}
|
106
|
+
|
107
|
+
~TransformEffect() override;
|
108
|
+
|
109
|
+
const sk_sp<Transform>& getTransform() const { return fTransform; }
|
110
|
+
|
111
|
+
protected:
|
112
|
+
void onRender(SkCanvas*, const RenderContext*) const override;
|
113
|
+
const RenderNode* onNodeAt(const SkPoint&) const override;
|
114
|
+
|
115
|
+
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
|
116
|
+
|
117
|
+
private:
|
118
|
+
TransformEffect(sk_sp<RenderNode>, sk_sp<Transform>);
|
119
|
+
|
120
|
+
const sk_sp<Transform> fTransform;
|
121
|
+
|
122
|
+
using INHERITED = EffectNode;
|
123
|
+
};
|
124
|
+
|
125
|
+
} // namespace sksg
|
126
|
+
|
127
|
+
#endif // SkSGTransform_DEFINED
|
@@ -0,0 +1,371 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2016 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 SkArenaAlloc_DEFINED
|
9
|
+
#define SkArenaAlloc_DEFINED
|
10
|
+
|
11
|
+
#include "include/private/base/SkASAN.h"
|
12
|
+
#include "include/private/base/SkAssert.h"
|
13
|
+
#include "include/private/base/SkSpan_impl.h"
|
14
|
+
#include "include/private/base/SkTFitsIn.h"
|
15
|
+
#include "include/private/base/SkTo.h"
|
16
|
+
|
17
|
+
#include <algorithm>
|
18
|
+
#include <array>
|
19
|
+
#include <cstdint>
|
20
|
+
#include <cstdlib>
|
21
|
+
#include <cstring>
|
22
|
+
#include <limits>
|
23
|
+
#include <new>
|
24
|
+
#include <type_traits> // IWYU pragma: keep
|
25
|
+
#include <utility>
|
26
|
+
|
27
|
+
// We found allocating strictly doubling amounts of memory from the heap left too
|
28
|
+
// much unused slop, particularly on Android. Instead we'll follow a Fibonacci-like
|
29
|
+
// progression.
|
30
|
+
|
31
|
+
// SkFibonacci47 is the first 47 Fibonacci numbers. Fib(47) is the largest value less than 2 ^ 32.
|
32
|
+
extern std::array<const uint32_t, 47> SkFibonacci47;
|
33
|
+
template<uint32_t kMaxSize>
|
34
|
+
class SkFibBlockSizes {
|
35
|
+
public:
|
36
|
+
// staticBlockSize, and firstAllocationSize are parameters describing the initial memory
|
37
|
+
// layout. staticBlockSize describes the size of the inlined memory, and firstAllocationSize
|
38
|
+
// describes the size of the first block to be allocated if the static block is exhausted. By
|
39
|
+
// convention, firstAllocationSize is the first choice for the block unit size followed by
|
40
|
+
// staticBlockSize followed by the default of 1024 bytes.
|
41
|
+
SkFibBlockSizes(uint32_t staticBlockSize, uint32_t firstAllocationSize) : fIndex{0} {
|
42
|
+
fBlockUnitSize = firstAllocationSize > 0 ? firstAllocationSize :
|
43
|
+
staticBlockSize > 0 ? staticBlockSize : 1024;
|
44
|
+
|
45
|
+
SkASSERT_RELEASE(0 < fBlockUnitSize);
|
46
|
+
SkASSERT_RELEASE(fBlockUnitSize < std::min(kMaxSize, (1u << 26) - 1));
|
47
|
+
}
|
48
|
+
|
49
|
+
uint32_t nextBlockSize() {
|
50
|
+
uint32_t result = SkFibonacci47[fIndex] * fBlockUnitSize;
|
51
|
+
|
52
|
+
if (SkTo<size_t>(fIndex + 1) < SkFibonacci47.size() &&
|
53
|
+
SkFibonacci47[fIndex + 1] < kMaxSize / fBlockUnitSize)
|
54
|
+
{
|
55
|
+
fIndex += 1;
|
56
|
+
}
|
57
|
+
|
58
|
+
return result;
|
59
|
+
}
|
60
|
+
|
61
|
+
private:
|
62
|
+
uint32_t fIndex : 6;
|
63
|
+
uint32_t fBlockUnitSize : 26;
|
64
|
+
};
|
65
|
+
|
66
|
+
// SkArenaAlloc allocates object and destroys the allocated objects when destroyed. It's designed
|
67
|
+
// to minimize the number of underlying block allocations. SkArenaAlloc allocates first out of an
|
68
|
+
// (optional) user-provided block of memory, and when that's exhausted it allocates on the heap,
|
69
|
+
// starting with an allocation of firstHeapAllocation bytes. If your data (plus a small overhead)
|
70
|
+
// fits in the user-provided block, SkArenaAlloc never uses the heap, and if it fits in
|
71
|
+
// firstHeapAllocation bytes, it'll use the heap only once. If 0 is specified for
|
72
|
+
// firstHeapAllocation, then blockSize is used unless that too is 0, then 1024 is used.
|
73
|
+
//
|
74
|
+
// Examples:
|
75
|
+
//
|
76
|
+
// char block[mostCasesSize];
|
77
|
+
// SkArenaAlloc arena(block, mostCasesSize);
|
78
|
+
//
|
79
|
+
// If mostCasesSize is too large for the stack, you can use the following pattern.
|
80
|
+
//
|
81
|
+
// std::unique_ptr<char[]> block{new char[mostCasesSize]};
|
82
|
+
// SkArenaAlloc arena(block.get(), mostCasesSize, almostAllCasesSize);
|
83
|
+
//
|
84
|
+
// If the program only sometimes allocates memory, use the following pattern.
|
85
|
+
//
|
86
|
+
// SkArenaAlloc arena(nullptr, 0, almostAllCasesSize);
|
87
|
+
//
|
88
|
+
// The storage does not necessarily need to be on the stack. Embedding the storage in a class also
|
89
|
+
// works.
|
90
|
+
//
|
91
|
+
// class Foo {
|
92
|
+
// char storage[mostCasesSize];
|
93
|
+
// SkArenaAlloc arena (storage, mostCasesSize);
|
94
|
+
// };
|
95
|
+
//
|
96
|
+
// In addition, the system is optimized to handle POD data including arrays of PODs (where
|
97
|
+
// POD is really data with no destructors). For POD data it has zero overhead per item, and a
|
98
|
+
// typical per block overhead of 8 bytes. For non-POD objects there is a per item overhead of 4
|
99
|
+
// bytes. For arrays of non-POD objects there is a per array overhead of typically 8 bytes. There
|
100
|
+
// is an addition overhead when switching from POD data to non-POD data of typically 8 bytes.
|
101
|
+
//
|
102
|
+
// If additional blocks are needed they are increased exponentially. This strategy bounds the
|
103
|
+
// recursion of the RunDtorsOnBlock to be limited to O(log size-of-memory). Block size grow using
|
104
|
+
// the Fibonacci sequence which means that for 2^32 memory there are 48 allocations, and for 2^48
|
105
|
+
// there are 71 allocations.
|
106
|
+
class SkArenaAlloc {
|
107
|
+
public:
|
108
|
+
SkArenaAlloc(char* block, size_t blockSize, size_t firstHeapAllocation);
|
109
|
+
|
110
|
+
explicit SkArenaAlloc(size_t firstHeapAllocation)
|
111
|
+
: SkArenaAlloc(nullptr, 0, firstHeapAllocation) {}
|
112
|
+
|
113
|
+
SkArenaAlloc(const SkArenaAlloc&) = delete;
|
114
|
+
SkArenaAlloc& operator=(const SkArenaAlloc&) = delete;
|
115
|
+
SkArenaAlloc(SkArenaAlloc&&) = delete;
|
116
|
+
SkArenaAlloc& operator=(SkArenaAlloc&&) = delete;
|
117
|
+
|
118
|
+
~SkArenaAlloc();
|
119
|
+
|
120
|
+
template <typename Ctor>
|
121
|
+
auto make(Ctor&& ctor) -> decltype(ctor(nullptr)) {
|
122
|
+
using T = std::remove_pointer_t<decltype(ctor(nullptr))>;
|
123
|
+
|
124
|
+
uint32_t size = SkToU32(sizeof(T));
|
125
|
+
uint32_t alignment = SkToU32(alignof(T));
|
126
|
+
char* objStart;
|
127
|
+
if (std::is_trivially_destructible<T>::value) {
|
128
|
+
objStart = this->allocObject(size, alignment);
|
129
|
+
fCursor = objStart + size;
|
130
|
+
sk_asan_unpoison_memory_region(objStart, size);
|
131
|
+
} else {
|
132
|
+
objStart = this->allocObjectWithFooter(size + sizeof(Footer), alignment);
|
133
|
+
// Can never be UB because max value is alignof(T).
|
134
|
+
uint32_t padding = SkToU32(objStart - fCursor);
|
135
|
+
|
136
|
+
// Advance to end of object to install footer.
|
137
|
+
fCursor = objStart + size;
|
138
|
+
sk_asan_unpoison_memory_region(objStart, size);
|
139
|
+
FooterAction* releaser = [](char* objEnd) {
|
140
|
+
char* objStart = objEnd - (sizeof(T) + sizeof(Footer));
|
141
|
+
((T*)objStart)->~T();
|
142
|
+
return objStart;
|
143
|
+
};
|
144
|
+
this->installFooter(releaser, padding);
|
145
|
+
}
|
146
|
+
|
147
|
+
// This must be last to make objects with nested use of this allocator work.
|
148
|
+
return ctor(objStart);
|
149
|
+
}
|
150
|
+
|
151
|
+
template <typename T, typename... Args>
|
152
|
+
T* make(Args&&... args) {
|
153
|
+
return this->make([&](void* objStart) {
|
154
|
+
return new(objStart) T(std::forward<Args>(args)...);
|
155
|
+
});
|
156
|
+
}
|
157
|
+
|
158
|
+
template <typename T>
|
159
|
+
T* make() {
|
160
|
+
if constexpr (std::is_standard_layout<T>::value && std::is_trivial<T>::value) {
|
161
|
+
// Just allocate some aligned bytes. This generates smaller code.
|
162
|
+
return (T*)this->makeBytesAlignedTo(sizeof(T), alignof(T));
|
163
|
+
} else {
|
164
|
+
// This isn't a POD type, so construct the object properly.
|
165
|
+
return this->make([&](void* objStart) {
|
166
|
+
return new(objStart) T();
|
167
|
+
});
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
template <typename T>
|
172
|
+
T* makeArrayDefault(size_t count) {
|
173
|
+
T* array = this->allocUninitializedArray<T>(count);
|
174
|
+
for (size_t i = 0; i < count; i++) {
|
175
|
+
// Default initialization: if T is primitive then the value is left uninitialized.
|
176
|
+
new (&array[i]) T;
|
177
|
+
}
|
178
|
+
return array;
|
179
|
+
}
|
180
|
+
|
181
|
+
template <typename T>
|
182
|
+
T* makeArray(size_t count) {
|
183
|
+
T* array = this->allocUninitializedArray<T>(count);
|
184
|
+
for (size_t i = 0; i < count; i++) {
|
185
|
+
// Value initialization: if T is primitive then the value is zero-initialized.
|
186
|
+
new (&array[i]) T();
|
187
|
+
}
|
188
|
+
return array;
|
189
|
+
}
|
190
|
+
|
191
|
+
template <typename T, typename Initializer>
|
192
|
+
T* makeInitializedArray(size_t count, Initializer initializer) {
|
193
|
+
T* array = this->allocUninitializedArray<T>(count);
|
194
|
+
for (size_t i = 0; i < count; i++) {
|
195
|
+
new (&array[i]) T(initializer(i));
|
196
|
+
}
|
197
|
+
return array;
|
198
|
+
}
|
199
|
+
|
200
|
+
template <typename T>
|
201
|
+
T* makeArrayCopy(SkSpan<const T> toCopy) {
|
202
|
+
T* array = this->allocUninitializedArray<T>(toCopy.size());
|
203
|
+
if constexpr (std::is_trivially_copyable<T>::value) {
|
204
|
+
memcpy(array, toCopy.data(), toCopy.size_bytes());
|
205
|
+
} else {
|
206
|
+
for (size_t i = 0; i < toCopy.size(); ++i) {
|
207
|
+
new (&array[i]) T(toCopy[i]);
|
208
|
+
}
|
209
|
+
}
|
210
|
+
return array;
|
211
|
+
}
|
212
|
+
|
213
|
+
// Only use makeBytesAlignedTo if none of the typed variants are practical to use.
|
214
|
+
void* makeBytesAlignedTo(size_t size, size_t align) {
|
215
|
+
AssertRelease(SkTFitsIn<uint32_t>(size));
|
216
|
+
auto objStart = this->allocObject(SkToU32(size), SkToU32(align));
|
217
|
+
fCursor = objStart + size;
|
218
|
+
sk_asan_unpoison_memory_region(objStart, size);
|
219
|
+
return objStart;
|
220
|
+
}
|
221
|
+
|
222
|
+
protected:
|
223
|
+
using FooterAction = char* (char*);
|
224
|
+
struct Footer {
|
225
|
+
uint8_t unaligned_action[sizeof(FooterAction*)];
|
226
|
+
uint8_t padding;
|
227
|
+
};
|
228
|
+
|
229
|
+
char* cursor() { return fCursor; }
|
230
|
+
char* end() { return fEnd; }
|
231
|
+
|
232
|
+
private:
|
233
|
+
static void AssertRelease(bool cond) { if (!cond) { ::abort(); } }
|
234
|
+
|
235
|
+
static char* SkipPod(char* footerEnd);
|
236
|
+
static void RunDtorsOnBlock(char* footerEnd);
|
237
|
+
static char* NextBlock(char* footerEnd);
|
238
|
+
|
239
|
+
template <typename T>
|
240
|
+
void installRaw(const T& val) {
|
241
|
+
sk_asan_unpoison_memory_region(fCursor, sizeof(val));
|
242
|
+
memcpy(fCursor, &val, sizeof(val));
|
243
|
+
fCursor += sizeof(val);
|
244
|
+
}
|
245
|
+
void installFooter(FooterAction* releaser, uint32_t padding);
|
246
|
+
|
247
|
+
void ensureSpace(uint32_t size, uint32_t alignment);
|
248
|
+
|
249
|
+
char* allocObject(uint32_t size, uint32_t alignment) {
|
250
|
+
uintptr_t mask = alignment - 1;
|
251
|
+
uintptr_t alignedOffset = (~reinterpret_cast<uintptr_t>(fCursor) + 1) & mask;
|
252
|
+
uintptr_t totalSize = size + alignedOffset;
|
253
|
+
AssertRelease(totalSize >= size);
|
254
|
+
if (totalSize > static_cast<uintptr_t>(fEnd - fCursor)) {
|
255
|
+
this->ensureSpace(size, alignment);
|
256
|
+
alignedOffset = (~reinterpret_cast<uintptr_t>(fCursor) + 1) & mask;
|
257
|
+
}
|
258
|
+
|
259
|
+
char* object = fCursor + alignedOffset;
|
260
|
+
|
261
|
+
SkASSERT((reinterpret_cast<uintptr_t>(object) & (alignment - 1)) == 0);
|
262
|
+
SkASSERT(object + size <= fEnd);
|
263
|
+
|
264
|
+
return object;
|
265
|
+
}
|
266
|
+
|
267
|
+
char* allocObjectWithFooter(uint32_t sizeIncludingFooter, uint32_t alignment);
|
268
|
+
|
269
|
+
template <typename T>
|
270
|
+
T* allocUninitializedArray(size_t countZ) {
|
271
|
+
static_assert(!std::has_virtual_destructor<T>::value, "Can't make an array of objects which have a vtable");
|
272
|
+
AssertRelease(SkTFitsIn<uint32_t>(countZ));
|
273
|
+
uint32_t count = SkToU32(countZ);
|
274
|
+
|
275
|
+
char* objStart;
|
276
|
+
AssertRelease(count <= std::numeric_limits<uint32_t>::max() / sizeof(T));
|
277
|
+
uint32_t arraySize = SkToU32(count * sizeof(T));
|
278
|
+
uint32_t alignment = SkToU32(alignof(T));
|
279
|
+
|
280
|
+
if (std::is_trivially_destructible<T>::value) {
|
281
|
+
objStart = this->allocObject(arraySize, alignment);
|
282
|
+
fCursor = objStart + arraySize;
|
283
|
+
sk_asan_unpoison_memory_region(objStart, arraySize);
|
284
|
+
} else {
|
285
|
+
constexpr uint32_t overhead = sizeof(Footer) + sizeof(uint32_t);
|
286
|
+
AssertRelease(arraySize <= std::numeric_limits<uint32_t>::max() - overhead);
|
287
|
+
uint32_t totalSize = arraySize + overhead;
|
288
|
+
objStart = this->allocObjectWithFooter(totalSize, alignment);
|
289
|
+
|
290
|
+
// Can never be UB because max value is alignof(T).
|
291
|
+
uint32_t padding = SkToU32(objStart - fCursor);
|
292
|
+
|
293
|
+
// Advance to end of array to install footer.
|
294
|
+
fCursor = objStart + arraySize;
|
295
|
+
sk_asan_unpoison_memory_region(objStart, arraySize);
|
296
|
+
this->installRaw(SkToU32(count));
|
297
|
+
this->installFooter(
|
298
|
+
[](char* footerEnd) {
|
299
|
+
char* objEnd = footerEnd - (sizeof(Footer) + sizeof(uint32_t));
|
300
|
+
uint32_t count;
|
301
|
+
memmove(&count, objEnd, sizeof(uint32_t));
|
302
|
+
char* objStart = objEnd - count * sizeof(T);
|
303
|
+
T* array = (T*) objStart;
|
304
|
+
for (uint32_t i = 0; i < count; i++) {
|
305
|
+
array[i].~T();
|
306
|
+
}
|
307
|
+
return objStart;
|
308
|
+
},
|
309
|
+
padding);
|
310
|
+
}
|
311
|
+
|
312
|
+
return (T*)objStart;
|
313
|
+
}
|
314
|
+
|
315
|
+
char* fDtorCursor;
|
316
|
+
char* fCursor;
|
317
|
+
char* fEnd;
|
318
|
+
|
319
|
+
SkFibBlockSizes<std::numeric_limits<uint32_t>::max()> fFibonacciProgression;
|
320
|
+
};
|
321
|
+
|
322
|
+
class SkArenaAllocWithReset : public SkArenaAlloc {
|
323
|
+
public:
|
324
|
+
SkArenaAllocWithReset(char* block, size_t blockSize, size_t firstHeapAllocation);
|
325
|
+
|
326
|
+
explicit SkArenaAllocWithReset(size_t firstHeapAllocation)
|
327
|
+
: SkArenaAllocWithReset(nullptr, 0, firstHeapAllocation) {}
|
328
|
+
|
329
|
+
// Destroy all allocated objects, free any heap allocations.
|
330
|
+
void reset();
|
331
|
+
|
332
|
+
// Returns true if the alloc has never made any objects.
|
333
|
+
bool isEmpty();
|
334
|
+
|
335
|
+
private:
|
336
|
+
char* const fFirstBlock;
|
337
|
+
const uint32_t fFirstSize;
|
338
|
+
const uint32_t fFirstHeapAllocationSize;
|
339
|
+
};
|
340
|
+
|
341
|
+
// Helper for defining allocators with inline/reserved storage.
|
342
|
+
// For argument declarations, stick to the base type (SkArenaAlloc).
|
343
|
+
// Note: Inheriting from the storage first means the storage will outlive the
|
344
|
+
// SkArenaAlloc, letting ~SkArenaAlloc read it as it calls destructors.
|
345
|
+
// (This is mostly only relevant for strict tools like MSAN.)
|
346
|
+
template <size_t InlineStorageSize>
|
347
|
+
class SkSTArenaAlloc : private std::array<char, InlineStorageSize>, public SkArenaAlloc {
|
348
|
+
public:
|
349
|
+
explicit SkSTArenaAlloc(size_t firstHeapAllocation = InlineStorageSize)
|
350
|
+
: SkArenaAlloc{this->data(), this->size(), firstHeapAllocation} {}
|
351
|
+
|
352
|
+
~SkSTArenaAlloc() {
|
353
|
+
// Be sure to unpoison the memory that is probably on the stack.
|
354
|
+
sk_asan_unpoison_memory_region(this->data(), this->size());
|
355
|
+
}
|
356
|
+
};
|
357
|
+
|
358
|
+
template <size_t InlineStorageSize>
|
359
|
+
class SkSTArenaAllocWithReset
|
360
|
+
: private std::array<char, InlineStorageSize>, public SkArenaAllocWithReset {
|
361
|
+
public:
|
362
|
+
explicit SkSTArenaAllocWithReset(size_t firstHeapAllocation = InlineStorageSize)
|
363
|
+
: SkArenaAllocWithReset{this->data(), this->size(), firstHeapAllocation} {}
|
364
|
+
|
365
|
+
~SkSTArenaAllocWithReset() {
|
366
|
+
// Be sure to unpoison the memory that is probably on the stack.
|
367
|
+
sk_asan_unpoison_memory_region(this->data(), this->size());
|
368
|
+
}
|
369
|
+
};
|
370
|
+
|
371
|
+
#endif // SkArenaAlloc_DEFINED
|