def _IncludedPaintEvents(events):
  """Get all events that are counted in the calculation of the speed index.

  There's one category of paint event that's filtered out: paint events
  that occur before the first 'ResourceReceiveResponse' and 'Layout' events.

  Previously in the WPT speed index, paint events that contain children paint
  events were also filtered out.
  """
  def FirstLayoutTime(events):
    """Get the start time of the first layout after a resource received."""
    has_received_response = False
    for event in events:
      if event.name == 'ResourceReceiveResponse':
        has_received_response = True
      elif has_received_response and event.name == 'Layout':
        return event.start
    assert False, 'There were no layout events after resource receive events.'

  paint_events = [e for e in events
                  if e.start >= FirstLayoutTime(events) and e.name == 'Paint']
  return paint_events