Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fo_context.c 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**************************************************************************
  2. *
  3. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #include "pipe/p_defines.h"
  28. #include "pipe/p_winsys.h"
  29. #include "pipe/p_util.h"
  30. #include "pipe/p_context.h"
  31. #include "fo_context.h"
  32. #include "fo_winsys.h"
  33. static void failover_destroy( struct pipe_context *pipe )
  34. {
  35. struct failover_context *failover = failover_context( pipe );
  36. free( failover );
  37. }
  38. static boolean failover_draw_elements( struct pipe_context *pipe,
  39. struct pipe_buffer *indexBuffer,
  40. unsigned indexSize,
  41. unsigned prim, unsigned start, unsigned count)
  42. {
  43. struct failover_context *failover = failover_context( pipe );
  44. /* If there has been any statechange since last time, try hardware
  45. * rendering again:
  46. */
  47. if (failover->dirty) {
  48. failover->mode = FO_HW;
  49. }
  50. /* Try hardware:
  51. */
  52. if (failover->mode == FO_HW) {
  53. if (!failover->hw->draw_elements( failover->hw,
  54. indexBuffer,
  55. indexSize,
  56. prim,
  57. start,
  58. count )) {
  59. failover->hw->flush( failover->hw, ~0 );
  60. failover->mode = FO_SW;
  61. }
  62. }
  63. /* Possibly try software:
  64. */
  65. if (failover->mode == FO_SW) {
  66. if (failover->dirty)
  67. failover_state_emit( failover );
  68. failover->sw->draw_elements( failover->sw,
  69. indexBuffer,
  70. indexSize,
  71. prim,
  72. start,
  73. count );
  74. /* Be ready to switch back to hardware rendering without an
  75. * intervening flush. Unlikely to be much performance impact to
  76. * this:
  77. */
  78. failover->sw->flush( failover->sw, ~0 );
  79. }
  80. return TRUE;
  81. }
  82. static boolean failover_draw_arrays( struct pipe_context *pipe,
  83. unsigned prim, unsigned start, unsigned count)
  84. {
  85. return failover_draw_elements(pipe, NULL, 0, prim, start, count);
  86. }
  87. struct pipe_context *failover_create( struct pipe_context *hw,
  88. struct pipe_context *sw )
  89. {
  90. struct failover_context *failover = CALLOC_STRUCT(failover_context);
  91. if (failover == NULL)
  92. return NULL;
  93. failover->hw = hw;
  94. failover->sw = sw;
  95. failover->pipe.winsys = hw->winsys;
  96. failover->pipe.screen = hw->screen;
  97. failover->pipe.destroy = failover_destroy;
  98. failover->pipe.is_format_supported = hw->is_format_supported;
  99. #if 0
  100. failover->pipe.get_name = hw->get_name;
  101. failover->pipe.get_vendor = hw->get_vendor;
  102. failover->pipe.get_param = hw->get_param;
  103. failover->pipe.get_paramf = hw->get_paramf;
  104. #endif
  105. failover->pipe.draw_arrays = failover_draw_arrays;
  106. failover->pipe.draw_elements = failover_draw_elements;
  107. failover->pipe.clear = hw->clear;
  108. /* No software occlusion fallback (or other optional functionality)
  109. * at this point - if the hardware doesn't support it, don't
  110. * advertise it to the application.
  111. */
  112. failover->pipe.begin_query = hw->begin_query;
  113. failover->pipe.end_query = hw->end_query;
  114. failover_init_state_functions( failover );
  115. failover->pipe.surface_copy = hw->surface_copy;
  116. failover->pipe.surface_fill = hw->surface_fill;
  117. failover->pipe.texture_create = hw->texture_create;
  118. failover->pipe.texture_release = hw->texture_release;
  119. failover->pipe.texture_update = hw->texture_update;
  120. failover->pipe.get_tex_surface = hw->get_tex_surface;
  121. failover->pipe.flush = hw->flush;
  122. failover->dirty = 0;
  123. return &failover->pipe;
  124. }