aboutsummaryrefslogtreecommitdiff
path: root/bridge/src/android/graphics/drawable/VectorDrawable_Delegate.java
blob: 828df6bfd5e251a9c625d298bc5143a67718edf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.graphics.drawable;

import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;

import android.annotation.NonNull;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.BaseCanvas_Delegate;
import android.graphics.Canvas_Delegate;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Join;
import android.graphics.Paint_Delegate;
import android.graphics.Path;
import android.graphics.Path.FillType;
import android.graphics.PathMeasure;
import android.graphics.Path_Delegate;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.Region.Op;
import android.graphics.Shader_Delegate;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.Log;
import android.util.MathUtils;
import android.util.PathParser_Delegate;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.function.Consumer;

import static android.graphics.Canvas.CLIP_SAVE_FLAG;
import static android.graphics.Canvas.MATRIX_SAVE_FLAG;
import static android.graphics.Paint.Cap.BUTT;
import static android.graphics.Paint.Cap.ROUND;
import static android.graphics.Paint.Cap.SQUARE;
import static android.graphics.Paint.Join.BEVEL;
import static android.graphics.Paint.Join.MITER;
import static android.graphics.Paint.Style;

/**
 * Delegate used to provide new implementation of a select few methods of {@link VectorDrawable}
 * <p>
 * Through the layoutlib_create tool, the original  methods of VectorDrawable have been replaced by
 * calls to methods of the same name in this delegate class.
 */
@SuppressWarnings("unused")
public class VectorDrawable_Delegate {
    private static final String LOGTAG = VectorDrawable_Delegate.class.getSimpleName();
    private static final boolean DBG_VECTOR_DRAWABLE = false;

    private static final DelegateManager<VNativeObject> sPathManager =
            new DelegateManager<>(VNativeObject.class);

    private static long addNativeObject(VNativeObject object) {
        long ptr = sPathManager.addNewDelegate(object);
        object.setNativePtr(ptr);

        return ptr;
    }

    /**
     * Obtains styled attributes from the theme, if available, or unstyled resources if the theme is
     * null.
     */
    private static TypedArray obtainAttributes(
            Resources res, Theme theme, AttributeSet set, int[] attrs) {
        if (theme == null) {
            return res.obtainAttributes(set, attrs);
        }
        return theme.obtainStyledAttributes(set, attrs, 0, 0);
    }

    private static int applyAlpha(int color, float alpha) {
        int alphaBytes = Color.alpha(color);
        color &= 0x00FFFFFF;
        color |= ((int) (alphaBytes * alpha)) << 24;
        return color;
    }

    @LayoutlibDelegate
    static long nCreateTree(long rootGroupPtr) {
        return addNativeObject(new VPathRenderer_Delegate(rootGroupPtr));
    }

    @LayoutlibDelegate
    static long nCreateTreeFromCopy(long rendererToCopyPtr, long rootGroupPtr) {
        VPathRenderer_Delegate rendererToCopy = VNativeObject.getDelegate(rendererToCopyPtr);
        return addNativeObject(new VPathRenderer_Delegate(rendererToCopy,
                rootGroupPtr));
    }

    @LayoutlibDelegate
    static void nSetRendererViewportSize(long rendererPtr, float viewportWidth,
            float viewportHeight) {
        VPathRenderer_Delegate nativePathRenderer = VNativeObject.getDelegate(rendererPtr);
        nativePathRenderer.mViewportWidth = viewportWidth;
        nativePathRenderer.mViewportHeight = viewportHeight;
    }

    @LayoutlibDelegate
    static boolean nSetRootAlpha(long rendererPtr, float alpha) {
        VPathRenderer_Delegate nativePathRenderer = VNativeObject.getDelegate(rendererPtr);
        nativePathRenderer.setRootAlpha(alpha);

        return true;
    }

    @LayoutlibDelegate
    static float nGetRootAlpha(long rendererPtr) {
        VPathRenderer_Delegate nativePathRenderer = VNativeObject.getDelegate(rendererPtr);

        return nativePathRenderer.getRootAlpha();
    }

    @LayoutlibDelegate
    static void nSetAntiAlias(long rendererPtr, boolean aa) {
        VPathRenderer_Delegate nativePathRenderer = VNativeObject.getDelegate(rendererPtr);
        nativePathRenderer.setAntiAlias(aa);
    }

    @LayoutlibDelegate
    static void nSetAllowCaching(long rendererPtr, boolean allowCaching) {
        // ignored
    }

    @LayoutlibDelegate
    static int nDraw(long rendererPtr, long canvasWrapperPtr,
            long colorFilterPtr, Rect bounds, boolean needsMirroring, boolean canReuseCache) {
        VPathRenderer_Delegate nativePathRenderer = VNativeObject.getDelegate(rendererPtr);

        Canvas_Delegate.nSave(canvasWrapperPtr, MATRIX_SAVE_FLAG | CLIP_SAVE_FLAG);
        Canvas_Delegate.nClipRect(canvasWrapperPtr,
                bounds.left, bounds.top, bounds.right, bounds.bottom,
                Region.Op.INTERSECT.nativeInt);
        Canvas_Delegate.nTranslate(canvasWrapperPtr, bounds.left, bounds.top);

        if (needsMirroring) {
            Canvas_Delegate.nTranslate(canvasWrapperPtr, bounds.width(), 0);
            Canvas_Delegate.nScale(canvasWrapperPtr, -1.0f, 1.0f);
        }

        // At this point, canvas has been translated to the right position.
        // And we use this bound for the destination rect for the drawBitmap, so
        // we offset to (0, 0);
        bounds.offsetTo(0, 0);
        nativePathRenderer.draw(canvasWrapperPtr, colorFilterPtr, bounds.width(), bounds.height());

        Canvas_Delegate.nRestore(canvasWrapperPtr);

        return bounds.width() * bounds.height();
    }

    @LayoutlibDelegate
    static long nCreateFullPath() {
        return addNativeObject(new VFullPath_Delegate());
    }

    @LayoutlibDelegate
    static long nCreateFullPath(long nativeFullPathPtr) {
        VFullPath_Delegate original = VNativeObject.getDelegate(nativeFullPathPtr);
        return addNativeObject(new VFullPath_Delegate(original));
    }

    @LayoutlibDelegate
    static boolean nGetFullPathProperties(long pathPtr, byte[] propertiesData,
            int length) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);

        ByteBuffer properties = ByteBuffer.wrap(propertiesData);
        properties.order(ByteOrder.nativeOrder());

        properties.putFloat(VFullPath_Delegate.STROKE_WIDTH_INDEX * 4, path.getStrokeWidth());
        properties.putInt(VFullPath_Delegate.STROKE_COLOR_INDEX * 4, path.getStrokeColor());
        properties.putFloat(VFullPath_Delegate.STROKE_ALPHA_INDEX * 4, path.getStrokeAlpha());
        properties.putInt(VFullPath_Delegate.FILL_COLOR_INDEX * 4, path.getFillColor());
        properties.putFloat(VFullPath_Delegate.FILL_ALPHA_INDEX * 4, path.getStrokeAlpha());
        properties.putFloat(VFullPath_Delegate.TRIM_PATH_START_INDEX * 4, path.getTrimPathStart());
        properties.putFloat(VFullPath_Delegate.TRIM_PATH_END_INDEX * 4, path.getTrimPathEnd());
        properties.putFloat(VFullPath_Delegate.TRIM_PATH_OFFSET_INDEX * 4,
                path.getTrimPathOffset());
        properties.putInt(VFullPath_Delegate.STROKE_LINE_CAP_INDEX * 4, path.getStrokeLineCap());
        properties.putInt(VFullPath_Delegate.STROKE_LINE_JOIN_INDEX * 4, path.getStrokeLineJoin());
        properties.putFloat(VFullPath_Delegate.STROKE_MITER_LIMIT_INDEX * 4,
                path.getStrokeMiterlimit());
        properties.putInt(VFullPath_Delegate.FILL_TYPE_INDEX * 4, path.getFillType());

        return true;
    }

    @LayoutlibDelegate
    static void nUpdateFullPathProperties(long pathPtr, float strokeWidth,
            int strokeColor, float strokeAlpha, int fillColor, float fillAlpha, float trimPathStart,
            float trimPathEnd, float trimPathOffset, float strokeMiterLimit, int strokeLineCap,
            int strokeLineJoin, int fillType) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);

        path.setStrokeWidth(strokeWidth);
        path.setStrokeColor(strokeColor);
        path.setStrokeAlpha(strokeAlpha);
        path.setFillColor(fillColor);
        path.setFillAlpha(fillAlpha);
        path.setTrimPathStart(trimPathStart);
        path.setTrimPathEnd(trimPathEnd);
        path.setTrimPathOffset(trimPathOffset);
        path.setStrokeMiterlimit(strokeMiterLimit);
        path.setStrokeLineCap(strokeLineCap);
        path.setStrokeLineJoin(strokeLineJoin);
        path.setFillType(fillType);
    }

    @LayoutlibDelegate
    static void nUpdateFullPathFillGradient(long pathPtr, long fillGradientPtr) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);

        path.setFillGradient(fillGradientPtr);
    }

    @LayoutlibDelegate
    static void nUpdateFullPathStrokeGradient(long pathPtr, long strokeGradientPtr) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);

        path.setStrokeGradient(strokeGradientPtr);
    }

    @LayoutlibDelegate
    static long nCreateClipPath() {
        return addNativeObject(new VClipPath_Delegate());
    }

    @LayoutlibDelegate
    static long nCreateClipPath(long clipPathPtr) {
        VClipPath_Delegate original = VNativeObject.getDelegate(clipPathPtr);
        return addNativeObject(new VClipPath_Delegate(original));
    }

    @LayoutlibDelegate
    static long nCreateGroup() {
        return addNativeObject(new VGroup_Delegate());
    }

    @LayoutlibDelegate
    static long nCreateGroup(long groupPtr) {
        VGroup_Delegate original = VNativeObject.getDelegate(groupPtr);
        return addNativeObject(new VGroup_Delegate(original, new ArrayMap<>()));
    }

    @LayoutlibDelegate
    static void nSetName(long nodePtr, String name) {
        VNativeObject group = VNativeObject.getDelegate(nodePtr);
        group.setName(name);
    }

    @LayoutlibDelegate
    static boolean nGetGroupProperties(long groupPtr, float[] propertiesData,
            int length) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);

        FloatBuffer properties = FloatBuffer.wrap(propertiesData);

        properties.put(VGroup_Delegate.ROTATE_INDEX, group.getRotation());
        properties.put(VGroup_Delegate.PIVOT_X_INDEX, group.getPivotX());
        properties.put(VGroup_Delegate.PIVOT_Y_INDEX, group.getPivotY());
        properties.put(VGroup_Delegate.SCALE_X_INDEX, group.getScaleX());
        properties.put(VGroup_Delegate.SCALE_Y_INDEX, group.getScaleY());
        properties.put(VGroup_Delegate.TRANSLATE_X_INDEX, group.getTranslateX());
        properties.put(VGroup_Delegate.TRANSLATE_Y_INDEX, group.getTranslateY());

        return true;
    }
    @LayoutlibDelegate
    static void nUpdateGroupProperties(long groupPtr, float rotate, float pivotX,
            float pivotY, float scaleX, float scaleY, float translateX, float translateY) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);

        group.setRotation(rotate);
        group.setPivotX(pivotX);
        group.setPivotY(pivotY);
        group.setScaleX(scaleX);
        group.setScaleY(scaleY);
        group.setTranslateX(translateX);
        group.setTranslateY(translateY);
    }

    @LayoutlibDelegate
    static void nAddChild(long groupPtr, long nodePtr) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        group.mChildren.add(VNativeObject.getDelegate(nodePtr));
    }

    @LayoutlibDelegate
    static void nSetPathString(long pathPtr, String pathString, int length) {
        VPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        path.setPathData(PathParser_Delegate.createNodesFromPathData(pathString));
    }

    /**
     * The setters and getters below for paths and groups are here temporarily, and will be removed
     * once the animation in AVD is replaced with RenderNodeAnimator, in which case the animation
     * will modify these properties in native. By then no JNI hopping would be necessary for VD
     * during animation, and these setters and getters will be obsolete.
     */
    // Setters and getters during animation.
    @LayoutlibDelegate
    static float nGetRotation(long groupPtr) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        return group.getRotation();
    }

    @LayoutlibDelegate
    static void nSetRotation(long groupPtr, float rotation) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        group.setRotation(rotation);
    }

    @LayoutlibDelegate
    static float nGetPivotX(long groupPtr) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        return group.getPivotX();
    }

    @LayoutlibDelegate
    static void nSetPivotX(long groupPtr, float pivotX) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        group.setPivotX(pivotX);
    }

    @LayoutlibDelegate
    static float nGetPivotY(long groupPtr) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        return group.getPivotY();
    }

    @LayoutlibDelegate
    static void nSetPivotY(long groupPtr, float pivotY) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        group.setPivotY(pivotY);
    }

    @LayoutlibDelegate
    static float nGetScaleX(long groupPtr) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        return group.getScaleX();
    }

    @LayoutlibDelegate
    static void nSetScaleX(long groupPtr, float scaleX) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        group.setScaleX(scaleX);
    }

    @LayoutlibDelegate
    static float nGetScaleY(long groupPtr) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        return group.getScaleY();
    }

    @LayoutlibDelegate
    static void nSetScaleY(long groupPtr, float scaleY) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        group.setScaleY(scaleY);
    }

    @LayoutlibDelegate
    static float nGetTranslateX(long groupPtr) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        return group.getTranslateX();
    }

    @LayoutlibDelegate
    static void nSetTranslateX(long groupPtr, float translateX) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        group.setTranslateX(translateX);
    }

    @LayoutlibDelegate
    static float nGetTranslateY(long groupPtr) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        return group.getTranslateY();
    }

    @LayoutlibDelegate
    static void nSetTranslateY(long groupPtr, float translateY) {
        VGroup_Delegate group = VNativeObject.getDelegate(groupPtr);
        group.setTranslateY(translateY);
    }

    @LayoutlibDelegate
    static void nSetPathData(long pathPtr, long pathDataPtr) {
        VPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        path.setPathData(PathParser_Delegate.getDelegate(pathDataPtr).getPathDataNodes());
    }

    @LayoutlibDelegate
    static float nGetStrokeWidth(long pathPtr) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        return path.getStrokeWidth();
    }

    @LayoutlibDelegate
    static void nSetStrokeWidth(long pathPtr, float width) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        path.setStrokeWidth(width);
    }

    @LayoutlibDelegate
    static int nGetStrokeColor(long pathPtr) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        return path.getStrokeColor();
    }

    @LayoutlibDelegate
    static void nSetStrokeColor(long pathPtr, int strokeColor) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        path.setStrokeColor(strokeColor);
    }

    @LayoutlibDelegate
    static float nGetStrokeAlpha(long pathPtr) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        return path.getStrokeAlpha();
    }

    @LayoutlibDelegate
    static void nSetStrokeAlpha(long pathPtr, float alpha) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        path.setStrokeAlpha(alpha);
    }

    @LayoutlibDelegate
    static int nGetFillColor(long pathPtr) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        return path.getFillColor();
    }

    @LayoutlibDelegate
    static void nSetFillColor(long pathPtr, int fillColor) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        path.setFillColor(fillColor);
    }

    @LayoutlibDelegate
    static float nGetFillAlpha(long pathPtr) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        return path.getFillAlpha();
    }

    @LayoutlibDelegate
    static void nSetFillAlpha(long pathPtr, float fillAlpha) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        path.setFillAlpha(fillAlpha);
    }

    @LayoutlibDelegate
    static float nGetTrimPathStart(long pathPtr) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        return path.getTrimPathStart();
    }

    @LayoutlibDelegate
    static void nSetTrimPathStart(long pathPtr, float trimPathStart) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        path.setTrimPathStart(trimPathStart);
    }

    @LayoutlibDelegate
    static float nGetTrimPathEnd(long pathPtr) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        return path.getTrimPathEnd();
    }

    @LayoutlibDelegate
    static void nSetTrimPathEnd(long pathPtr, float trimPathEnd) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        path.setTrimPathEnd(trimPathEnd);
    }

    @LayoutlibDelegate
    static float nGetTrimPathOffset(long pathPtr) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        return path.getTrimPathOffset();
    }

    @LayoutlibDelegate
    static void nSetTrimPathOffset(long pathPtr, float trimPathOffset) {
        VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
        path.setTrimPathOffset(trimPathOffset);
    }

    /**
     * Base class for all the internal Delegates that does two functions:
     * <ol>
     *     <li>Serves as base class to store all the delegates in one {@link DelegateManager}
     *     <li>Provides setName for all the classes. {@link VPathRenderer_Delegate} does actually
     *     not need it
     * </ol>
     */
    abstract static class VNativeObject {
        long mNativePtr = 0;

        @NonNull
        static <T> T getDelegate(long nativePtr) {
            //noinspection unchecked
            T vNativeObject = (T) sPathManager.getDelegate(nativePtr);

            assert vNativeObject != null;
            return vNativeObject;
        }

        abstract void setName(String name);

        void setNativePtr(long nativePtr) {
            mNativePtr = nativePtr;
        }

        /**
         * Method to explicitly dispose native objects
         */
        void dispose() {
        }
    }

    private static class VClipPath_Delegate extends VPath_Delegate {
        private VClipPath_Delegate() {
            // Empty constructor.
        }

        private VClipPath_Delegate(VClipPath_Delegate copy) {
            super(copy);
        }

        @Override
        public boolean isClipPath() {
            return true;
        }
    }

    static class VFullPath_Delegate extends VPath_Delegate {
        // These constants need to be kept in sync with their values in VectorDrawable.VFullPath
        private static final int STROKE_WIDTH_INDEX = 0;
        private static final int STROKE_COLOR_INDEX = 1;
        private static final int STROKE_ALPHA_INDEX = 2;
        private static final int FILL_COLOR_INDEX = 3;
        private static final int FILL_ALPHA_INDEX = 4;
        private static final int TRIM_PATH_START_INDEX = 5;
        private static final int TRIM_PATH_END_INDEX = 6;
        private static final int TRIM_PATH_OFFSET_INDEX = 7;
        private static final int STROKE_LINE_CAP_INDEX = 8;
        private static final int STROKE_LINE_JOIN_INDEX = 9;
        private static final int STROKE_MITER_LIMIT_INDEX = 10;
        private static final int FILL_TYPE_INDEX = 11;

        private static final int LINECAP_BUTT = 0;
        private static final int LINECAP_ROUND = 1;
        private static final int LINECAP_SQUARE = 2;

        private static final int LINEJOIN_MITER = 0;
        private static final int LINEJOIN_ROUND = 1;
        private static final int LINEJOIN_BEVEL = 2;

        @NonNull
        public Consumer<Float> getFloatPropertySetter(int propertyIdx) {
            switch (propertyIdx) {
                case STROKE_WIDTH_INDEX:
                    return this::setStrokeWidth;
                case STROKE_ALPHA_INDEX:
                    return this::setStrokeAlpha;
                case FILL_ALPHA_INDEX:
                    return this::setFillAlpha;
                case TRIM_PATH_START_INDEX:
                    return this::setTrimPathStart;
                case TRIM_PATH_END_INDEX:
                    return this::setTrimPathEnd;
                case TRIM_PATH_OFFSET_INDEX:
                    return this::setTrimPathOffset;
            }

            assert false : ("Invalid VFullPath_Delegate property index " + propertyIdx);
            return t -> {};
        }

        @NonNull
        public Consumer<Integer> getIntPropertySetter(int propertyIdx) {
            switch (propertyIdx) {
                case STROKE_COLOR_INDEX:
                    return this::setStrokeColor;
                case FILL_COLOR_INDEX:
                    return this::setFillColor;
            }

            assert false : ("Invalid VFullPath_Delegate property index " + propertyIdx);
            return t -> {};
        }

        /////////////////////////////////////////////////////
        // Variables below need to be copied (deep copy if applicable) for mutation.

        int mStrokeColor = Color.TRANSPARENT;
        float mStrokeWidth = 0;

        int mFillColor = Color.TRANSPARENT;
        long mStrokeGradient = 0;
        long mFillGradient = 0;
        float mStrokeAlpha = 1.0f;
        float mFillAlpha = 1.0f;
        float mTrimPathStart = 0;
        float mTrimPathEnd = 1;
        float mTrimPathOffset = 0;

        Cap mStrokeLineCap = BUTT;
        Join mStrokeLineJoin = MITER;
        float mStrokeMiterlimit = 4;

        int mFillType = 0; // WINDING(0) is the default value. See Path.FillType

        private VFullPath_Delegate() {
            // Empty constructor.
        }

        private VFullPath_Delegate(VFullPath_Delegate copy) {
            super(copy);

            mStrokeColor = copy.mStrokeColor;
            mStrokeWidth = copy.mStrokeWidth;
            mStrokeAlpha = copy.mStrokeAlpha;
            mFillColor = copy.mFillColor;
            mFillAlpha = copy.mFillAlpha;
            mTrimPathStart = copy.mTrimPathStart;
            mTrimPathEnd = copy.mTrimPathEnd;
            mTrimPathOffset = copy.mTrimPathOffset;

            mStrokeLineCap = copy.mStrokeLineCap;
            mStrokeLineJoin = copy.mStrokeLineJoin;
            mStrokeMiterlimit = copy.mStrokeMiterlimit;

            mStrokeGradient = copy.mStrokeGradient;
            mFillGradient = copy.mFillGradient;
            mFillType = copy.mFillType;
        }

        private int getStrokeLineCap() {
            switch (mStrokeLineCap) {
                case BUTT:
                    return LINECAP_BUTT;
                case ROUND:
                    return LINECAP_ROUND;
                case SQUARE:
                    return LINECAP_SQUARE;
                default:
                    assert false;
            }

            return -1;
        }

        private void setStrokeLineCap(int cap) {
            switch (cap) {
                case LINECAP_BUTT:
                    mStrokeLineCap = BUTT;
                    break;
                case LINECAP_ROUND:
                    mStrokeLineCap = ROUND;
                    break;
                case LINECAP_SQUARE:
                    mStrokeLineCap = SQUARE;
                    break;
                default:
                    assert false;
            }
        }

        private int getStrokeLineJoin() {
            switch (mStrokeLineJoin) {
                case MITER:
                    return LINEJOIN_MITER;
                case ROUND:
                    return LINEJOIN_ROUND;
                case BEVEL:
                    return LINEJOIN_BEVEL;
                default:
                    assert false;
            }

            return -1;
        }

        private void setStrokeLineJoin(int join) {
            switch (join) {
                case LINEJOIN_BEVEL:
                    mStrokeLineJoin = BEVEL;
                    break;
                case LINEJOIN_MITER:
                    mStrokeLineJoin = MITER;
                    break;
                case LINEJOIN_ROUND:
                    mStrokeLineJoin = Join.ROUND;
                    break;
                default:
                    assert false;
            }
        }

        private int getStrokeColor() {
            return mStrokeColor;
        }

        private void setStrokeColor(int strokeColor) {
            mStrokeColor = strokeColor;
        }

        private float getStrokeWidth() {
            return mStrokeWidth;
        }

        private void setStrokeWidth(float strokeWidth) {
            mStrokeWidth = strokeWidth;
        }

        private float getStrokeAlpha() {
            return mStrokeAlpha;
        }

        private void setStrokeAlpha(float strokeAlpha) {
            mStrokeAlpha = strokeAlpha;
        }

        private int getFillColor() {
            return mFillColor;
        }

        private void setFillColor(int fillColor) {
            mFillColor = fillColor;
        }

        private float getFillAlpha() {
            return mFillAlpha;
        }

        private void setFillAlpha(float fillAlpha) {
            mFillAlpha = fillAlpha;
        }

        private float getTrimPathStart() {
            return mTrimPathStart;
        }

        private void setTrimPathStart(float trimPathStart) {
            mTrimPathStart = trimPathStart;
        }

        private float getTrimPathEnd() {
            return mTrimPathEnd;
        }

        private void setTrimPathEnd(float trimPathEnd) {
            mTrimPathEnd = trimPathEnd;
        }

        private float getTrimPathOffset() {
            return mTrimPathOffset;
        }

        private void setTrimPathOffset(float trimPathOffset) {
            mTrimPathOffset = trimPathOffset;
        }

        private void setStrokeMiterlimit(float limit) {
            mStrokeMiterlimit = limit;
        }

        private float getStrokeMiterlimit() {
            return mStrokeMiterlimit;
        }

        private void setStrokeGradient(long gradientPtr) {
            mStrokeGradient = gradientPtr;
        }

        private void setFillGradient(long gradientPtr) {
            mFillGradient = gradientPtr;
        }

        private void setFillType(int fillType) {
            mFillType = fillType;
        }

        private int getFillType() {
            return mFillType;
        }
    }

    static class VGroup_Delegate extends VNativeObject {
        // This constants need to be kept in sync with their definitions in VectorDrawable.Group
        private static final int ROTATE_INDEX = 0;
        private static final int PIVOT_X_INDEX = 1;
        private static final int PIVOT_Y_INDEX = 2;
        private static final int SCALE_X_INDEX = 3;
        private static final int SCALE_Y_INDEX = 4;
        private static final int TRANSLATE_X_INDEX = 5;
        private static final int TRANSLATE_Y_INDEX = 6;

        public Consumer<Float> getPropertySetter(int propertyIdx) {
            switch (propertyIdx) {
                case ROTATE_INDEX:
                    return this::setRotation;
                case PIVOT_X_INDEX:
                    return this::setPivotX;
                case PIVOT_Y_INDEX:
                    return this::setPivotY;
                case SCALE_X_INDEX:
                    return this::setScaleX;
                case SCALE_Y_INDEX:
                    return this::setScaleY;
                case TRANSLATE_X_INDEX:
                    return this::setTranslateX;
                case TRANSLATE_Y_INDEX:
                    return this::setTranslateY;
            }

            assert false : ("Invalid VGroup_Delegate property index " + propertyIdx);
            return t -> {};
        }

        /////////////////////////////////////////////////////
        // Variables below need to be copied (deep copy if applicable) for mutation.
        final ArrayList<Object> mChildren = new ArrayList<>();
        // mStackedMatrix is only used temporarily when drawing, it combines all
        // the parents' local matrices with the current one.
        private final Matrix mStackedMatrix = new Matrix();
        // mLocalMatrix is updated based on the update of transformation information,
        // either parsed from the XML or by animation.
        private final Matrix mLocalMatrix = new Matrix();
        private float mRotate = 0;
        private float mPivotX = 0;
        private float mPivotY = 0;
        private float mScaleX = 1;
        private float mScaleY = 1;
        private float mTranslateX = 0;
        private float mTranslateY = 0;
        private int mChangingConfigurations;
        private String mGroupName = null;

        private VGroup_Delegate(VGroup_Delegate copy, ArrayMap<String, Object> targetsMap) {
            mRotate = copy.mRotate;
            mPivotX = copy.mPivotX;
            mPivotY = copy.mPivotY;
            mScaleX = copy.mScaleX;
            mScaleY = copy.mScaleY;
            mTranslateX = copy.mTranslateX;
            mTranslateY = copy.mTranslateY;
            mGroupName = copy.mGroupName;
            mChangingConfigurations = copy.mChangingConfigurations;
            if (mGroupName != null) {
                targetsMap.put(mGroupName, this);
            }

            mLocalMatrix.set(copy.mLocalMatrix);
        }

        private VGroup_Delegate() {
        }

        private void updateLocalMatrix() {
            // The order we apply is the same as the
            // RenderNode.cpp::applyViewPropertyTransforms().
            mLocalMatrix.reset();
            mLocalMatrix.postTranslate(-mPivotX, -mPivotY);
            mLocalMatrix.postScale(mScaleX, mScaleY);
            mLocalMatrix.postRotate(mRotate, 0, 0);
            mLocalMatrix.postTranslate(mTranslateX + mPivotX, mTranslateY + mPivotY);
        }

        /* Setters and Getters, used by animator from AnimatedVectorDrawable. */
        private float getRotation() {
            return mRotate;
        }

        private void setRotation(float rotation) {
            if (rotation != mRotate) {
                mRotate = rotation;
                updateLocalMatrix();
            }
        }

        private float getPivotX() {
            return mPivotX;
        }

        private void setPivotX(float pivotX) {
            if (pivotX != mPivotX) {
                mPivotX = pivotX;
                updateLocalMatrix();
            }
        }

        private float getPivotY() {
            return mPivotY;
        }

        private void setPivotY(float pivotY) {
            if (pivotY != mPivotY) {
                mPivotY = pivotY;
                updateLocalMatrix();
            }
        }

        private float getScaleX() {
            return mScaleX;
        }

        private void setScaleX(float scaleX) {
            if (scaleX != mScaleX) {
                mScaleX = scaleX;
                updateLocalMatrix();
            }
        }

        private float getScaleY() {
            return mScaleY;
        }

        private void setScaleY(float scaleY) {
            if (scaleY != mScaleY) {
                mScaleY = scaleY;
                updateLocalMatrix();
            }
        }

        private float getTranslateX() {
            return mTranslateX;
        }

        private void setTranslateX(float translateX) {
            if (translateX != mTranslateX) {
                mTranslateX = translateX;
                updateLocalMatrix();
            }
        }

        private float getTranslateY() {
            return mTranslateY;
        }

        private void setTranslateY(float translateY) {
            if (translateY != mTranslateY) {
                mTranslateY = translateY;
                updateLocalMatrix();
            }
        }

        @Override
        public void setName(String name) {
            mGroupName = name;
        }

        @Override
        protected void dispose() {
            mChildren.stream().filter(child -> child instanceof VNativeObject).forEach(child
                    -> {
                VNativeObject nativeObject = (VNativeObject) child;
                if (nativeObject.mNativePtr != 0) {
                    sPathManager.removeJavaReferenceFor(nativeObject.mNativePtr);
                    nativeObject.mNativePtr = 0;
                }
                nativeObject.dispose();
            });
            mChildren.clear();
        }

        @Override
        protected void finalize() throws Throwable {
            super.finalize();
        }
    }

    public static class VPath_Delegate extends VNativeObject {
        protected PathParser_Delegate.PathDataNode[] mNodes = null;
        String mPathName;
        int mChangingConfigurations;

        public VPath_Delegate() {
            // Empty constructor.
        }

        public VPath_Delegate(VPath_Delegate copy) {
            mPathName = copy.mPathName;
            mChangingConfigurations = copy.mChangingConfigurations;
            mNodes = copy.mNodes != null ? PathParser_Delegate.deepCopyNodes(copy.mNodes) : null;
        }

        public void toPath(Path path) {
            path.reset();
            if (mNodes != null) {
                PathParser_Delegate.PathDataNode.nodesToPath(mNodes,
                        Path_Delegate.getDelegate(path.mNativePath));
            }
        }

        @Override
        public void setName(String name) {
            mPathName = name;
        }

        public boolean isClipPath() {
            return false;
        }

        private void setPathData(PathParser_Delegate.PathDataNode[] nodes) {
            if (!PathParser_Delegate.canMorph(mNodes, nodes)) {
                // This should not happen in the middle of animation.
                mNodes = PathParser_Delegate.deepCopyNodes(nodes);
            } else {
                PathParser_Delegate.updateNodes(mNodes, nodes);
            }
        }

        @Override
        void dispose() {
            mNodes = null;
        }
    }

    static class VPathRenderer_Delegate extends VNativeObject {
        /* Right now the internal data structure is organized as a tree.
         * Each node can be a group node, or a path.
         * A group node can have groups or paths as children, but a path node has
         * no children.
         * One example can be:
         *                 Root Group
         *                /    |     \
         *           Group    Path    Group
         *          /     \             |
         *         Path   Path         Path
         *
         */
        // Variables that only used temporarily inside the draw() call, so there
        // is no need for deep copying.
        private final Path mPath;
        private final Path mRenderPath;
        private final Matrix mFinalPathMatrix = new Matrix();
        private final long mRootGroupPtr;
        private float mViewportWidth = 0;
        private float mViewportHeight = 0;
        private float mRootAlpha = 1.0f;
        private Paint mStrokePaint;
        private Paint mFillPaint;
        private PathMeasure mPathMeasure;
        private boolean mAntiAlias = true;

        private VPathRenderer_Delegate(long rootGroupPtr) {
            mRootGroupPtr = rootGroupPtr;
            mPath = new Path();
            mRenderPath = new Path();
        }

        private VPathRenderer_Delegate(VPathRenderer_Delegate rendererToCopy,
                long rootGroupPtr) {
            this(rootGroupPtr);
            mViewportWidth = rendererToCopy.mViewportWidth;
            mViewportHeight = rendererToCopy.mViewportHeight;
            mRootAlpha = rendererToCopy.mRootAlpha;
        }

        private float getRootAlpha() {
            return mRootAlpha;
        }

        void setRootAlpha(float alpha) {
            mRootAlpha = alpha;
        }

        private void drawGroupTree(VGroup_Delegate currentGroup, Matrix currentMatrix,
                long canvasPtr, int w, int h, long filterPtr) {
            // Calculate current group's matrix by preConcat the parent's and
            // and the current one on the top of the stack.
            // Basically the Mfinal = Mviewport * M0 * M1 * M2;
            // Mi the local matrix at level i of the group tree.
            currentGroup.mStackedMatrix.set(currentMatrix);
            currentGroup.mStackedMatrix.preConcat(currentGroup.mLocalMatrix);

            // Save the current clip information, which is local to this group.
            Canvas_Delegate.nSave(canvasPtr, MATRIX_SAVE_FLAG | CLIP_SAVE_FLAG);
            // Draw the group tree in the same order as the XML file.
            for (int i = 0; i < currentGroup.mChildren.size(); i++) {
                Object child = currentGroup.mChildren.get(i);
                if (child instanceof VGroup_Delegate) {
                    VGroup_Delegate childGroup = (VGroup_Delegate) child;
                    drawGroupTree(childGroup, currentGroup.mStackedMatrix,
                            canvasPtr, w, h, filterPtr);
                } else if (child instanceof VPath_Delegate) {
                    VPath_Delegate childPath = (VPath_Delegate) child;
                    drawPath(currentGroup, childPath, canvasPtr, w, h, filterPtr);
                }
            }
            Canvas_Delegate.nRestore(canvasPtr);
        }

        public void draw(long canvasPtr, long filterPtr, int w, int h) {
            // Traverse the tree in pre-order to draw.
            drawGroupTree(VNativeObject.getDelegate(mRootGroupPtr), Matrix.IDENTITY_MATRIX, canvasPtr, w, h, filterPtr);
        }

        private void drawPath(VGroup_Delegate VGroup, VPath_Delegate VPath, long canvasPtr,
                int w,
                int h,
                long filterPtr) {
            final float scaleX = w / mViewportWidth;
            final float scaleY = h / mViewportHeight;
            final float minScale = Math.min(scaleX, scaleY);
            final Matrix groupStackedMatrix = VGroup.mStackedMatrix;

            mFinalPathMatrix.set(groupStackedMatrix);
            mFinalPathMatrix.postScale(scaleX, scaleY);

            final float matrixScale = getMatrixScale(groupStackedMatrix);
            if (matrixScale == 0) {
                // When either x or y is scaled to 0, we don't need to draw anything.
                return;
            }
            VPath.toPath(mPath);
            final Path path = mPath;

            mRenderPath.reset();

            if (VPath.isClipPath()) {
                mRenderPath.setFillType(FillType.WINDING);
                mRenderPath.addPath(path, mFinalPathMatrix);
                Canvas_Delegate.nClipPath(canvasPtr, mRenderPath.mNativePath, Op
                        .INTERSECT.nativeInt);
            } else {
                VFullPath_Delegate fullPath = (VFullPath_Delegate) VPath;
                if (fullPath.mTrimPathStart != 0.0f || fullPath.mTrimPathEnd != 1.0f) {
                    float start = (fullPath.mTrimPathStart + fullPath.mTrimPathOffset) % 1.0f;
                    float end = (fullPath.mTrimPathEnd + fullPath.mTrimPathOffset) % 1.0f;

                    if (mPathMeasure == null) {
                        mPathMeasure = new PathMeasure();
                    }
                    mPathMeasure.setPath(mPath, false);

                    float len = mPathMeasure.getLength();
                    start = start * len;
                    end = end * len;
                    path.reset();
                    if (start > end) {
                        mPathMeasure.getSegment(start, len, path, true);
                        mPathMeasure.getSegment(0f, end, path, true);
                    } else {
                        mPathMeasure.getSegment(start, end, path, true);
                    }
                    path.rLineTo(0, 0); // fix bug in measure
                }
                mRenderPath.addPath(path, mFinalPathMatrix);

                if (fullPath.mFillColor != Color.TRANSPARENT) {
                    if (mFillPaint == null) {
                        mFillPaint = new Paint();
                        mFillPaint.setStyle(Style.FILL);
                        mFillPaint.setAntiAlias(mAntiAlias);
                    }

                    final Paint fillPaint = mFillPaint;
                    fillPaint.setColor(applyAlpha(applyAlpha(fullPath.mFillColor, fullPath
                      .mFillAlpha), getRootAlpha()));
                    Paint_Delegate fillPaintDelegate = Paint_Delegate.getDelegate(fillPaint
                            .getNativeInstance());
                    // mFillPaint can not be null at this point so we will have a delegate
                    assert fillPaintDelegate != null;
                    fillPaintDelegate.setColorFilter(filterPtr);

                    Shader_Delegate shaderDelegate =
                            Shader_Delegate.getDelegate(fullPath.mFillGradient);
                    if (shaderDelegate != null) {
                        // If there is a shader, apply the local transformation to make sure
                        // the gradient is transformed to match the viewport
                        shaderDelegate.setLocalMatrix(mFinalPathMatrix.ni());
                        shaderDelegate.setAlpha(fullPath.mFillAlpha);
                    }

                    fillPaintDelegate.setShader(fullPath.mFillGradient);
                    Path_Delegate.nSetFillType(mRenderPath.mNativePath, fullPath.mFillType);
                    BaseCanvas_Delegate.nDrawPath(canvasPtr, mRenderPath.mNativePath, fillPaint
                            .getNativeInstance());
                    if (shaderDelegate != null) {
                        // Remove the local matrix
                        shaderDelegate.setLocalMatrix(0);
                    }
                }

                if (fullPath.mStrokeColor != Color.TRANSPARENT) {
                    if (mStrokePaint == null) {
                        mStrokePaint = new Paint();
                        mStrokePaint.setStyle(Style.STROKE);
                        mStrokePaint.setAntiAlias(mAntiAlias);
                    }

                    final Paint strokePaint = mStrokePaint;
                    if (fullPath.mStrokeLineJoin != null) {
                        strokePaint.setStrokeJoin(fullPath.mStrokeLineJoin);
                    }

                    if (fullPath.mStrokeLineCap != null) {
                        strokePaint.setStrokeCap(fullPath.mStrokeLineCap);
                    }

                    strokePaint.setStrokeMiter(fullPath.mStrokeMiterlimit);
                    strokePaint.setColor(applyAlpha(applyAlpha(fullPath.mStrokeColor, fullPath
                      .mStrokeAlpha), getRootAlpha()));
                    Paint_Delegate strokePaintDelegate = Paint_Delegate.getDelegate(strokePaint
                            .getNativeInstance());
                    // mStrokePaint can not be null at this point so we will have a delegate
                    assert strokePaintDelegate != null;
                    strokePaintDelegate.setColorFilter(filterPtr);
                    final float finalStrokeScale = minScale * matrixScale;
                    strokePaint.setStrokeWidth(fullPath.mStrokeWidth * finalStrokeScale);
                    Shader_Delegate strokeShaderDelegate =
                            Shader_Delegate.getDelegate(fullPath.mStrokeGradient);
                    if (strokeShaderDelegate != null) {
                        strokeShaderDelegate.setAlpha(fullPath.mStrokeAlpha);
                    }
                    strokePaintDelegate.setShader(fullPath.mStrokeGradient);
                    BaseCanvas_Delegate.nDrawPath(canvasPtr, mRenderPath.mNativePath, strokePaint
                            .getNativeInstance());
                }
            }
        }

        private float getMatrixScale(Matrix groupStackedMatrix) {
            // Given unit vectors A = (0, 1) and B = (1, 0).
            // After matrix mapping, we got A' and B'. Let theta = the angel b/t A' and B'.
            // Therefore, the final scale we want is min(|A'| * sin(theta), |B'| * sin(theta)),
            // which is (|A'| * |B'| * sin(theta)) / max (|A'|, |B'|);
            // If  max (|A'|, |B'|) = 0, that means either x or y has a scale of 0.
            //
            // For non-skew case, which is most of the cases, matrix scale is computing exactly the
            // scale on x and y axis, and take the minimal of these two.
            // For skew case, an unit square will mapped to a parallelogram. And this function will
            // return the minimal height of the 2 bases.
            float[] unitVectors = new float[]{0, 1, 1, 0};
            groupStackedMatrix.mapVectors(unitVectors);
            float scaleX = MathUtils.mag(unitVectors[0], unitVectors[1]);
            float scaleY = MathUtils.mag(unitVectors[2], unitVectors[3]);
            float crossProduct = MathUtils.cross(unitVectors[0], unitVectors[1],
                    unitVectors[2], unitVectors[3]);
            float maxScale = MathUtils.max(scaleX, scaleY);

            float matrixScale = 0;
            if (maxScale > 0) {
                matrixScale = MathUtils.abs(crossProduct) / maxScale;
            }
            if (DBG_VECTOR_DRAWABLE) {
                Log.d(LOGTAG, "Scale x " + scaleX + " y " + scaleY + " final " + matrixScale);
            }
            return matrixScale;
        }

        private void setAntiAlias(boolean aa) {
            mAntiAlias = aa;
        }

        @Override
        public void setName(String name) {
        }

        @Override
        protected void finalize() throws Throwable {
            // The mRootGroupPtr is not explicitly freed by anything in the VectorDrawable so we
            // need to free it here.
            VNativeObject nativeObject = sPathManager.getDelegate(mRootGroupPtr);
            sPathManager.removeJavaReferenceFor(mRootGroupPtr);
            assert nativeObject != null;
            nativeObject.dispose();

            super.finalize();
        }
    }
}