From 7558aa708160c287552f4e1e33c33d8b191e9f0e Mon Sep 17 00:00:00 2001 From: John Reck Date: Wed, 5 Mar 2014 14:59:59 -0800 Subject: [PATCH] Remove invalid usage of DisplayList.isValid() Bug: 13324734 Editor was using isValid as a mechanism to track whether or not it needed to re-record the DisplayList. This is not correct as isValid() is not a general-purpose dirty bit. Add an explicit dirty bit for Editor to use instead Change-Id: I5608b151791870fca3681056b5507bd39ee48f52 --- core/java/android/view/DisplayList.java | 10 ------ core/java/android/widget/Editor.java | 44 ++++++++++++++++++------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/core/java/android/view/DisplayList.java b/core/java/android/view/DisplayList.java index 3060e6e44a257..0ae36c1656c96 100644 --- a/core/java/android/view/DisplayList.java +++ b/core/java/android/view/DisplayList.java @@ -238,16 +238,6 @@ public class DisplayList { mValid = true; } - /** - * After calling this method {@link #isValid()} will return false. - * TODO: Have Editor stop using this - * - * @see #isValid() - */ - public void markInvalid() { - mValid = false; - } - /** * Reset native resources. This is called when cleaning up the state of display lists * during destruction of hardware resources, to ensure that we do not hold onto diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 84c158649c284..98b43b32d5372 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -137,7 +137,16 @@ public class Editor { InputContentType mInputContentType; InputMethodState mInputMethodState; - DisplayList[] mTextDisplayLists; + private static class TextDisplayList { + DisplayList displayList; + boolean isDirty; + public TextDisplayList(String name) { + isDirty = true; + displayList = DisplayList.create(name); + } + boolean needsRecord() { return isDirty || !displayList.isValid(); } + } + TextDisplayList[] mTextDisplayLists; boolean mFrozenWithFocus; boolean mSelectionMoved; @@ -262,7 +271,7 @@ public class Editor { mTextView.removeCallbacks(mShowSuggestionRunnable); } - invalidateTextDisplayList(); + destroyDisplayListsData(); if (mSpellChecker != null) { mSpellChecker.closeSession(); @@ -277,6 +286,19 @@ public class Editor { mTemporaryDetach = false; } + private void destroyDisplayListsData() { + HardwareRenderer renderer = mTextView.getHardwareRenderer(); + if (mTextDisplayLists != null) { + for (int i = 0; i < mTextDisplayLists.length; i++) { + DisplayList displayList = mTextDisplayLists[i] != null + ? mTextDisplayLists[i].displayList : null; + if (displayList != null && displayList.isValid()) { + displayList.destroyDisplayListData(renderer); + } + } + } + } + private void showError() { if (mTextView.getWindowToken() == null) { mShowErrorAfterAttach = true; @@ -1320,7 +1342,7 @@ public class Editor { if (layout instanceof DynamicLayout) { if (mTextDisplayLists == null) { - mTextDisplayLists = new DisplayList[ArrayUtils.idealObjectArraySize(0)]; + mTextDisplayLists = new TextDisplayList[ArrayUtils.idealObjectArraySize(0)]; } DynamicLayout dynamicLayout = (DynamicLayout) layout; @@ -1344,13 +1366,13 @@ public class Editor { searchStartIndex = blockIndex + 1; } - DisplayList blockDisplayList = mTextDisplayLists[blockIndex]; - if (blockDisplayList == null) { - blockDisplayList = mTextDisplayLists[blockIndex] = - DisplayList.create("Text " + blockIndex); + if (mTextDisplayLists[blockIndex] == null) { + mTextDisplayLists[blockIndex] = + new TextDisplayList("Text " + blockIndex); } - final boolean blockDisplayListIsInvalid = !blockDisplayList.isValid(); + final boolean blockDisplayListIsInvalid = mTextDisplayLists[blockIndex].needsRecord(); + DisplayList blockDisplayList = mTextDisplayLists[blockIndex].displayList; if (i >= indexFirstChangedBlock || blockDisplayListIsInvalid) { final int blockBeginLine = endOfPreviousBlock + 1; final int top = layout.getLineTop(blockBeginLine); @@ -1421,7 +1443,7 @@ public class Editor { // No available index found, the pool has to grow int newSize = ArrayUtils.idealIntArraySize(length + 1); - DisplayList[] displayLists = new DisplayList[newSize]; + TextDisplayList[] displayLists = new TextDisplayList[newSize]; System.arraycopy(mTextDisplayLists, 0, displayLists, 0, length); mTextDisplayLists = displayLists; return length; @@ -1460,7 +1482,7 @@ public class Editor { while (i < numberOfBlocks) { final int blockIndex = blockIndices[i]; if (blockIndex != DynamicLayout.INVALID_BLOCK_INDEX) { - mTextDisplayLists[blockIndex].markInvalid(); + mTextDisplayLists[blockIndex].isDirty = true; } if (blockEndLines[i] >= lastLine) break; i++; @@ -1471,7 +1493,7 @@ public class Editor { void invalidateTextDisplayList() { if (mTextDisplayLists != null) { for (int i = 0; i < mTextDisplayLists.length; i++) { - if (mTextDisplayLists[i] != null) mTextDisplayLists[i].markInvalid(); + if (mTextDisplayLists[i] != null) mTextDisplayLists[i].isDirty = true; } } }