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.
[Android] Speed up the method 'FlutterRenderer.getBitmap' (flutter#37342
- Loading branch information
1 parent
0075e10
commit 4e03d05
Showing
7 changed files
with
176 additions
and
54 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
38 changes: 38 additions & 0 deletions
38
...scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/GetBitmapTests.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,38 @@ | ||
// 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 dev.flutter.scenariosui; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import androidx.annotation.NonNull; | ||
import androidx.test.filters.LargeTest; | ||
import androidx.test.rule.ActivityTestRule; | ||
import androidx.test.runner.AndroidJUnit4; | ||
import dev.flutter.scenarios.GetBitmapActivity; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@LargeTest | ||
public class GetBitmapTests { | ||
@Rule @NonNull | ||
public ActivityTestRule<GetBitmapActivity> activityRule = | ||
new ActivityTestRule<>( | ||
GetBitmapActivity.class, /*initialTouchMode=*/ false, /*launchActivity=*/ false); | ||
|
||
@Test | ||
public void getBitmap() throws Exception { | ||
Intent intent = new Intent(Intent.ACTION_MAIN); | ||
intent.putExtra("scenario_name", "get_bitmap"); | ||
GetBitmapActivity activity = activityRule.launchActivity(intent); | ||
Bitmap bitmap = activity.getBitmap(); | ||
|
||
assertEquals(bitmap.getPixel(10, 10), 0xFFFF0000); | ||
assertEquals(bitmap.getPixel(10, bitmap.getHeight() - 10), 0xFF0000FF); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/GetBitmapActivity.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,25 @@ | ||
// 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 dev.flutter.scenarios; | ||
|
||
import android.graphics.Bitmap; | ||
import androidx.annotation.Nullable; | ||
|
||
public class GetBitmapActivity extends TestActivity { | ||
|
||
@Nullable private volatile Bitmap bitmap; | ||
|
||
@Nullable | ||
public Bitmap getBitmap() { | ||
waitUntilFlutterRendered(); | ||
return bitmap; | ||
} | ||
|
||
@Nullable | ||
protected void notifyFlutterRendered() { | ||
bitmap = getFlutterEngine().getRenderer().getBitmap(); | ||
super.notifyFlutterRendered(); | ||
} | ||
} |
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. | ||
|
||
import 'dart:ui'; | ||
|
||
import 'scenario.dart'; | ||
|
||
/// A scenario with red on top and blue on the bottom. | ||
class GetBitmapScenario extends Scenario { | ||
/// Creates the GetBitmap scenario. | ||
/// | ||
/// The [dispatcher] parameter must not be null. | ||
GetBitmapScenario(PlatformDispatcher dispatcher) | ||
: super(dispatcher); | ||
|
||
@override | ||
void onBeginFrame(Duration duration) { | ||
final PictureRecorder recorder = PictureRecorder(); | ||
final Canvas canvas = Canvas(recorder); | ||
canvas.drawRect(Rect.fromLTWH(0, 0, window.physicalSize.width, 300), | ||
Paint()..color = const Color(0xFFFF0000)); | ||
canvas.drawRect( | ||
Rect.fromLTWH(0, window.physicalSize.height - 300, | ||
window.physicalSize.width, 300), | ||
Paint()..color = const Color(0xFF0000FF)); | ||
final Picture picture = recorder.endRecording(); | ||
final SceneBuilder builder = SceneBuilder(); | ||
builder.addPicture(Offset.zero, picture); | ||
final Scene scene = builder.build(); | ||
window.render(scene); | ||
picture.dispose(); | ||
scene.dispose(); | ||
} | ||
} |
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