From: Diego Perez Date: Mon, 21 Nov 2016 15:10:34 +0000 (+0000) Subject: Call layout when doing an only-measure pass X-Git-Tag: android-x86-8.1-r1~5409^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e6052ae44301da905c4edd4fca52475f355f20f4;p=android-x86%2Fframeworks-base.git Call layout when doing an only-measure pass Test: Modified testScrolled to check the only-measure behaviour Change-Id: Ie86c329e0f7d9135d53274977e24f431f5edc201 (cherry picked from commit 2d657bc344717281e470430b05adaa32fbd0af00) --- diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index 14f783bed648..85fe2a450e4f 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -385,13 +385,10 @@ public class RenderSessionImpl extends RenderAction { } /** - * Renders the given view hierarchy to the passed canvas and returns the result of the render - * operation. - * @param canvas an optional canvas to render the views to. If null, only the measure and - * layout steps will be executed. + * Runs a layout pass for the given view root */ - private static Result renderAndBuildResult(@NonNull BridgeContext context, @NonNull ViewGroup viewRoot, - @Nullable Canvas canvas, int width, int height) { + private static void doLayout(@NonNull BridgeContext context, @NonNull ViewGroup viewRoot, + int width, int height) { // measure again with the size we need // This must always be done before the call to layout measureView(viewRoot, null /*measuredView*/, @@ -401,7 +398,16 @@ public class RenderSessionImpl extends RenderAction { // now do the layout. viewRoot.layout(0, 0, width, height); handleScrolling(context, viewRoot); + } + /** + * Renders the given view hierarchy to the passed canvas and returns the result of the render + * operation. + * @param canvas an optional canvas to render the views to. If null, only the measure and + * layout steps will be executed. + */ + private static Result renderAndBuildResult(@NonNull BridgeContext context, @NonNull ViewGroup viewRoot, + @Nullable Canvas canvas, int width, int height) { if (canvas == null) { return SUCCESS.createResult(); } @@ -479,6 +485,7 @@ public class RenderSessionImpl extends RenderAction { // delete the canvas and image to reset them on the next full rendering mImage = null; mCanvas = null; + doLayout(getContext(), mViewRoot, mMeasuredScreenWidth, mMeasuredScreenHeight); } else { // draw the views // create the BufferedImage into which the layout will be rendered. @@ -539,6 +546,7 @@ public class RenderSessionImpl extends RenderAction { gc.dispose(); } + doLayout(getContext(), mViewRoot, mMeasuredScreenWidth, mMeasuredScreenHeight); if (mElapsedFrameTimeNanos >= 0) { long initialTime = System_Delegate.nanoTime(); if (!mFirstFrameExecuted) { diff --git a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java index cdcae89097b5..6cdd0ead85f5 100644 --- a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java +++ b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java @@ -555,7 +555,7 @@ public class Main { /** Test activity.xml */ @Test - public void testScrolling() throws ClassNotFoundException { + public void testScrollingAndMeasure() throws ClassNotFoundException { // Create the layout pull parser. LayoutPullParser parser = createLayoutPullParser("scrolled.xml"); // Create LayoutLibCallback. @@ -569,7 +569,10 @@ public class Main { params.setForceNoDecor(); params.setExtendedViewInfoMode(true); - RenderResult result = renderAndVerify(params, "scrolled.png"); + // Do an only-measure pass + RenderSession session = sBridge.createSession(params); + session.measure(); + RenderResult result = RenderResult.getFromSession(session); assertNotNull(result); assertNotNull(result.getResult()); assertTrue(result.getResult().isSuccess()); @@ -586,6 +589,20 @@ public class Main { assertEquals(90, rootLayout.getChildren().get(5).getChildren().get(0).getLeft()); assertEquals(-270, rootLayout.getChildren().get(5).getChildren().get(0).getBottom()); assertEquals(690, rootLayout.getChildren().get(5).getChildren().get(0).getRight()); + + // Do a full render pass + parser = createLayoutPullParser("scrolled.xml"); + + params = getSessionParams(parser, ConfigGenerator.NEXUS_5, + layoutLibCallback, "Theme.Material.NoActionBar.Fullscreen", false, + RenderingMode.V_SCROLL, 22); + params.setForceNoDecor(); + params.setExtendedViewInfoMode(true); + + result = renderAndVerify(params, "scrolled.png"); + assertNotNull(result); + assertNotNull(result.getResult()); + assertTrue(result.getResult().isSuccess()); } @Test