consplittergraphics.c

来自「Next BIOS Source code : Extensible Firmw」· C语言 代码 · 共 1,003 行 · 第 1/3 页

C
1,003
字号
/*++

Copyright (c)  1999 - 2002 Intel Corporation. All rights reserved
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.


Abstract:

  Support for ConsoleControl protocol. Support for UGA Draw spliter.
  Support for DevNull Console Out. This console uses memory buffers
  to represnt the console. It allows a console to start very early and
  when a new console is added it is synced up with the current console


--*/

#include "ConSplitter.h"

static CHAR16 mCrLfString[3] = {CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL};

EFI_STATUS
EFIAPI
ConSpliterConsoleControlGetMode (
  IN  EFI_CONSOLE_CONTROL_PROTOCOL    *This,
  OUT EFI_SCREEN_MODE_ENUM            *Mode,
  OUT BOOLEAN                         *UgaExists,
  OUT BOOLEAN                         *StdInLocked
  )
/*++

  Routine Description:
    Return the current video mode information. Also returns info about existence
    of UGA Draw devices in system, and if the Std In device is locked. All the
    arguments are optional and only returned if a non NULL pointer is passed in.

  Arguments:
    This - Protocol instance pointer.
    Mode        - Are we in text of grahics mode.
    UgaExists   - TRUE if UGA Spliter has found a UGA device
    StdInLocked - TRUE if StdIn device is keyboard locked

  Returns:
    EFI_SUCCES      - Mode information returned.

--*/
{
  TEXT_OUT_SPLITTER_PRIVATE_DATA      *Private;
  UINTN                               Index;
  
  Private = CONSOLE_CONTROL_SPLITTER_PRIVATE_DATA_FROM_THIS (This);

  if (Mode == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  *Mode = Private->UgaMode;

  if (UgaExists != NULL) {
    *UgaExists = FALSE;
    for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
      if (Private->TextOutList[Index].UgaDraw != NULL) {
        *UgaExists = TRUE;
        break;
      }
    }
  }

  if (StdInLocked != NULL) {
    *StdInLocked = ConSpliterConssoleControlStdInLocked ();
  }

  return EFI_SUCCESS;
}

EFI_STATUS
EFIAPI
ConSpliterConsoleControlSetMode (
  IN  EFI_CONSOLE_CONTROL_PROTOCOL    *This,
  IN  EFI_SCREEN_MODE_ENUM            Mode
  )
/*++

  Routine Description:
    Set the current mode to either text or graphics. Graphics is
    for Quiet Boot.

  Arguments:
    This  - Protocol instance pointer.
    Mode  - Mode to set the 

  Returns:
    EFI_SUCCES      - Mode information returned.

--*/
{
  TEXT_OUT_SPLITTER_PRIVATE_DATA      *Private;
  UINTN                               Index;
  TEXT_OUT_AND_UGA_DATA               *TextAndUga;
  BOOLEAN                             Supported;

  Private = CONSOLE_CONTROL_SPLITTER_PRIVATE_DATA_FROM_THIS (This);

  if (Mode >= EfiScreenTextMaxValue) {
    return EFI_INVALID_PARAMETER;
  }

  Supported  = FALSE;
  TextAndUga = &Private->TextOutList[0];
  for (Index = 0; Index < Private->CurrentNumberOfConsoles;
        Index++, TextAndUga++) {
    if (TextAndUga->UgaDraw != NULL) {
      Supported = TRUE;
      break;
    }
  }
  if ( ( Supported == FALSE ) && ( Mode == EfiScreenGraphics ) ) {
    return EFI_UNSUPPORTED;
  }

  Private->UgaMode = Mode;

  TextAndUga = &Private->TextOutList[0];
  for (Index = 0; Index < Private->CurrentNumberOfConsoles;
        Index++, TextAndUga++) {

    TextAndUga->TextOutEnabled  = TRUE;
    //
    // If we are going into Graphics mode disable ConOut to any UGA device
    //
    if ( ( Mode == EfiScreenGraphics ) && ( TextAndUga->UgaDraw != NULL ) ) { 
      TextAndUga->TextOutEnabled = FALSE;
      DevNullUgaSync (Private, TextAndUga->UgaDraw);
    }
  }

  if (Mode == EfiScreenText) {
    DevNullSyncUgaStdOut (Private);
  }

  return EFI_SUCCESS;
}

EFI_STATUS
EFIAPI
ConSpliterUgaDrawGetMode (
  IN  EFI_UGA_DRAW_PROTOCOL           *This,
  OUT UINT32                          *HorizontalResolution,
  OUT UINT32                          *VerticalResolution,
  OUT UINT32                          *ColorDepth,
  OUT UINT32                          *RefreshRate
  )
/*++

  Routine Description:
    Return the current video mode information.

  Arguments:
    This                  - Protocol instance pointer.
    HorizontalResolution  - Current video horizontal resolution in pixels
    VerticalResolution    - Current video vertical resolution in pixels
    ColorDepth            - Current video color depth in bits per pixel
    RefreshRate           - Current video refresh rate in Hz.

  Returns:
    EFI_SUCCES      - Mode information returned.
    EFI_NOT_STARTED - Video display is not initialized. Call SetMode () 
    EFI_INVALID_PARAMETER - One of the input args was NULL.

--*/
{
  TEXT_OUT_SPLITTER_PRIVATE_DATA      *Private;
  
  if ( !(HorizontalResolution && VerticalResolution 
      && RefreshRate && ColorDepth) ) {
    return EFI_INVALID_PARAMETER;
  }
  
  //
  // retrieve private data
  //
  Private = UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This);

  *HorizontalResolution = Private->UgaHorizontalResolution;
  *VerticalResolution   = Private->UgaVerticalResolution;
  *ColorDepth           = Private->UgaColorDepth;
  *RefreshRate          = Private->UgaRefreshRate;

  return EFI_SUCCESS;
}

EFI_STATUS
EFIAPI
ConSpliterUgaDrawSetMode (
  IN  EFI_UGA_DRAW_PROTOCOL           *This,
  IN UINT32                           HorizontalResolution,
  IN UINT32                           VerticalResolution,
  IN UINT32                           ColorDepth,
  IN UINT32                           RefreshRate
  )
/*++

  Routine Description:
    Return the current video mode information.

  Arguments:
    This                  - Protocol instance pointer.
    HorizontalResolution  - Current video horizontal resolution in pixels
    VerticalResolution    - Current video vertical resolution in pixels
    ColorDepth            - Current video color depth in bits per pixel
    RefreshRate           - Current video refresh rate in Hz.

  Returns:
    EFI_SUCCES      - Mode information returned.
    EFI_NOT_STARTED - Video display is not initialized. Call SetMode () 

--*/
{
  EFI_STATUS                          Status;
  TEXT_OUT_SPLITTER_PRIVATE_DATA      *Private;
  UINTN                               Index;
  EFI_STATUS                          ReturnStatus;
  UINTN                               Size;

  Private = UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This);

  //
  // UgaDevNullSetMode ()
  //
  ReturnStatus = EFI_SUCCESS;
  if ((HorizontalResolution != Private->UgaHorizontalResolution) && 
      (VerticalResolution != Private->UgaVerticalResolution)) {
    //
    // Free the old version
    //
    gBS->FreePool (Private->UgaBlt);

    //
    // Allocate the virtual Blt buffer
    //
    Size = HorizontalResolution * VerticalResolution * sizeof (EFI_UGA_PIXEL);
    Private->UgaBlt = EfiLibAllocateZeroPool (Size);
    if ( Private->UgaBlt == NULL ) {
      return EFI_OUT_OF_RESOURCES;
    }
  }

  // 
  // Update the Mode data
  //
  Private->UgaHorizontalResolution  = HorizontalResolution;
  Private->UgaVerticalResolution    = VerticalResolution;
  Private->UgaColorDepth            = ColorDepth;
  Private->UgaRefreshRate           = RefreshRate;

  if (Private->UgaMode != EfiScreenGraphics) {
    return ReturnStatus;
  }

  //
  // return the worst status met
  //
  for ( Index = 0; Index < Private->CurrentNumberOfConsoles; Index++ ) {
    if ( Private->TextOutList[Index].UgaDraw ) {
      Status = Private->TextOutList[Index].UgaDraw->SetMode (
                                      Private->TextOutList[Index].UgaDraw,
                                      HorizontalResolution,
                                      VerticalResolution,
                                      ColorDepth,
                                      RefreshRate
                                      );
      if (EFI_ERROR (Status)) {
        ReturnStatus = Status;
      }
    }
  }
   
  return ReturnStatus;
}

EFI_STATUS
DevNullUgaBlt (
  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private,
  IN  EFI_UGA_PIXEL                   *BltBuffer,   OPTIONAL
  IN  EFI_UGA_BLT_OPERATION           BltOperation,
  IN  UINTN                           SourceX,
  IN  UINTN                           SourceY,
  IN  UINTN                           DestinationX,
  IN  UINTN                           DestinationY,
  IN  UINTN                           Width,
  IN  UINTN                           Height,
  IN  UINTN                           Delta         OPTIONAL
  )
{
  UINTN                               SrcY;
  UINTN                               Index;
  EFI_UGA_PIXEL                       *BltPtr;
  EFI_UGA_PIXEL                       *ScreenPtr;
  UINT32                              HorizontalResolution, VerticalResolution;

  if( ( BltOperation >= EfiUgaBltMax ) || ( BltOperation < 0 ) ) {
    return EFI_INVALID_PARAMETER;
  }


  if ( Width == 0 || Height == 0 ) {
    return EFI_INVALID_PARAMETER;
  }

  if ((DestinationX != 0 || DestinationY != 0) && Delta == 0) {
    return EFI_INVALID_PARAMETER;
  }

  if ( Delta == 0 ) {
    Delta = Width * sizeof (EFI_UGA_PIXEL);
  }

  HorizontalResolution  = Private->UgaHorizontalResolution;
  VerticalResolution    = Private->UgaVerticalResolution;

  //
  // We need to fill the Virtual Screen buffer with the blt data.
  //

  if ( BltOperation == EfiUgaVideoToBltBuffer ) {
    //
    // Video to BltBuffer: Source is Video, destination is BltBuffer
    //
    if ( ( SourceY + Height ) > VerticalResolution ) {
      return EFI_INVALID_PARAMETER;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?