/* Query and save all resolutions supported by the GOP. */
STATIC EFI_STATUS EFIAPI QueryGopModes(IN EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop, OUT UINTN *NumGopModes, OUT GOP_MODE **GopModes)
/* Query and save all resolutions supported by the GOP. */
STATIC EFI_STATUS EFIAPI QueryGopModes(IN EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop, OUT UINTN *NumGopModes, OUT GOP_MODE **GopModes)
{
  EFI_STATUS  Status;
  UINT32      ModeNumber;
  if (Gop->Mode->MaxMode == 0) {
    return EFI_UNSUPPORTED;
  }
  *NumGopModes = Gop->Mode->MaxMode;
  *GopModes = AllocatePool (Gop->Mode->MaxMode * sizeof **GopModes);
  if (*GopModes == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }
  for (ModeNumber = 0; ModeNumber < Gop->Mode->MaxMode; ++ModeNumber) {
    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *Info;
    UINTN                                 SizeOfInfo;
    Status = Gop->QueryMode (Gop, ModeNumber, &SizeOfInfo, &Info);
    if (EFI_ERROR (Status)) {
      goto FreeGopModes;
    }
    (*GopModes)[ModeNumber].X = Info->HorizontalResolution;
    (*GopModes)[ModeNumber].Y = Info->VerticalResolution;
    FreePool (Info);
  }
  return EFI_SUCCESS;
FreeGopModes:
  FreePool (*GopModes);
  return Status;
}