private void recycleDispatchEventLocked(DispatchEvent d) {
    if (d.mEvent != null) {
      d.mEvent.recycle();
      d.mEvent = null;
    }

    if (mDispatchEventPoolSize < MAX_DISPATCH_EVENT_POOL_SIZE) {
      mDispatchEventPoolSize += 1;
      d.mNext = mDispatchEventPool;
      mDispatchEventPool = d;
    }
  }
  private void dispatchUiEvents(boolean calledFromHandler) {
    for (; ; ) {
      MotionEvent event;
      final int eventType;
      final int flags;
      synchronized (mLock) {
        DispatchEvent d = mUiDispatchEventQueue.dequeue();
        if (d == null) {
          if (mUiDispatchScheduled) {
            mUiDispatchScheduled = false;
            if (!calledFromHandler) {
              mUiHandler.removeMessages(UiHandler.MSG_DISPATCH_UI_EVENTS);
            }
          }
          return;
        }

        event = d.mEvent;
        if (event != null && (d.mFlags & FLAG_WEBKIT_TRANSFORMED_EVENT) != 0) {
          event.scale(1.0f / d.mWebKitScale);
          event.offsetLocation(-d.mWebKitXOffset, -d.mWebKitYOffset);
          d.mFlags &= ~FLAG_WEBKIT_TRANSFORMED_EVENT;
        }

        eventType = d.mEventType;
        if (eventType == EVENT_TYPE_TOUCH) {
          event = mUiTouchStream.update(event);
          if (DEBUG && event == null && d.mEvent != null) {
            Log.d(TAG, "dispatchUiEvents: dropped event " + d.mEvent);
          }
        }

        flags = d.mFlags;

        if (event == d.mEvent) {
          d.mEvent = null; // retain ownership of event, don't recycle it yet
        }
        recycleDispatchEventLocked(d);

        if (eventType == EVENT_TYPE_CLICK) {
          scheduleHideTapHighlightLocked();
        }
      }

      // Handle the event.
      if (event != null) {
        dispatchUiEvent(event, eventType, flags);
        event.recycle();
      }
    }
  }
 private DispatchEvent copyDispatchEventLocked(DispatchEvent d) {
   DispatchEvent copy = obtainUninitializedDispatchEventLocked();
   if (d.mEvent != null) {
     copy.mEvent = d.mEvent.copy();
   }
   copy.mEventType = d.mEventType;
   copy.mFlags = d.mFlags;
   copy.mTimeoutTime = d.mTimeoutTime;
   copy.mWebKitXOffset = d.mWebKitXOffset;
   copy.mWebKitYOffset = d.mWebKitYOffset;
   copy.mWebKitScale = d.mWebKitScale;
   copy.mNext = d.mNext;
   return copy;
 }
 private DispatchEvent obtainDispatchEventLocked(
     MotionEvent event,
     int eventType,
     int flags,
     int webKitXOffset,
     int webKitYOffset,
     float webKitScale) {
   DispatchEvent d = obtainUninitializedDispatchEventLocked();
   d.mEvent = event;
   d.mEventType = eventType;
   d.mFlags = flags;
   d.mTimeoutTime = SystemClock.uptimeMillis() + WEBKIT_TIMEOUT_MILLIS;
   d.mWebKitXOffset = webKitXOffset;
   d.mWebKitYOffset = webKitYOffset;
   d.mWebKitScale = webKitScale;
   if (DEBUG) {
     Log.d(TAG, "Timeout time: " + (d.mTimeoutTime - SystemClock.uptimeMillis()));
   }
   return d;
 }