zircon/kernel/lib/gfxconsole/gfxconsole.cc
/**
 * @brief  Initialize graphics console and bind to a display
 *
 * If the display was previously initialized, first it is shut down and
 * detached from the print callback.
 *
 * If the new display_info is NULL, nothing else is done, otherwise the
 * display is initialized against the provided display_info.
 *
 * If raw_sw_fb is non-NULL it is a memory large enough to be a backing
 * surface (stride * height * pixelsize) for the provided hardware display.
 * This is used for very early framebuffer init before the heap is alive.
 */
@brief  Initialize graphics console and bind to a display
If the display was previously initialized, first it is shut down and
detached from the print callback.

If the new display_info is NULL, nothing else is done, otherwise the
display is initialized against the provided display_info.

If raw_sw_fb is non-NULL it is a memory large enough to be a backing
surface (stride * height * pixelsize) for the provided hardware display.
This is used for very early framebuffer init before the heap is alive.
@brief Initialize graphics console and bind to a display If the display was previously initialized first it is shut down and detached from the print callback . If the new display_info is NULL nothing else is done otherwise the display is initialized against the provided display_info . If raw_sw_fb is non - NULL it is a memory large enough to be a backing surface ( stride * height * pixelsize ) for the provided hardware display . This is used for very early framebuffer init before the heap is alive .
void gfxconsole_bind_display(struct display_info* info, void* raw_sw_fb) {
  static bool active = false;
  bool same_as_before = false;
  struct gfx_surface hw;
  if (active) {
    active = false;
    unregister_print_callback(&cb);
  }
  if (info == NULL) {
    return;
  }
  if (gfx_init_surface_from_display(&hw, info)) {
    return;
  }
  if (info->flags & DISPLAY_FLAG_CRASH_FRAMEBUFFER) {
    memcpy(&hw_surface, &hw, sizeof(hw));
    gfxconsole_setup(&hw_surface, &hw_surface);
    memcpy(&dispinfo, info, sizeof(*info));
    gfxconsole_clear(true);
    register_print_callback(&cb);
    active = true;
    return;
  }
  if ((hw.format == hw_surface.format) && (hw.width == hw_surface.width) &&
      (hw.height == hw_surface.height) && (hw.stride == hw_surface.stride) &&
      (hw.pixelsize == hw_surface.pixelsize)) {
    same_as_before = true;
  } else {
    if (sw_surface.ptr && (sw_surface.flags & GFX_FLAG_FREE_ON_DESTROY)) {
      free(sw_surface.ptr);
    }
    memset(&sw_surface, 0, sizeof(sw_surface));
  }
  memcpy(&hw_surface, &hw, sizeof(hw));
  gfx_surface* s = &hw_surface;
  if (info->flags & DISPLAY_FLAG_HW_FRAMEBUFFER) {
    if (!same_as_before) {
      if (gfx_init_surface(&sw_surface, raw_sw_fb, hw_surface.width, hw_surface.height,
                           hw_surface.stride, hw_surface.format, 0)) {
        return;
      }
    }
    s = &sw_surface;
  } else {
    same_as_before = false;
  }
  gfxconsole_setup(s, &hw_surface);
  if (!same_as_before) {
    gfxconsole_clear(false);
  }
  memcpy(&dispinfo, info, sizeof(*info));
  register_print_callback(&cb);
  active = true;
}
void gfxconsole_bind_display ( struct display_info * info , void * raw_sw_fb ) { static bool active = false ; bool same_as_before = false ; struct gfx_surface hw ; if ( active ) { active = false ; unregister_print_callback ( & cb ) ; } if ( info == NULL ) { return ; } if ( gfx_init_surface_from_display ( & hw , info ) ) { return ; } if ( info -> flags & DISPLAY_FLAG_CRASH_FRAMEBUFFER ) { memcpy ( & hw_surface , & hw , sizeof ( hw ) ) ; gfxconsole_setup ( & hw_surface , & hw_surface ) ; memcpy ( & dispinfo , info , sizeof ( * info ) ) ; gfxconsole_clear ( true ) ; register_print_callback ( & cb ) ; active = true ; return ; } if ( ( hw . format == hw_surface . format ) && ( hw . width == hw_surface . width ) && ( hw . height == hw_surface . height ) && ( hw . stride == hw_surface . stride ) && ( hw . pixelsize == hw_surface . pixelsize ) ) { same_as_before = true ; } else { if ( sw_surface . ptr && ( sw_surface . flags & GFX_FLAG_FREE_ON_DESTROY ) ) { free ( sw_surface . ptr ) ; } memset ( & sw_surface , 0 , sizeof ( sw_surface ) ) ; } memcpy ( & hw_surface , & hw , sizeof ( hw ) ) ; gfx_surface * s = & hw_surface ; if ( info -> flags & DISPLAY_FLAG_HW_FRAMEBUFFER ) { if ( ! same_as_before ) { if ( gfx_init_surface ( & sw_surface , raw_sw_fb , hw_surface . width , hw_surface . height , hw_surface . stride , hw_surface . format , 0 ) ) { return ; } } s = & sw_surface ; } else { same_as_before = false ; } gfxconsole_setup ( s , & hw_surface ) ; if ( ! same_as_before ) { gfxconsole_clear ( false ) ; } memcpy ( & dispinfo , info , sizeof ( * info ) ) ; register_print_callback ( & cb ) ; active = true ; }
@brief  Initialize graphics console and bind to a display
 If the display was previously initialized, first it is shut down and
 detached from the print callback.
@brief Initialize graphics console and bind to a display If the display was previously initialized first it is shut down and detached from the print callback .
// on re-init or detach, we need to unhook from print callbacks // "bluescreen" path. no allocations allowed // we are binding to a new hw surface with the same properties // as the existing one // we cannot re-use the sw backing surface, so destroy it // we can't re-use the existing sw_surface, create a new one // for non-hw surfaces we're not using a backing surface // so we can't be the same as before and must fully init // on first init, or different-backing-buffer re-init // we clear and reset to x,y @ 0,0