Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set FLAG_HARDWARE_ACCELERATED in ShadowPackageManger.addActivityIfNotPresent #9032

Merged
merged 1 commit into from May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -13,7 +13,6 @@
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -57,12 +56,6 @@ static class HardwareAcceleratedActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO(hoisie): manually setting these flags should not be required. Robolectric should
// set them automatically by default (they have been default since ICS).
getWindow()
.setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.setLayoutParams(
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
Expand Down
Expand Up @@ -42,10 +42,11 @@ private HardwareRenderingScreenshot() {}
* the presence of the {@link #USE_HARDWARE_RENDERER_NATIVE_ENV} property, and the {@link
* GraphicsMode}.
*/
static boolean canTakeScreenshot() {
static boolean canTakeScreenshot(View view) {
return VERSION.SDK_INT >= VERSION_CODES.S
&& "hardware".equalsIgnoreCase(System.getProperty(PIXEL_COPY_RENDER_MODE, ""))
&& ShadowView.useRealGraphics();
&& ShadowView.useRealGraphics()
&& view.canHaveDisplayList();
}

/**
Expand Down
Expand Up @@ -204,12 +204,10 @@ public class ShadowPackageManager {
* @return existing or newly created activity info.
*/
public ActivityInfo addActivityIfNotPresent(ComponentName componentName) {
ActivityInfo activityInfo = updateName(componentName, new ActivityInfo());
activityInfo.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
return addComponent(
activityFilters,
p -> p.activities,
(p, a) -> p.activities = a,
updateName(componentName, new ActivityInfo()),
false);
activityFilters, p -> p.activities, (p, a) -> p.activities = a, activityInfo, false);
}

/**
Expand Down
Expand Up @@ -168,7 +168,7 @@ private static void takeScreenshot(View view, Bitmap screenshot, @Nullable Rect

Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);

if (HardwareRenderingScreenshot.canTakeScreenshot()) {
if (HardwareRenderingScreenshot.canTakeScreenshot(view)) {
PerfStatsCollector.getInstance()
.measure(
"ShadowPixelCopy-Hardware",
Expand Down
Expand Up @@ -131,7 +131,7 @@ protected Bitmap takeScreenshot() throws Exception {
Bitmap window =
Bitmap.createBitmap(
rootView.getWidth(), rootView.getHeight(), Bitmap.Config.ARGB_8888);
if (HardwareRenderingScreenshot.canTakeScreenshot()) {
if (HardwareRenderingScreenshot.canTakeScreenshot(rootView)) {
HardwareRenderingScreenshot.takeScreenshot(rootView, window);
} else {
Canvas windowCanvas = new Canvas(window);
Expand Down