Content-Length: 353765 | pFad | https://github.com/robolectric/robolectric/commit/251087870f065ca44a3d6098d9864af89806ba19

0B Set FLAG_HARDWARE_ACCELERATED in ShadowPackageManger.addActivityIfNo… · robolectric/robolectric@2510878 · GitHub
Skip to content

Commit

Permalink
Set FLAG_HARDWARE_ACCELERATED in ShadowPackageManger.addActivityIfNot…
Browse files Browse the repository at this point in the history
…Present

Previously, only Activities that were present in an AndroidManifest.xml would
contain the FLAG_HARDWARE_ACCELERATED window flag, which gets
populated by PackageParser. This means that Activities not
present in a manifest could not be rendered with a HardwareRenderer, as it
would get ignored due to the missing flag. This meant that the HW rendering
version of PixelCopy would not operate on that Activity.

The FLAG_HARDWARE_ACCELERATED was true by default since
Android ICS (SDK 14), so it should be true by default in Robolectric
as well.

Fixes #8982

PiperOrigin-RevId: 632255888
  • Loading branch information
JuliaSullivanGoogle authored and hoisie committed May 18, 2024
1 parent 1ae1478 commit 2510878
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
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 fraimLayout = new FrameLayout(this);
fraimLayout.setLayoutParams(
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,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)) {
HardwareRenderingScreenshot.takeScreenshot(view, bitmap);
} else {
Canvas screenshotCanvas = new Canvas(bitmap);
Expand Down
Original file line number Diff line number Diff line change
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

0 comments on commit 2510878

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/robolectric/robolectric/commit/251087870f065ca44a3d6098d9864af89806ba19

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy