forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland "Avoid vsync scheduling delay" (flutter#36197)
- Loading branch information
Showing
9 changed files
with
127 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.util; | ||
|
||
import android.os.Build; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
|
||
/** Compatability wrapper over {@link Handler}. */ | ||
public final class HandlerCompat { | ||
/** | ||
* Create a new Handler whose posted messages and runnables are not subject to synchronization | ||
* barriers such as display vsync. | ||
* | ||
* <p>Messages sent to an async handler are guaranteed to be ordered with respect to one another, | ||
* but not necessarily with respect to messages from other Handlers. Compatibility behavior: | ||
* | ||
* <ul> | ||
* <li>SDK 28 and above, this method matches platform behavior. | ||
* <li>Otherwise, returns a synchronous handler instance. | ||
* </ul> | ||
* | ||
* @param looper the Looper that the new Handler should be bound to | ||
* @return a new async Handler instance | ||
* @see Handler#createAsync(Looper) | ||
*/ | ||
public static Handler createAsyncHandler(Looper looper) { | ||
if (Build.VERSION.SDK_INT >= 28) { | ||
return Handler.createAsync(looper); | ||
} | ||
return new Handler(looper); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
shell/platform/android/test/io/flutter/util/HandlerCompatTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.util; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.os.Message; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class HandlerCompatTest { | ||
@Test | ||
@Config(sdk = 28) | ||
public void createAsync_createsAnAsyncHandler() { | ||
Handler handler = Handler.createAsync(Looper.getMainLooper()); | ||
|
||
Message message = Message.obtain(); | ||
handler.sendMessageAtTime(message, 0); | ||
|
||
assertTrue(message.isAsynchronous()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters