diff options
author | Chet Haase <chet@google.com> | 2011-04-22 16:24:23 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-05-04 17:37:22 -0700 |
commit | 3fe16ced4294bdeeab31008e93b5e2d004da7437 (patch) | |
tree | a82c16fc41828ac25f6d744735fc709c7bcf6559 /hierarchyviewer2/libs | |
parent | 4355ff5f80690a4503314ead5299b88f04bfcfaa (diff) | |
download | sdk-3fe16ced4294bdeeab31008e93b5e2d004da7437.zip sdk-3fe16ced4294bdeeab31008e93b5e2d004da7437.tar.gz sdk-3fe16ced4294bdeeab31008e93b5e2d004da7437.tar.bz2 |
hierarchyviewer can dump displaylists for selected nodes.
In hierarchyviewer (and hierarchyviewer1):
The displaylist for the selected node (if there is one) is output
into logcat when the "Dump DisplayList" button is clicked.
Change-Id: I1996bbd1cbe32d8bc25708453c777800385fe444
Diffstat (limited to 'hierarchyviewer2/libs')
4 files changed, 117 insertions, 7 deletions
diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/HierarchyViewerDirector.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/HierarchyViewerDirector.java index 77f8d74..23dfbea 100644 --- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/HierarchyViewerDirector.java +++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/HierarchyViewerDirector.java @@ -166,7 +166,7 @@ public abstract class HierarchyViewerDirector implements IDeviceChangeListener, return; } Window[] windows = DeviceBridge.loadWindows(device); - DeviceSelectionModel.getModel().addDevice(device, windows); + DeviceSelectionModel.getModel().addDevice(device, windows, viewServerInfo); if (viewServerInfo.protocolVersion >= 3) { WindowUpdater.startListenForWindowChanges(HierarchyViewerDirector.this, device); focusChanged(device); @@ -586,6 +586,17 @@ public abstract class HierarchyViewerDirector implements IDeviceChangeListener, } } + public void dumpDisplayListForCurrentNode() { + final DrawableViewNode selectedNode = TreeViewModel.getModel().getSelection(); + if (selectedNode != null) { + executeInBackground("Dump displaylist", new Runnable() { + public void run() { + DeviceBridge.outputDisplayList(selectedNode.viewNode); + } + }); + } + } + public void loadAllViews() { executeInBackground("Loading all views", new Runnable() { public void run() { diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/actions/DumpDisplayListAction.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/actions/DumpDisplayListAction.java new file mode 100644 index 0000000..8b9ba29 --- /dev/null +++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/actions/DumpDisplayListAction.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.hierarchyviewerlib.actions; + +import com.android.ddmuilib.ImageLoader; +import com.android.hierarchyviewerlib.HierarchyViewerDirector; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; + +public class DumpDisplayListAction extends SelectedNodeEnabledAction implements ImageAction { + + private static DumpDisplayListAction sAction; + + private Image mImage; + + private DumpDisplayListAction() { + super("Dump DisplayList"); + ImageLoader imageLoader = ImageLoader.getLoader(HierarchyViewerDirector.class); + mImage = imageLoader.loadImage("load-view-hierarchy.png", Display.getDefault()); //$NON-NLS-1$ + setImageDescriptor(ImageDescriptor.createFromImage(mImage)); + setToolTipText("Request the view to output its displaylist to logcat"); + } + + public static DumpDisplayListAction getAction() { + if (sAction == null) { + sAction = new DumpDisplayListAction(); + } + return sAction; + } + + @Override + public void run() { + HierarchyViewerDirector.getDirector().dumpDisplayListForCurrentNode(); + } + + public Image getImage() { + return mImage; + } +} diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java index 40cc3a9..610f7b3 100644 --- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java +++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/device/DeviceBridge.java @@ -643,4 +643,18 @@ public class DeviceBridge { } } + public static void outputDisplayList(ViewNode viewNode) { + DeviceConnection connection = null; + try { + connection = new DeviceConnection(viewNode.window.getDevice()); + connection.sendCommand("OUTPUT_DISPLAYLIST " + + viewNode.window.encode() + " " + viewNode); //$NON-NLS-1$ + } catch (Exception e) { + Log.e(TAG, "Unable to dump displaylist for node " + viewNode + " in window " + + viewNode.window + " on device " + viewNode.window.getDevice()); + } finally { + connection.close(); + } + } + } diff --git a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/models/DeviceSelectionModel.java b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/models/DeviceSelectionModel.java index d029d39..b00a1dc 100644 --- a/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/models/DeviceSelectionModel.java +++ b/hierarchyviewer2/libs/hierarchyviewerlib/src/com/android/hierarchyviewerlib/models/DeviceSelectionModel.java @@ -17,6 +17,7 @@ package com.android.hierarchyviewerlib.models; import com.android.ddmlib.IDevice; +import com.android.hierarchyviewerlib.device.DeviceBridge.ViewServerInfo; import com.android.hierarchyviewerlib.device.Window; import java.util.ArrayList; @@ -29,7 +30,7 @@ import java.util.HashMap; */ public class DeviceSelectionModel { - private final HashMap<IDevice, Window[]> mDeviceMap = new HashMap<IDevice, Window[]>(); + private final HashMap<IDevice, DeviceInfo> mDeviceMap = new HashMap<IDevice, DeviceInfo>(); private final HashMap<IDevice, Integer> mFocusedWindowHashes = new HashMap<IDevice, Integer>(); @@ -44,6 +45,15 @@ public class DeviceSelectionModel { private static DeviceSelectionModel sModel; + private static class DeviceInfo { + Window[] windows; + ViewServerInfo viewServerInfo; + + private DeviceInfo(Window[] windows, ViewServerInfo viewServerInfo) { + this.windows = windows; + this.viewServerInfo = viewServerInfo; + } + } public static DeviceSelectionModel getModel() { if (sModel == null) { sModel = new DeviceSelectionModel(); @@ -57,9 +67,9 @@ public class DeviceSelectionModel { } } - public void addDevice(IDevice device, Window[] windows) { + public void addDevice(IDevice device, Window[] windows, ViewServerInfo info) { synchronized (mDeviceMap) { - mDeviceMap.put(device, windows); + mDeviceMap.put(device, new DeviceInfo(windows, info)); mDeviceList.add(device); } notifyDeviceConnected(device); @@ -88,7 +98,12 @@ public class DeviceSelectionModel { public void updateDevice(IDevice device, Window[] windows) { boolean selectionChanged = false; synchronized (mDeviceMap) { - mDeviceMap.put(device, windows); + DeviceInfo oldDeviceInfo = mDeviceMap.get(device); + ViewServerInfo oldViewServerInfo = null; + if (oldDeviceInfo != null) { + oldViewServerInfo = oldDeviceInfo.viewServerInfo; + } + mDeviceMap.put(device, new DeviceInfo(windows, oldViewServerInfo)); // If the selected window no longer exists, we clear the selection. if (mSelectedDevice == device && mSelectedWindow != null) { boolean windowStillExists = false; @@ -214,9 +229,12 @@ public class DeviceSelectionModel { } public Window[] getWindows(IDevice device) { - Window[] windows; + Window[] windows = null; synchronized (mDeviceMap) { - windows = mDeviceMap.get(device); + DeviceInfo info = mDeviceMap.get(device); + if (info != null) { + windows = mDeviceMap.get(device).windows; + } } return windows; } @@ -253,4 +271,15 @@ public class DeviceSelectionModel { return mSelectedWindow; } } + + public ViewServerInfo getSelectedDeviceInfo() { + synchronized (mDeviceMap) { + ViewServerInfo viewServerInfo = null; + if (mSelectedDevice != null) { + return mDeviceMap.get(mSelectedDevice).viewServerInfo; + } + return null; + } + } + } |