+ //\r
+ // Add full screen mode to the last entry.\r
+ //\r
+ mGraphicsConsoleModeData[Count - 1].Columns = MaxColumns;\r
+ mGraphicsConsoleModeData[Count - 1].Rows = MaxRows;\r
+\r
+ //\r
+ // Get defined mode buffer pointer.\r
+ //\r
+ ModeBuffer = mGraphicsConsoleModeData;\r
+\r
+ //\r
+ // Here we make sure that the final mode exposed does not include the duplicated modes,\r
+ // and does not include the invalid modes which exceed the max column and row.\r
+ // Reserve 2 modes for 80x25, 80x50 of graphics console.\r
+ //\r
+ NewModeBuffer = AllocateZeroPool (sizeof (GRAPHICS_CONSOLE_MODE_DATA) * (Count + 2));\r
+ ASSERT (NewModeBuffer != NULL);\r
+\r
+ //\r
+ // Mode 0 and mode 1 is for 80x25, 80x50 according to UEFI spec.\r
+ //\r
+ ValidCount = 0; \r
+\r
+ NewModeBuffer[ValidCount].Columns = 80;\r
+ NewModeBuffer[ValidCount].Rows = 25;\r
+ NewModeBuffer[ValidCount].GopWidth = HorizontalResolution;\r
+ NewModeBuffer[ValidCount].GopHeight = VerticalResolution;\r
+ NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;\r
+ NewModeBuffer[ValidCount].DeltaX = (HorizontalResolution - (NewModeBuffer[ValidCount].Columns * EFI_GLYPH_WIDTH)) >> 1;\r
+ NewModeBuffer[ValidCount].DeltaY = (VerticalResolution - (NewModeBuffer[ValidCount].Rows * EFI_GLYPH_HEIGHT)) >> 1; \r
+ ValidCount++;\r
+\r
+ if ((MaxColumns >= 80) && (MaxRows >= 50)) {\r
+ NewModeBuffer[ValidCount].Columns = 80;\r
+ NewModeBuffer[ValidCount].Rows = 50;\r
+ NewModeBuffer[ValidCount].DeltaX = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
+ NewModeBuffer[ValidCount].DeltaY = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1; \r
+ }\r
+ NewModeBuffer[ValidCount].GopWidth = HorizontalResolution;\r
+ NewModeBuffer[ValidCount].GopHeight = VerticalResolution;\r
+ NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;\r
+ ValidCount++;\r
+ \r
+ //\r
+ // Start from mode 2 to put the valid mode other than 80x25 and 80x50 in the output mode buffer.\r
+ //\r
+ for (Index = 0; Index < Count; Index++) {\r
+ if ((ModeBuffer[Index].Columns == 0) || (ModeBuffer[Index].Rows == 0) ||\r
+ (ModeBuffer[Index].Columns > MaxColumns) || (ModeBuffer[Index].Rows > MaxRows)) {\r
+ //\r
+ // Skip the pre-defined mode which is invalid or exceeds the max column and row.\r
+ //\r
+ continue;\r
+ }\r
+ for (ValidIndex = 0; ValidIndex < ValidCount; ValidIndex++) {\r
+ if ((ModeBuffer[Index].Columns == NewModeBuffer[ValidIndex].Columns) &&\r
+ (ModeBuffer[Index].Rows == NewModeBuffer[ValidIndex].Rows)) {\r
+ //\r
+ // Skip the duplicated mode.\r
+ //\r
+ break;\r
+ }\r
+ }\r
+ if (ValidIndex == ValidCount) {\r
+ NewModeBuffer[ValidCount].Columns = ModeBuffer[Index].Columns;\r
+ NewModeBuffer[ValidCount].Rows = ModeBuffer[Index].Rows;\r
+ NewModeBuffer[ValidCount].GopWidth = HorizontalResolution;\r
+ NewModeBuffer[ValidCount].GopHeight = VerticalResolution;\r
+ NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;\r
+ NewModeBuffer[ValidCount].DeltaX = (HorizontalResolution - (NewModeBuffer[ValidCount].Columns * EFI_GLYPH_WIDTH)) >> 1;\r
+ NewModeBuffer[ValidCount].DeltaY = (VerticalResolution - (NewModeBuffer[ValidCount].Rows * EFI_GLYPH_HEIGHT)) >> 1;\r
+ ValidCount++;\r
+ }\r
+ }\r
+ \r
+ DEBUG_CODE (\r
+ for (Index = 0; Index < ValidCount; Index++) {\r
+ DEBUG ((EFI_D_INFO, "Graphics - Mode %d, Column = %d, Row = %d\n", \r
+ Index, NewModeBuffer[Index].Columns, NewModeBuffer[Index].Rows)); \r
+ }\r
+ );\r
+ \r
+ //\r
+ // Return valid mode count and mode information buffer.\r
+ //\r
+ *TextModeCount = ValidCount;\r
+ *TextModeData = NewModeBuffer;\r
+ return EFI_SUCCESS;\r
+}\r