Skip to content

Commit eda123f

Browse files
Treehugger RobotGerrit Code Review
Treehugger Robot
authored and
Gerrit Code Review
committedApr 26, 2023
Merge "Introduce Path#rewind" into androidx-main
2 parents 738402d + d4173ae commit eda123f

File tree

9 files changed

+67
-0
lines changed

9 files changed

+67
-0
lines changed
 

Diff for: ‎compose/ui/ui-graphics/api/current.txt

+1
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ package androidx.compose.ui.graphics {
623623
method public void relativeMoveTo(float dx, float dy);
624624
method public void relativeQuadraticBezierTo(float dx1, float dy1, float dx2, float dy2);
625625
method public void reset();
626+
method public default void rewind();
626627
method public void setFillType(int);
627628
method public void translate(long offset);
628629
property public abstract int fillType;

Diff for: ‎compose/ui/ui-graphics/api/public_plus_experimental_current.txt

+1
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ package androidx.compose.ui.graphics {
626626
method public void relativeMoveTo(float dx, float dy);
627627
method public void relativeQuadraticBezierTo(float dx1, float dy1, float dx2, float dy2);
628628
method public void reset();
629+
method public default void rewind();
629630
method public void setFillType(int);
630631
method public void translate(long offset);
631632
property public abstract int fillType;

Diff for: ‎compose/ui/ui-graphics/api/restricted_current.txt

+1
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ package androidx.compose.ui.graphics {
658658
method public void relativeMoveTo(float dx, float dy);
659659
method public void relativeQuadraticBezierTo(float dx1, float dy1, float dx2, float dy2);
660660
method public void reset();
661+
method public default void rewind();
661662
method public void setFillType(int);
662663
method public void translate(long offset);
663664
property public abstract int fillType;

Diff for: ‎compose/ui/ui-graphics/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/PathTest.kt

+28
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import org.junit.Test
2525
import org.junit.runner.RunWith
2626
import androidx.test.ext.junit.runners.AndroidJUnit4
2727
import kotlin.math.PI
28+
import org.junit.Assert.assertFalse
29+
import org.junit.Assert.assertTrue
2830

2931
@SmallTest
3032
@RunWith(AndroidJUnit4::class)
@@ -78,4 +80,30 @@ class PathTest {
7880
]
7981
)
8082
}
83+
84+
@Test
85+
fun testRewindPath() {
86+
val androidPath = TestAndroidPath()
87+
val path = androidPath.asComposePath().apply {
88+
addRect(Rect(0f, 0f, 100f, 200f))
89+
}
90+
assertFalse(path.isEmpty)
91+
92+
path.rewind()
93+
94+
assertTrue(path.isEmpty)
95+
// Reset should not be invoked as the rewind method is implemented to call into the
96+
// corresponding rewind call in the framework and not call the default fallback
97+
assertEquals(0, androidPath.resetCount)
98+
}
99+
100+
class TestAndroidPath : android.graphics.Path() {
101+
102+
var resetCount = 0
103+
104+
override fun reset() {
105+
resetCount++
106+
super.reset()
107+
}
108+
}
81109
}

Diff for: ‎compose/ui/ui-graphics/src/androidMain/kotlin/androidx/compose/ui/graphics/AndroidPath.android.kt

+4
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ inline fun Path.asAndroidPath(): android.graphics.Path =
180180
internalPath.reset()
181181
}
182182

183+
override fun rewind() {
184+
internalPath.rewind()
185+
}
186+
183187
override fun translate(offset: Offset) {
184188
mMatrix.reset()
185189
mMatrix.setTranslate(offset.x, offset.y)

Diff for: ‎compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/Path.kt

+10
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,16 @@ expect fun Path(): Path
217217
*/
218218
fun reset()
219219

220+
/**
221+
* Rewinds the path: clears any lines and curves from the path but keeps the internal data
222+
* structure for faster reuse.
223+
*/
224+
fun rewind() {
225+
// Call reset to avoid AbstractMethodAdded lint API errors. Implementations are already
226+
// calling into the respective platform Path#rewind equivalent.
227+
reset()
228+
}
229+
220230
/**
221231
* Translates all the segments of every subpath by the given offset.
222232
*/

Diff for: ‎compose/ui/ui-graphics/src/commonTest/kotlin/androidx/compose/ui/graphics/vector/PathParserTest.kt

+4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ class PathParserTest {
179179
// NO-OP
180180
}
181181

182+
override fun rewind() {
183+
// NO-OP
184+
}
185+
182186
override fun translate(offset: Offset) {
183187
// NO-OP
184188
}

Diff for: ‎compose/ui/ui-graphics/src/desktopTest/kotlin/androidx/compose/ui/graphics/DesktopPathTest.kt

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import androidx.compose.ui.geometry.Rect
2020
import androidx.compose.ui.geometry.RoundRect
2121
import androidx.compose.ui.test.InternalTestApi
2222
import org.junit.Assert.assertEquals
23+
import org.junit.Assert.assertTrue
24+
import org.junit.Assert.assertFalse
2325
import org.junit.Test
2426

2527
@OptIn(InternalTestApi::class)
@@ -211,4 +213,16 @@ class DesktopPathTest : DesktopGraphicsTest() {
211213

212214
assertEquals(PathFillType.EvenOdd, path.fillType)
213215
}
216+
217+
@Test
218+
fun testRewind() {
219+
val path = Path().apply {
220+
addRect(Rect(0f, 0f, 100f, 200f))
221+
}
222+
assertFalse(path.isEmpty)
223+
224+
path.rewind()
225+
226+
assertTrue(path.isEmpty)
227+
}
214228
}

Diff for: ‎compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedPath.skiko.kt

+4
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ internal class SkiaBackedPath(
164164
this.fillType = fillType
165165
}
166166

167+
override fun rewind() {
168+
internalPath.rewind()
169+
}
170+
167171
override fun translate(offset: Offset) {
168172
internalPath.transform(Matrix33.makeTranslate(offset.x, offset.y))
169173
}

0 commit comments

Comments
 (0)