intel_screen.c revision ecadb51bbcb972a79f3ed79e65a7986b9396e757
177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/**************************************************************************
277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * All Rights Reserved.
577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Permission is hereby granted, free of charge, to any person obtaining a
777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * copy of this software and associated documentation files (the
877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * "Software"), to deal in the Software without restriction, including
977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * without limitation the rights to use, copy, modify, merge, publish,
1077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * distribute, sub license, and/or sell copies of the Software, and to
1177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * permit persons to whom the Software is furnished to do so, subject to
1277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * the following conditions:
1377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
1477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * The above copyright notice and this permission notice (including the
1577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * next paragraph) shall be included in all copies or substantial portions
1677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * of the Software.
1777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
1877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
2177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
2277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
2677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt **************************************************************************/
2777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
28ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/glheader.h"
29ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/context.h"
30ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/framebuffer.h"
31ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/matrix.h"
32ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/renderbuffer.h"
33ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/simple_list.h"
3477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "utils.h"
3577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "vblank.h"
3677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "xmlpool.h"
3777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
3877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
3977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_screen.h"
4077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
4177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_buffers.h"
4277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_tex.h"
4377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_span.h"
4477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_fbo.h"
45bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt#include "intel_chipset.h"
4677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
47bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt#include "i915_drm.h"
4877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "i830_dri.h"
4977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_regions.h"
5077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_batchbuffer.h"
51f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie#include "intel_bufmgr.h"
5277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
5377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtPUBLIC const char __driConfigOptions[] =
54a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric Anholt   DRI_CONF_BEGIN
55a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric Anholt   DRI_CONF_SECTION_PERFORMANCE
56a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric Anholt      DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
57e9bf3e4cc9a7e4bcd4c45bd707541d26ecdf0409Jesse Barnes      DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC)
58fe91c05b5494b889c8adda77ff562712116d2e59Eric Anholt      /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
59fe91c05b5494b889c8adda77ff562712116d2e59Eric Anholt       * DRI_CONF_BO_REUSE_ALL
60fe91c05b5494b889c8adda77ff562712116d2e59Eric Anholt       */
61f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1")
62fe91c05b5494b889c8adda77ff562712116d2e59Eric Anholt	 DRI_CONF_DESC_BEGIN(en, "Buffer object reuse")
63fe91c05b5494b889c8adda77ff562712116d2e59Eric Anholt	    DRI_CONF_ENUM(0, "Disable buffer object reuse")
64fe91c05b5494b889c8adda77ff562712116d2e59Eric Anholt	    DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
65fe91c05b5494b889c8adda77ff562712116d2e59Eric Anholt	 DRI_CONF_DESC_END
66fe91c05b5494b889c8adda77ff562712116d2e59Eric Anholt      DRI_CONF_OPT_END
67a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric Anholt   DRI_CONF_SECTION_END
68a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric Anholt   DRI_CONF_SECTION_QUALITY
69a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric Anholt      DRI_CONF_FORCE_S3TC_ENABLE(false)
70acba9c1771d653126fd6f604cb80c050b9e8ffb3Michel Dänzer      DRI_CONF_ALLOW_LARGE_TEXTURES(2)
71a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric Anholt   DRI_CONF_SECTION_END
72a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric Anholt   DRI_CONF_SECTION_DEBUG
73a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric Anholt     DRI_CONF_NO_RAST(false)
74a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric Anholt   DRI_CONF_SECTION_END
75a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric AnholtDRI_CONF_END;
76a0e453a5eca7ed4b57a7f4c1e418d368815e3957Eric Anholt
77fe91c05b5494b889c8adda77ff562712116d2e59Eric Anholtconst GLuint __driNConfigOptions = 6;
7877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
7977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#ifdef USE_NEW_INTERFACE
8085063f14ea431b586d710f249563fc73481552c7Eric Anholtstatic PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
8177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#endif /*USE_NEW_INTERFACE */
8277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
8377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/**
8477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Map all the memory regions described by the screen.
8577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * \return GL_TRUE if success, GL_FALSE if error.
8677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
8777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtGLboolean
8877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtintelMapScreenRegions(__DRIscreenPrivate * sPriv)
8977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
9077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
9177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
9277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (0)
9377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      _mesa_printf("TEX 0x%08x ", intelScreen->tex.handle);
9477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (intelScreen->tex.size != 0) {
9577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      if (drmMap(sPriv->fd,
9677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt		 intelScreen->tex.handle,
9777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt		 intelScreen->tex.size,
9877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt		 (drmAddress *) & intelScreen->tex.map) != 0) {
9977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt	 intelUnmapScreenRegions(intelScreen);
10077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt	 return GL_FALSE;
10177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      }
10277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
10377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
10477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   return GL_TRUE;
10577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
10677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
10777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
10877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtintelUnmapScreenRegions(intelScreenPrivate * intelScreen)
10977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
11077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (intelScreen->tex.map) {
11177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      drmUnmap(intelScreen->tex.map, intelScreen->tex.size);
11277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->tex.map = NULL;
11377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
11477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
11577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
11677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
11777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic void
11877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtintelPrintDRIInfo(intelScreenPrivate * intelScreen,
11977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                  __DRIscreenPrivate * sPriv, I830DRIPtr gDRIPriv)
12077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
12177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   fprintf(stderr, "*** Front size:   0x%x  offset: 0x%x  pitch: %d\n",
12277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt           intelScreen->front.size, intelScreen->front.offset,
12346eb02b60920a920b782bacb15f01b44e18f888dKristian Høgsberg           intelScreen->pitch);
12477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   fprintf(stderr, "*** Back size:    0x%x  offset: 0x%x  pitch: %d\n",
12577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt           intelScreen->back.size, intelScreen->back.offset,
12646eb02b60920a920b782bacb15f01b44e18f888dKristian Høgsberg           intelScreen->pitch);
12777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   fprintf(stderr, "*** Depth size:   0x%x  offset: 0x%x  pitch: %d\n",
12877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt           intelScreen->depth.size, intelScreen->depth.offset,
12946eb02b60920a920b782bacb15f01b44e18f888dKristian Høgsberg           intelScreen->pitch);
13077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   fprintf(stderr, "*** Texture size: 0x%x  offset: 0x%x\n",
13177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt           intelScreen->tex.size, intelScreen->tex.offset);
13277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   fprintf(stderr, "*** Memory : 0x%x\n", gDRIPriv->mem);
13377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
13477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
13577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
13677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic void
1371c718c0d78cf4eae9e02b03a0abbec384db948a6Alan HourihaneintelPrintSAREA(const struct drm_i915_sarea * sarea)
13877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
13977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   fprintf(stderr, "SAREA: sarea width %d  height %d\n", sarea->width,
14077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt           sarea->height);
14177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   fprintf(stderr, "SAREA: pitch: %d\n", sarea->pitch);
14277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   fprintf(stderr,
143f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie           "SAREA: front offset: 0x%08x  size: 0x%x  handle: 0x%x tiled: %d\n",
14477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt           sarea->front_offset, sarea->front_size,
145f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie           (unsigned) sarea->front_handle, sarea->front_tiled);
14677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   fprintf(stderr,
147f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie           "SAREA: back  offset: 0x%08x  size: 0x%x  handle: 0x%x tiled: %d\n",
14877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt           sarea->back_offset, sarea->back_size,
149f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie           (unsigned) sarea->back_handle, sarea->back_tiled);
150f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   fprintf(stderr, "SAREA: depth offset: 0x%08x  size: 0x%x  handle: 0x%x tiled: %d\n",
15177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt           sarea->depth_offset, sarea->depth_size,
152f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie           (unsigned) sarea->depth_handle, sarea->depth_tiled);
15377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   fprintf(stderr, "SAREA: tex   offset: 0x%08x  size: 0x%x  handle: 0x%x\n",
15477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt           sarea->tex_offset, sarea->tex_size, (unsigned) sarea->tex_handle);
15577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
15677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
15777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
15877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/**
15977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * A number of the screen parameters are obtained/computed from
16077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * information in the SAREA.  This function updates those parameters.
16177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
16277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
16377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtintelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen,
1641c718c0d78cf4eae9e02b03a0abbec384db948a6Alan Hourihane                           struct drm_i915_sarea * sarea)
16577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
16677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->width = sarea->width;
16777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->height = sarea->height;
16846eb02b60920a920b782bacb15f01b44e18f888dKristian Høgsberg   intelScreen->pitch = sarea->pitch;
16977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
17077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->front.offset = sarea->front_offset;
17177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->front.handle = sarea->front_handle;
17277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->front.size = sarea->front_size;
173f00a64999c197e6a96e65fd00f64224a6f22c9faEric Anholt   intelScreen->front.tiled = sarea->front_tiled;
17477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
17577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->back.offset = sarea->back_offset;
17677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->back.handle = sarea->back_handle;
17777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->back.size = sarea->back_size;
178f00a64999c197e6a96e65fd00f64224a6f22c9faEric Anholt   intelScreen->back.tiled = sarea->back_tiled;
17977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
18077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (intelScreen->driScrnPriv->ddx_version.minor >= 8) {
18177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->third.offset = sarea->third_offset;
18277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->third.handle = sarea->third_handle;
18377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->third.size = sarea->third_size;
184f00a64999c197e6a96e65fd00f64224a6f22c9faEric Anholt      intelScreen->third.tiled = sarea->third_tiled;
18577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
18677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
18777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->depth.offset = sarea->depth_offset;
18877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->depth.handle = sarea->depth_handle;
18977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->depth.size = sarea->depth_size;
190f00a64999c197e6a96e65fd00f64224a6f22c9faEric Anholt   intelScreen->depth.tiled = sarea->depth_tiled;
19177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
19277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (intelScreen->driScrnPriv->ddx_version.minor >= 9) {
19377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->front.bo_handle = sarea->front_bo_handle;
19477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->back.bo_handle = sarea->back_bo_handle;
19577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->third.bo_handle = sarea->third_bo_handle;
19677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->depth.bo_handle = sarea->depth_bo_handle;
19777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   } else {
19877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->front.bo_handle = -1;
19977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->back.bo_handle = -1;
20077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->third.bo_handle = -1;
20177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelScreen->depth.bo_handle = -1;
20277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
20377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
20477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->tex.offset = sarea->tex_offset;
20577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->logTextureGranularity = sarea->log_tex_granularity;
20677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->tex.handle = sarea->tex_handle;
20777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->tex.size = sarea->tex_size;
20877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
20977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (0)
21077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelPrintSAREA(sarea);
21177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
21277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
21377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic const __DRItexOffsetExtension intelTexOffsetExtension = {
21477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   { __DRI_TEX_OFFSET },
21577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelSetTexOffset,
21677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt};
21777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
2186d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstatic const __DRItexBufferExtension intelTexBufferExtension = {
2196d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg    { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
2206d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   intelSetTexBuffer,
2216d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg};
2226d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
223e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsbergstatic const __DRIextension *intelScreenExtensions[] = {
22477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    &driReadDrawableExtension,
22577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    &driCopySubBufferExtension.base,
22677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    &driSwapControlExtension.base,
22777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    &driFrameTrackingExtension.base,
22877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    &driMediaStreamCounterExtension.base,
22977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    &intelTexOffsetExtension.base,
2306d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg    &intelTexBufferExtension.base,
23177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    NULL
23277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt};
23377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
23424e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsbergstatic GLboolean
23524e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsbergintel_get_param(__DRIscreenPrivate *psp, int param, int *value)
23624e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg{
23724e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg   int ret;
2381c718c0d78cf4eae9e02b03a0abbec384db948a6Alan Hourihane   struct drm_i915_getparam gp;
23924e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg
24024e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg   gp.param = param;
24124e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg   gp.value = value;
24224e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg
2431c718c0d78cf4eae9e02b03a0abbec384db948a6Alan Hourihane   ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
24424e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg   if (ret) {
2451c718c0d78cf4eae9e02b03a0abbec384db948a6Alan Hourihane      fprintf(stderr, "drm_i915_getparam: %d\n", ret);
24624e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg      return GL_FALSE;
24724e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg   }
24824e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg
24924e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg   return GL_TRUE;
25024e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg}
25177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
25277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic GLboolean intelInitDriver(__DRIscreenPrivate *sPriv)
25377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
25477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreenPrivate *intelScreen;
25577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   I830DRIPtr gDRIPriv = (I830DRIPtr) sPriv->pDevPriv;
2561c718c0d78cf4eae9e02b03a0abbec384db948a6Alan Hourihane   struct drm_i915_sarea *sarea;
25777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
25877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (sPriv->devPrivSize != sizeof(I830DRIRec)) {
25977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      fprintf(stderr,
26077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt              "\nERROR!  sizeof(I830DRIRec) does not match passed size from device driver\n");
26177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_FALSE;
26277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
26377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
26477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Allocate the private area */
26577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
26677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (!intelScreen) {
26777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      fprintf(stderr, "\nERROR!  Allocating private area failed\n");
26877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_FALSE;
26977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
27077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* parse information in __driConfigOptions */
27177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   driParseOptionInfo(&intelScreen->optionCache,
27277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                      __driConfigOptions, __driNConfigOptions);
27377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
27477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->driScrnPriv = sPriv;
27577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   sPriv->private = (void *) intelScreen;
2761c718c0d78cf4eae9e02b03a0abbec384db948a6Alan Hourihane   sarea = (struct drm_i915_sarea *)
2773628185f566e178a12b493fb89abf52b4b281f99Eric Anholt      (((GLubyte *) sPriv->pSAREA) + gDRIPriv->sarea_priv_offset);
2783628185f566e178a12b493fb89abf52b4b281f99Eric Anholt   intelScreen->sarea = sarea;
27977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
28077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->deviceID = gDRIPriv->deviceID;
28177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
28277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelUpdateScreenFromSAREA(intelScreen, sarea);
28377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
28477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (!intelMapScreenRegions(sPriv)) {
28577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      fprintf(stderr, "\nERROR!  mapping regions\n");
28677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      _mesa_free(intelScreen);
28777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      sPriv->private = NULL;
28877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_FALSE;
28977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
29077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
29177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (0)
29277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intelPrintDRIInfo(intelScreen, sPriv, gDRIPriv);
29377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
29477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreen->drmMinor = sPriv->drm_version.minor;
29577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
29677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Determine if IRQs are active? */
2971c718c0d78cf4eae9e02b03a0abbec384db948a6Alan Hourihane   if (!intel_get_param(sPriv, I915_PARAM_IRQ_ACTIVE,
29824e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg			&intelScreen->irq_active))
29924e7e457680d700e986fd0b0e0f046fadf67caf4Kristian Høgsberg      return GL_FALSE;
30077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
301e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   sPriv->extensions = intelScreenExtensions;
30277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
30377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   return GL_TRUE;
30477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
30577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
30677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
30777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic void
30877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtintelDestroyScreen(__DRIscreenPrivate * sPriv)
30977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
31077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
31177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
312904f31a62444d9f7e9b12ddafaa4beeb7fed6dfaEric Anholt   dri_bufmgr_destroy(intelScreen->bufmgr);
31377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelUnmapScreenRegions(intelScreen);
31477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
31577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   FREE(intelScreen);
31677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   sPriv->private = NULL;
31777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
31877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
31977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
32077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/**
32177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * This is called when we need to set up GL rendering to a new X window.
32277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
32377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic GLboolean
32477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtintelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
32577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                  __DRIdrawablePrivate * driDrawPriv,
32677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                  const __GLcontextModes * mesaVis, GLboolean isPixmap)
32777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
32877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreenPrivate *screen = (intelScreenPrivate *) driScrnPriv->private;
32977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
33077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (isPixmap) {
33177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_FALSE;          /* not implemented */
33277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
33377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   else {
33477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      GLboolean swStencil = (mesaVis->stencilBits > 0 &&
33577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                             mesaVis->depthBits != 24);
33677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      GLenum rgbFormat = (mesaVis->redBits == 5 ? GL_RGB5 : GL_RGBA8);
33777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
33877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      struct intel_framebuffer *intel_fb = CALLOC_STRUCT(intel_framebuffer);
33977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
34077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      if (!intel_fb)
34177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt	 return GL_FALSE;
34277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
34377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      _mesa_initialize_framebuffer(&intel_fb->Base, mesaVis);
34477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
34577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      /* setup the hardware-based renderbuffers */
346f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      intel_fb->color_rb[0] = intel_create_renderbuffer(rgbFormat);
347f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT,
348f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie			     &intel_fb->color_rb[0]->Base);
34977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
35077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      if (mesaVis->doubleBufferMode) {
351f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie	 intel_fb->color_rb[1] = intel_create_renderbuffer(rgbFormat);
352f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie
35377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt         _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT,
35477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt				&intel_fb->color_rb[1]->Base);
35577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
35677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt	 if (screen->third.handle) {
35777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt	    struct gl_renderbuffer *tmp_rb = NULL;
35877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
359e131c46b20241737ceba4856dbe01dcca6dd2c03Kristian Høgsberg	    intel_fb->color_rb[2] = intel_create_renderbuffer(rgbFormat);
36077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt	    _mesa_reference_renderbuffer(&tmp_rb, &intel_fb->color_rb[2]->Base);
36177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt	 }
36277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      }
36377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
36438c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt      if (mesaVis->depthBits == 24) {
36538c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt	 if (mesaVis->stencilBits == 8) {
36638c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt	    /* combined depth/stencil buffer */
36738c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt	    struct intel_renderbuffer *depthStencilRb
368e131c46b20241737ceba4856dbe01dcca6dd2c03Kristian Høgsberg	       = intel_create_renderbuffer(GL_DEPTH24_STENCIL8_EXT);
36938c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt	    /* note: bind RB to two attachment points */
37038c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt	    _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
37138c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt				   &depthStencilRb->Base);
37238c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt	    _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_STENCIL,
37338c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt				   &depthStencilRb->Base);
37438c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt	 } else {
37538c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt	    struct intel_renderbuffer *depthRb
376e131c46b20241737ceba4856dbe01dcca6dd2c03Kristian Høgsberg	       = intel_create_renderbuffer(GL_DEPTH_COMPONENT24);
37738c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt	    _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH,
37838c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt				   &depthRb->Base);
37938c616260a4c14bf5a1d7831e6349c3e8817d14bEric Anholt	 }
38077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      }
38177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      else if (mesaVis->depthBits == 16) {
38277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt         /* just 16-bit depth buffer, no hw stencil */
38377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt         struct intel_renderbuffer *depthRb
384f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie	    = intel_create_renderbuffer(GL_DEPTH_COMPONENT16);
38577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt         _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, &depthRb->Base);
38677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      }
38777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
38877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      /* now add any/all software-based renderbuffers we may need */
38977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      _mesa_add_soft_renderbuffers(&intel_fb->Base,
39077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   GL_FALSE, /* never sw color */
39177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   GL_FALSE, /* never sw depth */
39277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   swStencil, mesaVis->accumRedBits > 0,
39377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   GL_FALSE, /* never sw alpha */
39477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   GL_FALSE  /* never sw aux */ );
39577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      driDrawPriv->driverPrivate = (void *) intel_fb;
39677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
39777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_TRUE;
39877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
39977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
40077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
40177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic void
40277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtintelDestroyBuffer(__DRIdrawablePrivate * driDrawPriv)
40377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
40477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
40577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
40677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
40777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
40877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/**
40977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Get information about previous buffer swaps.
41077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
41177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic int
41277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtintelGetSwapInfo(__DRIdrawablePrivate * dPriv, __DRIswapInfo * sInfo)
41377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
41477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   struct intel_framebuffer *intel_fb;
41577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
41677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if ((dPriv == NULL) || (dPriv->driverPrivate == NULL)
41777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       || (sInfo == NULL)) {
41877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return -1;
41977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
42077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
42177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intel_fb = dPriv->driverPrivate;
42277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   sInfo->swap_count = intel_fb->swap_count;
42377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   sInfo->swap_ust = intel_fb->swap_ust;
42477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   sInfo->swap_missed_count = intel_fb->swap_missed_count;
42577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
42677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
42777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      ? driCalculateSwapUsage(dPriv, 0, intel_fb->swap_missed_ust)
42877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      : 0.0;
42977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
43077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   return 0;
43177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
43277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
43377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
43477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/* There are probably better ways to do this, such as an
43577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * init-designated function to register chipids and createcontext
43677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * functions.
43777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
43877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtextern GLboolean i830CreateContext(const __GLcontextModes * mesaVis,
43977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   __DRIcontextPrivate * driContextPriv,
44077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   void *sharedContextPrivate);
44177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
44277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtextern GLboolean i915CreateContext(const __GLcontextModes * mesaVis,
44377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   __DRIcontextPrivate * driContextPriv,
44477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   void *sharedContextPrivate);
445bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholtextern GLboolean brwCreateContext(const __GLcontextModes * mesaVis,
446bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt				  __DRIcontextPrivate * driContextPriv,
447bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt				  void *sharedContextPrivate);
44877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
44977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic GLboolean
45077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtintelCreateContext(const __GLcontextModes * mesaVis,
45177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                   __DRIcontextPrivate * driContextPriv,
45277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                   void *sharedContextPrivate)
45377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
45477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
45577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
45677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
457bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt#ifdef I915
45819420e6c2592e8a31e2ead4bccebc1a9ccca52b1Eric Anholt   if (IS_9XX(intelScreen->deviceID)) {
45919420e6c2592e8a31e2ead4bccebc1a9ccca52b1Eric Anholt      if (!IS_965(intelScreen->deviceID)) {
46019420e6c2592e8a31e2ead4bccebc1a9ccca52b1Eric Anholt	 return i915CreateContext(mesaVis, driContextPriv,
461bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt				  sharedContextPrivate);
46219420e6c2592e8a31e2ead4bccebc1a9ccca52b1Eric Anholt      }
463bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt   } else {
46477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return i830CreateContext(mesaVis, driContextPriv, sharedContextPrivate);
46577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
466bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt#else
467bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt   if (IS_965(intelScreen->deviceID))
468bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt      return brwCreateContext(mesaVis, driContextPriv, sharedContextPrivate);
469bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt#endif
470bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt   fprintf(stderr, "Unrecognized deviceID %x\n", intelScreen->deviceID);
471bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt   return GL_FALSE;
47277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
47377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
47477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
475e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsbergstatic __DRIconfig **
4766cb3f5c4d8618a14bb7ad1d9df10ed7e648a7b2bKristian HøgsbergintelFillInModes(__DRIscreenPrivate *psp,
4776cb3f5c4d8618a14bb7ad1d9df10ed7e648a7b2bKristian Høgsberg		 unsigned pixel_bits, unsigned depth_bits,
47877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                 unsigned stencil_bits, GLboolean have_back_buffer)
47977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
480e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   __DRIconfig **configs;
48177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   __GLcontextModes *m;
48277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   unsigned depth_buffer_factor;
48377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   unsigned back_buffer_factor;
48477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLenum fb_format;
48577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLenum fb_type;
486e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   int i;
48777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
48877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
48977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * support pageflipping at all.
49077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    */
49177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   static const GLenum back_buffer_modes[] = {
49277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
49377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   };
49477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
49577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   u_int8_t depth_bits_array[3];
49677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   u_int8_t stencil_bits_array[3];
49777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
49877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   depth_bits_array[0] = 0;
49977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   depth_bits_array[1] = depth_bits;
50077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   depth_bits_array[2] = depth_bits;
50177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
50277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Just like with the accumulation buffer, always provide some modes
50377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * with a stencil buffer.  It will be a sw fallback, but some apps won't
50477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * care about that.
50577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    */
50677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   stencil_bits_array[0] = 0;
50777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   stencil_bits_array[1] = 0;
50877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (depth_bits == 24)
50977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
51077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
51177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
51277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
51377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
51477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   back_buffer_factor = (have_back_buffer) ? 3 : 1;
51577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
51677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (pixel_bits == 16) {
51777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      fb_format = GL_RGB;
51877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      fb_type = GL_UNSIGNED_SHORT_5_6_5;
51977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
52077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   else {
52177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      fb_format = GL_BGRA;
52277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
52377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
52477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
525e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   configs = driCreateConfigs(fb_format, fb_type,
526e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg			      depth_bits_array, stencil_bits_array,
527e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg			      depth_buffer_factor, back_buffer_modes,
528e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg			      back_buffer_factor);
529e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   if (configs == NULL) {
530e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
53177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt              __LINE__);
53277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return NULL;
53377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
53477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
53577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Mark the visual as slow if there are "fake" stencil bits.
53677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    */
537e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   for (i = 0; configs[i]; i++) {
538e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg      m = &configs[i]->modes;
53977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
54077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt         m->visualRating = GLX_SLOW_CONFIG;
54177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      }
54277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
54377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
544e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   return configs;
54577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
54677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
5477e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholtstatic GLboolean
5487e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholtintel_init_bufmgr(intelScreenPrivate *intelScreen)
5497e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt{
5507e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   GLboolean gem_disable = getenv("INTEL_NO_GEM") != NULL;
5517e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   int gem_kernel = 0;
5527e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   GLboolean gem_supported;
5537e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   struct drm_i915_getparam gp;
5547e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   __DRIscreenPrivate *spriv = intelScreen->driScrnPriv;
5557e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
5567e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   intelScreen->no_hw = getenv("INTEL_NO_HW") != NULL;
5577e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
5587e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   gp.param = I915_PARAM_HAS_GEM;
5597e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   gp.value = &gem_kernel;
5607e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
5617e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   (void) drmCommandWriteRead(spriv->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
5627e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
5637e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   /* If we've got a new enough DDX that's initializing GEM and giving us
5647e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt    * object handles for the shared buffers, use that.
5657e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt    */
5667e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   intelScreen->ttm = GL_FALSE;
5677e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   if (intelScreen->driScrnPriv->dri2.enabled)
5687e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt       gem_supported = GL_TRUE;
5697e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   else if (intelScreen->driScrnPriv->ddx_version.minor >= 9 &&
5707e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt	    gem_kernel &&
5717e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt	    intelScreen->front.bo_handle != -1)
5727e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt       gem_supported = GL_TRUE;
5737e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   else
5747e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt       gem_supported = GL_FALSE;
5757e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
5767e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   if (!gem_disable && gem_supported) {
5777e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt      intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ);
5787e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt      if (intelScreen->bufmgr != NULL)
5797e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt	 intelScreen->ttm = GL_TRUE;
5807e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   }
5817e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   /* Otherwise, use the classic buffer manager. */
5827e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   if (intelScreen->bufmgr == NULL) {
5837e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt      if (gem_disable) {
5847e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt	 fprintf(stderr, "GEM disabled.  Using classic.\n");
5857e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt      } else {
5867e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt	 fprintf(stderr, "Failed to initialize GEM.  "
5877e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt		 "Falling back to classic.\n");
5887e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt      }
5897e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
5907e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt      if (intelScreen->tex.size == 0) {
5917e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt	 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
5927e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt		 __func__, __LINE__);
5937e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt	 return GL_FALSE;
5947e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt      }
5957e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
5963628185f566e178a12b493fb89abf52b4b281f99Eric Anholt      intelScreen->bufmgr =
5973628185f566e178a12b493fb89abf52b4b281f99Eric Anholt	 intel_bufmgr_fake_init(spriv->fd,
5983628185f566e178a12b493fb89abf52b4b281f99Eric Anholt				intelScreen->tex.offset,
5993628185f566e178a12b493fb89abf52b4b281f99Eric Anholt				intelScreen->tex.map,
6003628185f566e178a12b493fb89abf52b4b281f99Eric Anholt				intelScreen->tex.size,
6013628185f566e178a12b493fb89abf52b4b281f99Eric Anholt				(unsigned int * volatile)
6023628185f566e178a12b493fb89abf52b4b281f99Eric Anholt				&intelScreen->sarea->last_dispatch);
6037e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   }
6047e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
6057e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   /* XXX bufmgr should be per-screen, not per-context */
6067e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   intelScreen->ttm = intelScreen->ttm;
6077e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
6087e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   return GL_TRUE;
6097e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt}
6107e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
61177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/**
61277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * This is the driver specific part of the createNewScreen entry point.
6138d976aedc4654bc66b80f22690e3674f1ef46183Brian Paul * Called when using legacy DRI.
61477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
61577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * \todo maybe fold this into intelInitDriver
61677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
61777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * \return the __GLcontextModes supported by this driver
61877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
619e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsbergstatic const __DRIconfig **intelInitScreen(__DRIscreenPrivate *psp)
62077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
6217e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   intelScreenPrivate *intelScreen;
622bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt#ifdef I915
62377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   static const __DRIversion ddx_expected = { 1, 5, 0 };
624bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt#else
625bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt   static const __DRIversion ddx_expected = { 1, 6, 0 };
626bea6b5fe5aa3138cec8d057766ae48da4aa57deeEric Anholt#endif
62777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   static const __DRIversion dri_expected = { 4, 0, 0 };
62877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   static const __DRIversion drm_expected = { 1, 5, 0 };
62977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   I830DRIPtr dri_priv = (I830DRIPtr) psp->pDevPriv;
63077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
63177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (!driCheckDriDdxDrmVersions2("i915",
63277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   &psp->dri_version, &dri_expected,
63377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   &psp->ddx_version, &ddx_expected,
63477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                                   &psp->drm_version, &drm_expected)) {
63577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return NULL;
63677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
63777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
63877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Calling driInitExtensions here, with a NULL context pointer,
63977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * does not actually enable the extensions.  It just makes sure
64077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * that all the dispatch offsets for all the extensions that
64177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * *might* be enables are known.  This is needed because the
64277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * dispatch offsets need to be known when _mesa_context_create is
64377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * called, but we can't enable the extensions until we have a
64477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * context pointer.
64577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    *
64677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * Hello chicken.  Hello egg.  How are you two today?
64777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    */
64860c0f09abb9421de359cd92e094a943d650fc7faKristian Høgsberg   intelInitExtensions(NULL, GL_TRUE);
64960c0f09abb9421de359cd92e094a943d650fc7faKristian Høgsberg
65077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (!intelInitDriver(psp))
65177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       return NULL;
65277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
653e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   psp->extensions = intelScreenExtensions;
654e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
6557e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   intelScreen = psp->private;
6567e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   if (!intel_init_bufmgr(intelScreen))
6577e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt       return GL_FALSE;
6587e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
659e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   return (const __DRIconfig **)
660e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg       intelFillInModes(psp, dri_priv->cpp * 8,
661e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg			(dri_priv->cpp == 2) ? 16 : 24,
662e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg			(dri_priv->cpp == 2) ? 0  : 8, 1);
66377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
66477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
66577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstruct intel_context *intelScreenContext(intelScreenPrivate *intelScreen)
66677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
66777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt  /*
66877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   * This should probably change to have the screen allocate a dummy
66977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   * context at screen creation. For now just use the current context.
67077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   */
67177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
67277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt  GET_CURRENT_CONTEXT(ctx);
67377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt  if (ctx == NULL) {
67477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt     _mesa_problem(NULL, "No current context in intelScreenContext\n");
67577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt     return NULL;
67677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt  }
67777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt  return intel_context(ctx);
67877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
67977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
680c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg/**
681c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg * This is the driver specific part of the createNewScreen entry point.
6828d976aedc4654bc66b80f22690e3674f1ef46183Brian Paul * Called when using DRI2.
6838d976aedc4654bc66b80f22690e3674f1ef46183Brian Paul *
684c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg * \return the __GLcontextModes supported by this driver
685c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg */
686e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsbergstatic const
687e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg__DRIconfig **intelInitScreen2(__DRIscreenPrivate *psp)
688c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg{
689c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   intelScreenPrivate *intelScreen;
690c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg
691c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   /* Calling driInitExtensions here, with a NULL context pointer,
692c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg    * does not actually enable the extensions.  It just makes sure
693c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg    * that all the dispatch offsets for all the extensions that
694c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg    * *might* be enables are known.  This is needed because the
695c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg    * dispatch offsets need to be known when _mesa_context_create is
696c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg    * called, but we can't enable the extensions until we have a
697c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg    * context pointer.
698c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg    *
699c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg    * Hello chicken.  Hello egg.  How are you two today?
700c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg    */
70160c0f09abb9421de359cd92e094a943d650fc7faKristian Høgsberg   intelInitExtensions(NULL, GL_TRUE);
702c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg
703c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   /* Allocate the private area */
704c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   intelScreen = (intelScreenPrivate *) CALLOC(sizeof(intelScreenPrivate));
705c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   if (!intelScreen) {
706c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg      fprintf(stderr, "\nERROR!  Allocating private area failed\n");
707c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg      return GL_FALSE;
708c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   }
709c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   /* parse information in __driConfigOptions */
710c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   driParseOptionInfo(&intelScreen->optionCache,
711c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg                      __driConfigOptions, __driNConfigOptions);
712c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg
713c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   intelScreen->driScrnPriv = psp;
714c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   psp->private = (void *) intelScreen;
715c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg
716c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   intelScreen->drmMinor = psp->drm_version.minor;
717c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg
718f56b569e9af356c11869ee49a4669bb01b75397eKristian Høgsberg   /* Determine chipset ID */
719c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg   if (!intel_get_param(psp, I915_PARAM_CHIPSET_ID,
720c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg			&intelScreen->deviceID))
721c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg      return GL_FALSE;
722c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg
7237e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt   if (!intel_init_bufmgr(intelScreen))
7247e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt       return GL_FALSE;
7257e0bbdcf033981282978554c2e68ce48b55aa291Eric Anholt
726f56b569e9af356c11869ee49a4669bb01b75397eKristian Høgsberg   intelScreen->irq_active = 1;
727e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   psp->extensions = intelScreenExtensions;
728c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg
729e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   return driConcatConfigs(intelFillInModes(psp, 16, 16, 0, 1),
730e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg			   intelFillInModes(psp, 32, 24, 8, 1));
731c5c73c1b605611faf0f06df9b5d08d8984388238Kristian Høgsberg}
732e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
733e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsbergconst struct __DriverAPIRec driDriverAPI = {
734e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .InitScreen		 = intelInitScreen,
735e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .DestroyScreen	 = intelDestroyScreen,
736e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .CreateContext	 = intelCreateContext,
737e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .DestroyContext	 = intelDestroyContext,
738e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .CreateBuffer	 = intelCreateBuffer,
739e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .DestroyBuffer	 = intelDestroyBuffer,
740e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .SwapBuffers		 = intelSwapBuffers,
741e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .MakeCurrent		 = intelMakeCurrent,
742e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .UnbindContext	 = intelUnbindContext,
743e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .GetSwapInfo		 = intelGetSwapInfo,
744e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .GetDrawableMSC	 = driDrawableGetMSC32,
745e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .WaitForMSC		 = driWaitForMSC32,
746e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .CopySubBuffer	 = intelCopySubBuffer,
747e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
748e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   .InitScreen2		 = intelInitScreen2,
749e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg};
750