OSDN Git Service

Call layout when doing an only-measure pass
authorDiego Perez <diegoperez@google.com>
Mon, 21 Nov 2016 15:10:34 +0000 (15:10 +0000)
committerJerome Gaillard <jgaillard@google.com>
Mon, 16 Jan 2017 14:29:56 +0000 (14:29 +0000)
Test: Modified testScrolled to check the only-measure behaviour
Change-Id: Ie86c329e0f7d9135d53274977e24f431f5edc201
(cherry picked from commit 2d657bc344717281e470430b05adaa32fbd0af00)

tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java

index 14f783b..85fe2a4 100644 (file)
@@ -385,13 +385,10 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
     }
 
     /**
-     * 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<SessionParams> {
         // 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<SessionParams> {
                 // 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<SessionParams> {
                     gc.dispose();
                 }
 
+                doLayout(getContext(), mViewRoot, mMeasuredScreenWidth, mMeasuredScreenHeight);
                 if (mElapsedFrameTimeNanos >= 0) {
                     long initialTime = System_Delegate.nanoTime();
                     if (!mFirstFrameExecuted) {
index cdcae89..6cdd0ea 100644 (file)
@@ -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