2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.server;
21 * A specialized list of window information objects backed by an array.
23 * This class is part of an InputManager optimization to avoid allocating objects and arrays
24 * unnecessarily. Internally, it keeps an array full of demand-allocated objects that it
25 * recycles each time the list is cleared. The used portion of the array is padded with a null.
27 * The contents of the list are intended to be Z-ordered from top to bottom.
31 public final class InputWindowList {
32 private InputWindow[] mArray;
36 * Creates an empty list.
38 public InputWindowList() {
39 mArray = new InputWindow[8];
52 mArray[count] = mArray[0];
55 mArray[count].recycle();
61 * Adds an uninitialized input window object to the list and returns it.
63 public InputWindow add() {
64 if (mCount + 1 == mArray.length) {
65 InputWindow[] oldArray = mArray;
66 mArray = new InputWindow[oldArray.length * 2];
67 System.arraycopy(oldArray, 0, mArray, 0, mCount);
70 // Grab object from tail (after used section) if available.
71 InputWindow item = mArray[mCount + 1];
73 item = new InputWindow();
76 mArray[mCount] = item;
78 mArray[mCount] = null;
83 * Gets the input window objects as a null-terminated array.
84 * @return The input window array.
86 public InputWindow[] toNullTerminatedArray() {