• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <hwui/Paint.h>
18 
19 #include "ColorFilter.h"
20 #include "GraphicsJNI.h"
21 #include "PathParser.h"
22 #include "VectorDrawable.h"
23 
24 namespace android {
25 using namespace uirenderer;
26 using namespace uirenderer::VectorDrawable;
27 
28 /**
29  * VectorDrawable's pre-draw construction.
30  */
createTree(JNIEnv *,jobject,jlong groupPtr)31 static jlong createTree(JNIEnv*, jobject, jlong groupPtr) {
32     VectorDrawable::Group* rootGroup = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
33     VectorDrawable::Tree* tree = new VectorDrawable::Tree(rootGroup);
34     return reinterpret_cast<jlong>(tree);
35 }
36 
createTreeFromCopy(JNIEnv *,jobject,jlong treePtr,jlong groupPtr)37 static jlong createTreeFromCopy(JNIEnv*, jobject, jlong treePtr, jlong groupPtr) {
38     VectorDrawable::Group* rootGroup = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
39     VectorDrawable::Tree* treeToCopy = reinterpret_cast<VectorDrawable::Tree*>(treePtr);
40     VectorDrawable::Tree* tree = new VectorDrawable::Tree(treeToCopy, rootGroup);
41     return reinterpret_cast<jlong>(tree);
42 }
43 
createEmptyFullPath(JNIEnv *,jobject)44 static jlong createEmptyFullPath(JNIEnv*, jobject) {
45     VectorDrawable::FullPath* newPath = new VectorDrawable::FullPath();
46     return reinterpret_cast<jlong>(newPath);
47 }
48 
createFullPath(JNIEnv *,jobject,jlong srcFullPathPtr)49 static jlong createFullPath(JNIEnv*, jobject, jlong srcFullPathPtr) {
50     VectorDrawable::FullPath* srcFullPath =
51             reinterpret_cast<VectorDrawable::FullPath*>(srcFullPathPtr);
52     VectorDrawable::FullPath* newPath = new VectorDrawable::FullPath(*srcFullPath);
53     return reinterpret_cast<jlong>(newPath);
54 }
55 
createEmptyClipPath(JNIEnv *,jobject)56 static jlong createEmptyClipPath(JNIEnv*, jobject) {
57     VectorDrawable::ClipPath* newPath = new VectorDrawable::ClipPath();
58     return reinterpret_cast<jlong>(newPath);
59 }
60 
createClipPath(JNIEnv *,jobject,jlong srcClipPathPtr)61 static jlong createClipPath(JNIEnv*, jobject, jlong srcClipPathPtr) {
62     VectorDrawable::ClipPath* srcClipPath =
63             reinterpret_cast<VectorDrawable::ClipPath*>(srcClipPathPtr);
64     VectorDrawable::ClipPath* newPath = new VectorDrawable::ClipPath(*srcClipPath);
65     return reinterpret_cast<jlong>(newPath);
66 }
67 
createEmptyGroup(JNIEnv *,jobject)68 static jlong createEmptyGroup(JNIEnv*, jobject) {
69     VectorDrawable::Group* newGroup = new VectorDrawable::Group();
70     return reinterpret_cast<jlong>(newGroup);
71 }
72 
createGroup(JNIEnv *,jobject,jlong srcGroupPtr)73 static jlong createGroup(JNIEnv*, jobject, jlong srcGroupPtr) {
74     VectorDrawable::Group* srcGroup = reinterpret_cast<VectorDrawable::Group*>(srcGroupPtr);
75     VectorDrawable::Group* newGroup = new VectorDrawable::Group(*srcGroup);
76     return reinterpret_cast<jlong>(newGroup);
77 }
78 
setNodeName(JNIEnv * env,jobject,jlong nodePtr,jstring nameStr)79 static void setNodeName(JNIEnv* env, jobject, jlong nodePtr, jstring nameStr) {
80     VectorDrawable::Node* node = reinterpret_cast<VectorDrawable::Node*>(nodePtr);
81     const char* nodeName = env->GetStringUTFChars(nameStr, NULL);
82     node->setName(nodeName);
83     env->ReleaseStringUTFChars(nameStr, nodeName);
84 }
85 
addChild(JNIEnv *,jobject,jlong groupPtr,jlong childPtr)86 static void addChild(JNIEnv*, jobject, jlong groupPtr, jlong childPtr) {
87     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
88     VectorDrawable::Node* child = reinterpret_cast<VectorDrawable::Node*>(childPtr);
89     group->addChild(child);
90 }
91 
setAllowCaching(JNIEnv *,jobject,jlong treePtr,jboolean allowCaching)92 static void setAllowCaching(JNIEnv*, jobject, jlong treePtr, jboolean allowCaching) {
93     VectorDrawable::Tree* tree = reinterpret_cast<VectorDrawable::Tree*>(treePtr);
94     tree->setAllowCaching(allowCaching);
95 }
96 
setAntiAlias(JNIEnv *,jobject,jlong treePtr,jboolean aa)97 static void setAntiAlias(JNIEnv*, jobject, jlong treePtr, jboolean aa) {
98     VectorDrawable::Tree* tree = reinterpret_cast<VectorDrawable::Tree*>(treePtr);
99     tree->setAntiAlias(aa);
100 }
101 
102 /**
103  * Draw
104  */
draw(JNIEnv * env,jobject,jlong treePtr,jlong canvasPtr,jlong colorFilterPtr,jobject jrect,jboolean needsMirroring,jboolean canReuseCache)105 static jint draw(JNIEnv* env, jobject, jlong treePtr, jlong canvasPtr,
106         jlong colorFilterPtr, jobject jrect, jboolean needsMirroring, jboolean canReuseCache) {
107     VectorDrawable::Tree* tree = reinterpret_cast<VectorDrawable::Tree*>(treePtr);
108     Canvas* canvas = reinterpret_cast<Canvas*>(canvasPtr);
109     SkRect rect;
110     GraphicsJNI::jrect_to_rect(env, jrect, &rect);
111     auto colorFilter = ColorFilter::fromJava(colorFilterPtr);
112     auto skColorFilter = colorFilter != nullptr ? colorFilter->getInstance() : nullptr;
113     return tree->draw(canvas, skColorFilter.get(), rect, needsMirroring, canReuseCache);
114 }
115 
116 /**
117  * Setters and getters for updating staging properties that can happen both pre-draw and post draw.
118  */
setTreeViewportSize(JNIEnv *,jobject,jlong treePtr,jfloat viewportWidth,jfloat viewportHeight)119 static void setTreeViewportSize(JNIEnv*, jobject, jlong treePtr,
120         jfloat viewportWidth, jfloat viewportHeight) {
121     VectorDrawable::Tree* tree = reinterpret_cast<VectorDrawable::Tree*>(treePtr);
122     tree->mutateStagingProperties()->setViewportSize(viewportWidth, viewportHeight);
123 }
124 
setRootAlpha(JNIEnv *,jobject,jlong treePtr,jfloat alpha)125 static jboolean setRootAlpha(JNIEnv*, jobject, jlong treePtr, jfloat alpha) {
126     VectorDrawable::Tree* tree = reinterpret_cast<VectorDrawable::Tree*>(treePtr);
127     return tree->mutateStagingProperties()->setRootAlpha(alpha);
128 }
129 
getRootAlpha(JNIEnv *,jobject,jlong treePtr)130 static jfloat getRootAlpha(JNIEnv*, jobject, jlong treePtr) {
131     VectorDrawable::Tree* tree = reinterpret_cast<VectorDrawable::Tree*>(treePtr);
132     return tree->stagingProperties().getRootAlpha();
133 }
134 
updateFullPathPropertiesAndStrokeStyles(JNIEnv *,jobject,jlong fullPathPtr,jfloat strokeWidth,jint strokeColor,jfloat strokeAlpha,jint fillColor,jfloat fillAlpha,jfloat trimPathStart,jfloat trimPathEnd,jfloat trimPathOffset,jfloat strokeMiterLimit,jint strokeLineCap,jint strokeLineJoin,jint fillType)135 static void updateFullPathPropertiesAndStrokeStyles(JNIEnv*, jobject, jlong fullPathPtr,
136         jfloat strokeWidth, jint strokeColor, jfloat strokeAlpha, jint fillColor, jfloat fillAlpha,
137         jfloat trimPathStart, jfloat trimPathEnd, jfloat trimPathOffset, jfloat strokeMiterLimit,
138         jint strokeLineCap, jint strokeLineJoin, jint fillType) {
139     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
140     fullPath->mutateStagingProperties()->updateProperties(strokeWidth, strokeColor, strokeAlpha,
141             fillColor, fillAlpha, trimPathStart, trimPathEnd, trimPathOffset, strokeMiterLimit,
142             strokeLineCap, strokeLineJoin, fillType);
143 }
144 
updateFullPathFillGradient(JNIEnv *,jobject,jlong pathPtr,jlong fillGradientPtr)145 static void updateFullPathFillGradient(JNIEnv*, jobject, jlong pathPtr, jlong fillGradientPtr) {
146     VectorDrawable::FullPath* path = reinterpret_cast<VectorDrawable::FullPath*>(pathPtr);
147     SkShader* fillShader = reinterpret_cast<SkShader*>(fillGradientPtr);
148     path->mutateStagingProperties()->setFillGradient(fillShader);
149 }
150 
updateFullPathStrokeGradient(JNIEnv *,jobject,jlong pathPtr,jlong strokeGradientPtr)151 static void updateFullPathStrokeGradient(JNIEnv*, jobject, jlong pathPtr, jlong strokeGradientPtr) {
152     VectorDrawable::FullPath* path = reinterpret_cast<VectorDrawable::FullPath*>(pathPtr);
153     SkShader* strokeShader = reinterpret_cast<SkShader*>(strokeGradientPtr);
154     path->mutateStagingProperties()->setStrokeGradient(strokeShader);
155 }
156 
getFullPathProperties(JNIEnv * env,jobject,jlong fullPathPtr,jbyteArray outProperties,jint length)157 static jboolean getFullPathProperties(JNIEnv* env, jobject, jlong fullPathPtr,
158         jbyteArray outProperties, jint length) {
159     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
160     int8_t pathProperties[length];
161     bool success = fullPath->stagingProperties()->copyProperties(pathProperties, length);
162     env->SetByteArrayRegion(outProperties, 0, length, reinterpret_cast<int8_t*>(&pathProperties));
163     return success;
164 }
165 
getGroupProperties(JNIEnv * env,jobject,jlong groupPtr,jfloatArray outProperties,jint length)166 static jboolean getGroupProperties(JNIEnv* env, jobject, jlong groupPtr,
167         jfloatArray outProperties, jint length) {
168     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
169     float groupProperties[length];
170     bool success = group->stagingProperties()->copyProperties(groupProperties, length);
171     env->SetFloatArrayRegion(outProperties, 0, length, reinterpret_cast<float*>(&groupProperties));
172     return success;
173 }
174 
updateGroupProperties(JNIEnv *,jobject,jlong groupPtr,jfloat rotate,jfloat pivotX,jfloat pivotY,jfloat scaleX,jfloat scaleY,jfloat translateX,jfloat translateY)175 static void updateGroupProperties(JNIEnv*, jobject, jlong groupPtr, jfloat rotate, jfloat pivotX,
176         jfloat pivotY, jfloat scaleX, jfloat scaleY, jfloat translateX, jfloat translateY) {
177     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
178     group->mutateStagingProperties()->updateProperties(rotate, pivotX, pivotY, scaleX, scaleY,
179             translateX, translateY);
180 }
181 
setPathString(JNIEnv * env,jobject,jlong pathPtr,jstring inputStr,jint stringLength)182 static void setPathString(JNIEnv* env, jobject, jlong pathPtr, jstring inputStr,
183         jint stringLength) {
184     VectorDrawable::Path* path = reinterpret_cast<VectorDrawable::Path*>(pathPtr);
185     const char* pathString = env->GetStringUTFChars(inputStr, NULL);
186 
187     PathParser::ParseResult result;
188     PathData data;
189     PathParser::getPathDataFromAsciiString(&data, &result, pathString, stringLength);
190     if (result.failureOccurred) {
191         doThrowIAE(env, result.failureMessage.c_str());
192     }
193     path->mutateStagingProperties()->setData(data);
194     env->ReleaseStringUTFChars(inputStr, pathString);
195 }
196 
197 /**
198  * Setters and getters that should only be called from animation thread for animation purpose.
199  */
getRotation(JNIEnv *,jobject,jlong groupPtr)200 static jfloat getRotation(JNIEnv*, jobject, jlong groupPtr) {
201     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
202     return group->stagingProperties()->getRotation();
203 }
204 
setRotation(JNIEnv *,jobject,jlong groupPtr,jfloat rotation)205 static void setRotation(JNIEnv*, jobject, jlong groupPtr, jfloat rotation) {
206     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
207     group->mutateStagingProperties()->setRotation(rotation);
208 }
209 
getPivotX(JNIEnv *,jobject,jlong groupPtr)210 static jfloat getPivotX(JNIEnv*, jobject, jlong groupPtr) {
211     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
212     return group->stagingProperties()->getPivotX();
213 }
214 
setPivotX(JNIEnv *,jobject,jlong groupPtr,jfloat pivotX)215 static void setPivotX(JNIEnv*, jobject, jlong groupPtr, jfloat pivotX) {
216     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
217     group->mutateStagingProperties()->setPivotX(pivotX);
218 }
219 
getPivotY(JNIEnv *,jobject,jlong groupPtr)220 static jfloat getPivotY(JNIEnv*, jobject, jlong groupPtr) {
221     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
222     return group->stagingProperties()->getPivotY();
223 }
224 
setPivotY(JNIEnv *,jobject,jlong groupPtr,jfloat pivotY)225 static void setPivotY(JNIEnv*, jobject, jlong groupPtr, jfloat pivotY) {
226     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
227     group->mutateStagingProperties()->setPivotY(pivotY);
228 }
229 
getScaleX(JNIEnv *,jobject,jlong groupPtr)230 static jfloat getScaleX(JNIEnv*, jobject, jlong groupPtr) {
231     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
232     return group->stagingProperties()->getScaleX();
233 }
234 
setScaleX(JNIEnv *,jobject,jlong groupPtr,jfloat scaleX)235 static void setScaleX(JNIEnv*, jobject, jlong groupPtr, jfloat scaleX) {
236     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
237     group->mutateStagingProperties()->setScaleX(scaleX);
238 }
239 
getScaleY(JNIEnv *,jobject,jlong groupPtr)240 static jfloat getScaleY(JNIEnv*, jobject, jlong groupPtr) {
241     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
242     return group->stagingProperties()->getScaleY();
243 }
244 
setScaleY(JNIEnv *,jobject,jlong groupPtr,jfloat scaleY)245 static void setScaleY(JNIEnv*, jobject, jlong groupPtr, jfloat scaleY) {
246     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
247     group->mutateStagingProperties()->setScaleY(scaleY);
248 }
249 
getTranslateX(JNIEnv *,jobject,jlong groupPtr)250 static jfloat getTranslateX(JNIEnv*, jobject, jlong groupPtr) {
251     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
252     return group->stagingProperties()->getTranslateX();
253 }
254 
setTranslateX(JNIEnv *,jobject,jlong groupPtr,jfloat translateX)255 static void setTranslateX(JNIEnv*, jobject, jlong groupPtr, jfloat translateX) {
256     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
257     group->mutateStagingProperties()->setTranslateX(translateX);
258 }
259 
getTranslateY(JNIEnv *,jobject,jlong groupPtr)260 static jfloat getTranslateY(JNIEnv*, jobject, jlong groupPtr) {
261     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
262     return group->stagingProperties()->getTranslateY();
263 }
264 
setTranslateY(JNIEnv *,jobject,jlong groupPtr,jfloat translateY)265 static void setTranslateY(JNIEnv*, jobject, jlong groupPtr, jfloat translateY) {
266     VectorDrawable::Group* group = reinterpret_cast<VectorDrawable::Group*>(groupPtr);
267     group->mutateStagingProperties()->setTranslateY(translateY);
268 }
269 
setPathData(JNIEnv *,jobject,jlong pathPtr,jlong pathDataPtr)270 static void setPathData(JNIEnv*, jobject, jlong pathPtr, jlong pathDataPtr) {
271     VectorDrawable::Path* path = reinterpret_cast<VectorDrawable::Path*>(pathPtr);
272     PathData* pathData = reinterpret_cast<PathData*>(pathDataPtr);
273     path->mutateStagingProperties()->setData(*pathData);
274 }
275 
getStrokeWidth(JNIEnv *,jobject,jlong fullPathPtr)276 static jfloat getStrokeWidth(JNIEnv*, jobject, jlong fullPathPtr) {
277     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
278     return fullPath->stagingProperties()->getStrokeWidth();
279 }
280 
setStrokeWidth(JNIEnv *,jobject,jlong fullPathPtr,jfloat strokeWidth)281 static void setStrokeWidth(JNIEnv*, jobject, jlong fullPathPtr, jfloat strokeWidth) {
282     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
283     fullPath->mutateStagingProperties()->setStrokeWidth(strokeWidth);
284 }
285 
getStrokeColor(JNIEnv *,jobject,jlong fullPathPtr)286 static jint getStrokeColor(JNIEnv*, jobject, jlong fullPathPtr) {
287     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
288     return fullPath->stagingProperties()->getStrokeColor();
289 }
290 
setStrokeColor(JNIEnv *,jobject,jlong fullPathPtr,jint strokeColor)291 static void setStrokeColor(JNIEnv*, jobject, jlong fullPathPtr, jint strokeColor) {
292     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
293     fullPath->mutateStagingProperties()->setStrokeColor(strokeColor);
294 }
295 
getStrokeAlpha(JNIEnv *,jobject,jlong fullPathPtr)296 static jfloat getStrokeAlpha(JNIEnv*, jobject, jlong fullPathPtr) {
297     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
298     return fullPath->stagingProperties()->getStrokeAlpha();
299 }
300 
setStrokeAlpha(JNIEnv *,jobject,jlong fullPathPtr,jfloat strokeAlpha)301 static void setStrokeAlpha(JNIEnv*, jobject, jlong fullPathPtr, jfloat strokeAlpha) {
302     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
303     fullPath->mutateStagingProperties()->setStrokeAlpha(strokeAlpha);
304 }
305 
getFillColor(JNIEnv *,jobject,jlong fullPathPtr)306 static jint getFillColor(JNIEnv*, jobject, jlong fullPathPtr) {
307     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
308     return fullPath->stagingProperties()->getFillColor();
309 }
310 
setFillColor(JNIEnv *,jobject,jlong fullPathPtr,jint fillColor)311 static void setFillColor(JNIEnv*, jobject, jlong fullPathPtr, jint fillColor) {
312     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
313     fullPath->mutateStagingProperties()->setFillColor(fillColor);
314 }
315 
getFillAlpha(JNIEnv *,jobject,jlong fullPathPtr)316 static jfloat getFillAlpha(JNIEnv*, jobject, jlong fullPathPtr) {
317     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
318     return fullPath->stagingProperties()->getFillAlpha();
319 }
320 
setFillAlpha(JNIEnv *,jobject,jlong fullPathPtr,jfloat fillAlpha)321 static void setFillAlpha(JNIEnv*, jobject, jlong fullPathPtr, jfloat fillAlpha) {
322     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
323     fullPath->mutateStagingProperties()->setFillAlpha(fillAlpha);
324 }
325 
getTrimPathStart(JNIEnv *,jobject,jlong fullPathPtr)326 static jfloat getTrimPathStart(JNIEnv*, jobject, jlong fullPathPtr) {
327     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
328     return fullPath->stagingProperties()->getTrimPathStart();
329 }
330 
setTrimPathStart(JNIEnv *,jobject,jlong fullPathPtr,jfloat trimPathStart)331 static void setTrimPathStart(JNIEnv*, jobject, jlong fullPathPtr, jfloat trimPathStart) {
332     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
333     fullPath->mutateStagingProperties()->setTrimPathStart(trimPathStart);
334 }
335 
getTrimPathEnd(JNIEnv *,jobject,jlong fullPathPtr)336 static jfloat getTrimPathEnd(JNIEnv*, jobject, jlong fullPathPtr) {
337     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
338     return fullPath->stagingProperties()->getTrimPathEnd();
339 }
340 
setTrimPathEnd(JNIEnv *,jobject,jlong fullPathPtr,jfloat trimPathEnd)341 static void setTrimPathEnd(JNIEnv*, jobject, jlong fullPathPtr, jfloat trimPathEnd) {
342     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
343     fullPath->mutateStagingProperties()->setTrimPathEnd(trimPathEnd);
344 }
345 
getTrimPathOffset(JNIEnv *,jobject,jlong fullPathPtr)346 static jfloat getTrimPathOffset(JNIEnv*, jobject, jlong fullPathPtr) {
347     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
348     return fullPath->stagingProperties()->getTrimPathOffset();
349 }
350 
setTrimPathOffset(JNIEnv *,jobject,jlong fullPathPtr,jfloat trimPathOffset)351 static void setTrimPathOffset(JNIEnv*, jobject, jlong fullPathPtr, jfloat trimPathOffset) {
352     VectorDrawable::FullPath* fullPath = reinterpret_cast<VectorDrawable::FullPath*>(fullPathPtr);
353     fullPath->mutateStagingProperties()->setTrimPathOffset(trimPathOffset);
354 }
355 
356 static const JNINativeMethod gMethods[] = {
357         {"nDraw", "(JJJLandroid/graphics/Rect;ZZ)I", (void*)draw},
358         {"nGetFullPathProperties", "(J[BI)Z", (void*)getFullPathProperties},
359         {"nGetGroupProperties", "(J[FI)Z", (void*)getGroupProperties},
360         {"nSetPathString", "(JLjava/lang/String;I)V", (void*)setPathString},
361         {"nSetName", "(JLjava/lang/String;)V", (void*)setNodeName},
362 
363         // ------------- @FastNative ----------------
364 
365         {"nCreateTree", "(J)J", (void*)createTree},
366         {"nCreateTreeFromCopy", "(JJ)J", (void*)createTreeFromCopy},
367         {"nSetRendererViewportSize", "(JFF)V", (void*)setTreeViewportSize},
368         {"nSetRootAlpha", "(JF)Z", (void*)setRootAlpha},
369         {"nGetRootAlpha", "(J)F", (void*)getRootAlpha},
370         {"nSetAntiAlias", "(JZ)V", (void*)setAntiAlias},
371         {"nSetAllowCaching", "(JZ)V", (void*)setAllowCaching},
372 
373         {"nCreateFullPath", "()J", (void*)createEmptyFullPath},
374         {"nCreateFullPath", "(J)J", (void*)createFullPath},
375         {"nUpdateFullPathProperties", "(JFIFIFFFFFIII)V", (void*)updateFullPathPropertiesAndStrokeStyles},
376         {"nUpdateFullPathFillGradient", "(JJ)V", (void*)updateFullPathFillGradient},
377         {"nUpdateFullPathStrokeGradient", "(JJ)V", (void*)updateFullPathStrokeGradient},
378 
379         {"nCreateClipPath", "()J", (void*)createEmptyClipPath},
380         {"nCreateClipPath", "(J)J", (void*)createClipPath},
381         {"nCreateGroup", "()J", (void*)createEmptyGroup},
382         {"nCreateGroup", "(J)J", (void*)createGroup},
383         {"nUpdateGroupProperties", "(JFFFFFFF)V", (void*)updateGroupProperties},
384 
385         {"nAddChild", "(JJ)V", (void*)addChild},
386         {"nGetRotation", "(J)F", (void*)getRotation},
387         {"nSetRotation", "(JF)V", (void*)setRotation},
388         {"nGetPivotX", "(J)F", (void*)getPivotX},
389         {"nSetPivotX", "(JF)V", (void*)setPivotX},
390         {"nGetPivotY", "(J)F", (void*)getPivotY},
391         {"nSetPivotY", "(JF)V", (void*)setPivotY},
392         {"nGetScaleX", "(J)F", (void*)getScaleX},
393         {"nSetScaleX", "(JF)V", (void*)setScaleX},
394         {"nGetScaleY", "(J)F", (void*)getScaleY},
395         {"nSetScaleY", "(JF)V", (void*)setScaleY},
396         {"nGetTranslateX", "(J)F", (void*)getTranslateX},
397         {"nSetTranslateX", "(JF)V", (void*)setTranslateX},
398         {"nGetTranslateY", "(J)F", (void*)getTranslateY},
399         {"nSetTranslateY", "(JF)V", (void*)setTranslateY},
400 
401         {"nSetPathData", "(JJ)V", (void*)setPathData},
402         {"nGetStrokeWidth", "(J)F", (void*)getStrokeWidth},
403         {"nSetStrokeWidth", "(JF)V", (void*)setStrokeWidth},
404         {"nGetStrokeColor", "(J)I", (void*)getStrokeColor},
405         {"nSetStrokeColor", "(JI)V", (void*)setStrokeColor},
406         {"nGetStrokeAlpha", "(J)F", (void*)getStrokeAlpha},
407         {"nSetStrokeAlpha", "(JF)V", (void*)setStrokeAlpha},
408         {"nGetFillColor", "(J)I", (void*)getFillColor},
409         {"nSetFillColor", "(JI)V", (void*)setFillColor},
410         {"nGetFillAlpha", "(J)F", (void*)getFillAlpha},
411         {"nSetFillAlpha", "(JF)V", (void*)setFillAlpha},
412         {"nGetTrimPathStart", "(J)F", (void*)getTrimPathStart},
413         {"nSetTrimPathStart", "(JF)V", (void*)setTrimPathStart},
414         {"nGetTrimPathEnd", "(J)F", (void*)getTrimPathEnd},
415         {"nSetTrimPathEnd", "(JF)V", (void*)setTrimPathEnd},
416         {"nGetTrimPathOffset", "(J)F", (void*)getTrimPathOffset},
417         {"nSetTrimPathOffset", "(JF)V", (void*)setTrimPathOffset},
418 };
419 
register_android_graphics_drawable_VectorDrawable(JNIEnv * env)420 int register_android_graphics_drawable_VectorDrawable(JNIEnv* env) {
421     return RegisterMethodsOrDie(env, "android/graphics/drawable/VectorDrawable", gMethods, NELEM(gMethods));
422 }
423 
424 }; // namespace android
425