radeon: derive radeon_renderbuffer from swrast_renderbuffer
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_common_context.c
index 2694dafc75f40fa87b8cbd19d229ad3cdff20266..b5fe7cdd04980ea78808f2e78f67ddc8f08277fb 100644 (file)
@@ -38,6 +38,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "drivers/common/meta.h"
 #include "main/context.h"
 #include "main/framebuffer.h"
+#include "main/fbobject.h"
 #include "main/renderbuffer.h"
 #include "main/state.h"
 #include "main/simple_list.h"
@@ -53,54 +54,18 @@ int RADEON_DEBUG = (0);
 static const char* get_chip_family_name(int chip_family)
 {
        switch(chip_family) {
+#if defined(RADEON_R100)
        case CHIP_FAMILY_R100: return "R100";
        case CHIP_FAMILY_RV100: return "RV100";
        case CHIP_FAMILY_RS100: return "RS100";
        case CHIP_FAMILY_RV200: return "RV200";
        case CHIP_FAMILY_RS200: return "RS200";
+#elif defined(RADEON_R200)
        case CHIP_FAMILY_R200: return "R200";
        case CHIP_FAMILY_RV250: return "RV250";
        case CHIP_FAMILY_RS300: return "RS300";
        case CHIP_FAMILY_RV280: return "RV280";
-       case CHIP_FAMILY_R300: return "R300";
-       case CHIP_FAMILY_R350: return "R350";
-       case CHIP_FAMILY_RV350: return "RV350";
-       case CHIP_FAMILY_RV380: return "RV380";
-       case CHIP_FAMILY_R420: return "R420";
-       case CHIP_FAMILY_RV410: return "RV410";
-       case CHIP_FAMILY_RS400: return "RS400";
-       case CHIP_FAMILY_RS600: return "RS600";
-       case CHIP_FAMILY_RS690: return "RS690";
-       case CHIP_FAMILY_RS740: return "RS740";
-       case CHIP_FAMILY_RV515: return "RV515";
-       case CHIP_FAMILY_R520: return "R520";
-       case CHIP_FAMILY_RV530: return "RV530";
-       case CHIP_FAMILY_R580: return "R580";
-       case CHIP_FAMILY_RV560: return "RV560";
-       case CHIP_FAMILY_RV570: return "RV570";
-       case CHIP_FAMILY_R600: return "R600";
-       case CHIP_FAMILY_RV610: return "RV610";
-       case CHIP_FAMILY_RV630: return "RV630";
-       case CHIP_FAMILY_RV670: return "RV670";
-       case CHIP_FAMILY_RV620: return "RV620";
-       case CHIP_FAMILY_RV635: return "RV635";
-       case CHIP_FAMILY_RS780: return "RS780";
-       case CHIP_FAMILY_RS880: return "RS880";
-       case CHIP_FAMILY_RV770: return "RV770";
-       case CHIP_FAMILY_RV730: return "RV730";
-       case CHIP_FAMILY_RV710: return "RV710";
-       case CHIP_FAMILY_RV740: return "RV740";
-       case CHIP_FAMILY_CEDAR: return "CEDAR";
-       case CHIP_FAMILY_REDWOOD: return "REDWOOD";
-       case CHIP_FAMILY_JUNIPER: return "JUNIPER";
-       case CHIP_FAMILY_CYPRESS: return "CYPRESS";
-       case CHIP_FAMILY_HEMLOCK: return "HEMLOCK";
-       case CHIP_FAMILY_PALM: return "PALM";
-       case CHIP_FAMILY_SUMO: return "SUMO";
-       case CHIP_FAMILY_SUMO2: return "SUMO2";
-       case CHIP_FAMILY_BARTS: return "BARTS";
-       case CHIP_FAMILY_TURKS: return "TURKS";
-       case CHIP_FAMILY_CAICOS: return "CAICOS";
+#endif
        default: return "unknown";
        }
 }
@@ -122,16 +87,14 @@ static const GLubyte *radeonGetString(struct gl_context * ctx, GLenum name)
                unsigned offset;
                GLuint agp_mode = (radeon->radeonScreen->card_type==RADEON_CARD_PCI) ? 0 :
                        radeon->radeonScreen->AGPMode;
-               const char* chipclass;
                char hardwarename[32];
 
-               if (IS_R200_CLASS(radeon->radeonScreen))
-                       chipclass = "R200";
-               else
-                       chipclass = "R100";
-
                sprintf(hardwarename, "%s (%s %04X)",
-                       chipclass,
+#if defined(RADEON_R100)
+                       "R100",
+#elif defined(RADEON_R200)
+                       "R200",
+#endif
                        get_chip_family_name(radeon->radeonScreen->chip_family),
                        radeon->radeonScreen->device_id);
 
@@ -169,7 +132,7 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
                            void *sharedContextPrivate)
 {
        __DRIscreen *sPriv = driContextPriv->driScreenPriv;
-       radeonScreenPtr screen = (radeonScreenPtr) (sPriv->private);
+       radeonScreenPtr screen = (radeonScreenPtr) (sPriv->driverPrivate);
        struct gl_context* ctx;
        struct gl_context* shareCtx;
        int fthrottle_mode;
@@ -220,12 +183,9 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
                 radeon->texture_depth = ( glVisual->rgbBits > 16 ) ?
                DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
 
-       if (IS_R200_CLASS(radeon->radeonScreen) ||
-           IS_R100_CLASS(radeon->radeonScreen)) {
-               radeon->texture_row_align = 32;
-               radeon->texture_rect_row_align = 64;
-               radeon->texture_compressed_row_align = 32;
-       }
+       radeon->texture_row_align = 32;
+       radeon->texture_rect_row_align = 64;
+       radeon->texture_compressed_row_align = 32;
 
        radeon_init_dma(radeon);
 
@@ -251,7 +211,7 @@ static void radeon_destroy_atom_list(radeonContextPtr radeon)
 
 /**
  * Cleanup common context fields.
- * Called by r200DestroyContext/r300DestroyContext
+ * Called by r200DestroyContext
  */
 void radeonDestroyContext(__DRIcontext *driContextPriv )
 {
@@ -334,7 +294,7 @@ GLboolean radeonUnbindContext(__DRIcontext * driContextPriv)
 static unsigned
 radeon_bits_per_pixel(const struct radeon_renderbuffer *rb)
 {
-   return _mesa_get_format_bytes(rb->base.Format) * 8; 
+   return _mesa_get_format_bytes(rb->base.Base.Format) * 8; 
 }
 
 /*
@@ -524,8 +484,8 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable,
 
                rb->cpp = buffers[i].cpp;
                rb->pitch = buffers[i].pitch;
-               rb->base.Width = drawable->w;
-               rb->base.Height = drawable->h;
+               rb->base.Base.Width = drawable->w;
+               rb->base.Base.Height = drawable->h;
                rb->has_surface = 0;
 
                if (buffers[i].attachment == __DRI_BUFFER_STENCIL && depth_bo) {
@@ -551,11 +511,19 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable,
                        }
 
                        ret = radeon_bo_get_tiling(bo, &tiling_flags, &pitch);
-                       if (tiling_flags & RADEON_TILING_MACRO)
-                               bo->flags |= RADEON_BO_FLAGS_MACRO_TILE;
-                       if (tiling_flags & RADEON_TILING_MICRO)
-                               bo->flags |= RADEON_BO_FLAGS_MICRO_TILE;
-
+                       if (ret) {
+                               fprintf(stderr,
+                                       "failed to get tiling for %s %d\n",
+                                       regname, buffers[i].name);
+                               radeon_bo_unref(bo);
+                               bo = NULL;
+                               continue;
+                       } else {
+                               if (tiling_flags & RADEON_TILING_MACRO)
+                                       bo->flags |= RADEON_BO_FLAGS_MACRO_TILE;
+                               if (tiling_flags & RADEON_TILING_MICRO)
+                                       bo->flags |= RADEON_BO_FLAGS_MICRO_TILE;
+                       }
                }
 
                if (buffers[i].attachment == __DRI_BUFFER_DEPTH) {
@@ -597,8 +565,22 @@ GLboolean radeonMakeCurrent(__DRIcontext * driContextPriv,
                            __DRIdrawable * driReadPriv)
 {
        radeonContextPtr radeon;
+       GET_CURRENT_CONTEXT(curCtx);
        struct gl_framebuffer *drfb, *readfb;
 
+       if (driContextPriv)
+               radeon = (radeonContextPtr)driContextPriv->driverPrivate;
+       else
+               radeon = NULL;
+       /* According to the glXMakeCurrent() man page: "Pending commands to
+        * the previous context, if any, are flushed before it is released."
+        * But only flush if we're actually changing contexts.
+        */
+
+       if ((radeonContextPtr)curCtx && (radeonContextPtr)curCtx != radeon) {
+               _mesa_flush(curCtx);
+       }
+
        if (!driContextPriv) {
                if (RADEON_DEBUG & RADEON_DRI)
                        fprintf(stderr, "%s ctx is null\n", __FUNCTION__);
@@ -606,8 +588,6 @@ GLboolean radeonMakeCurrent(__DRIcontext * driContextPriv,
                return GL_TRUE;
        }
 
-       radeon = (radeonContextPtr) driContextPriv->driverPrivate;
-
        if(driDrawPriv == NULL && driReadPriv == NULL) {
                drfb = _mesa_create_framebuffer(&radeon->glCtx->Visual);
                readfb = drfb;
@@ -622,9 +602,9 @@ GLboolean radeonMakeCurrent(__DRIcontext * driContextPriv,
        if (driDrawPriv != driReadPriv)
           radeon_update_renderbuffers(driContextPriv, driReadPriv, GL_FALSE);
        _mesa_reference_renderbuffer(&radeon->state.color.rb,
-               &(radeon_get_renderbuffer(drfb, BUFFER_BACK_LEFT)->base));
+               &(radeon_get_renderbuffer(drfb, BUFFER_BACK_LEFT)->base.Base));
        _mesa_reference_renderbuffer(&radeon->state.depth.rb,
-               &(radeon_get_renderbuffer(drfb, BUFFER_DEPTH)->base));
+               &(radeon_get_renderbuffer(drfb, BUFFER_DEPTH)->base.Base));
 
        if (RADEON_DEBUG & RADEON_DRI)
             fprintf(stderr, "%s ctx %p dfb %p rfb %p\n", __FUNCTION__, radeon->glCtx, drfb, readfb);