intel_device.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00028 
00029 #include "utils.h"
00030 
00031 #include "state_tracker/st_public.h"
00032 #include "i915simple/i915_screen.h"
00033 
00034 #include "intel_context.h"
00035 #include "intel_device.h"
00036 #include "intel_batchbuffer.h"
00037 #include "intel_egl.h"
00038 
00039 
00040 extern const struct dri_extension card_extensions[];
00041 
00042 
00043 int
00044 intel_create_device(struct egl_drm_device *device)
00045 {
00046         struct intel_device *intel_device;
00047 
00048         /* Allocate the private area */
00049         intel_device = CALLOC_STRUCT(intel_device);
00050         if (!intel_device)
00051                 return FALSE;
00052 
00053         device->priv = (void *)intel_device;
00054         intel_device->device = device;
00055 
00056         intel_device->deviceID = device->deviceID;
00057 
00058         intel_be_init_device(&intel_device->base, device->drmFD, intel_device->deviceID);
00059 
00060         intel_device->pipe = i915_create_screen(&intel_device->base.base, intel_device->deviceID);
00061 
00062         /* hack */
00063         driInitExtensions(NULL, card_extensions, GL_FALSE);
00064 
00065         return TRUE;
00066 }
00067 
00068 int
00069 intel_destroy_device(struct egl_drm_device *device)
00070 {
00071         struct intel_device *intel_device = (struct intel_device *)device->priv;
00072         
00073         intel_be_destroy_device(&intel_device->base);
00074 
00075         free(intel_device);
00076         device->priv = NULL;
00077 
00078         return TRUE;
00079 }
00080 
00081 int
00082 intel_create_drawable(struct egl_drm_drawable *drawable,
00083                       const __GLcontextModes * visual)
00084 {
00085         enum pipe_format colorFormat, depthFormat, stencilFormat;
00086         struct intel_framebuffer *intelfb = CALLOC_STRUCT(intel_framebuffer);
00087 
00088         if (!intelfb)
00089                 return GL_FALSE;
00090 
00091         intelfb->device = drawable->device->priv;
00092 
00093         if (visual->redBits == 5)
00094                 colorFormat = PIPE_FORMAT_R5G6B5_UNORM;
00095         else
00096                 colorFormat = PIPE_FORMAT_A8R8G8B8_UNORM;
00097 
00098         if (visual->depthBits == 16)
00099                 depthFormat = PIPE_FORMAT_Z16_UNORM;
00100         else if (visual->depthBits == 24)
00101                 depthFormat = PIPE_FORMAT_S8Z24_UNORM;
00102         else
00103                 depthFormat = PIPE_FORMAT_NONE;
00104 
00105         if (visual->stencilBits == 8)
00106                 stencilFormat = PIPE_FORMAT_S8Z24_UNORM;
00107         else
00108                 stencilFormat = PIPE_FORMAT_NONE;
00109 
00110         intelfb->stfb = st_create_framebuffer(visual,
00111                         colorFormat,
00112                         depthFormat,
00113                         stencilFormat,
00114                         drawable->w,
00115                         drawable->h,
00116                         (void*) intelfb);
00117 
00118         if (!intelfb->stfb) {
00119                 free(intelfb);
00120                 return GL_FALSE;
00121         }
00122 
00123         drawable->priv = (void *) intelfb;
00124         return GL_TRUE;
00125 }
00126 
00127 int
00128 intel_destroy_drawable(struct egl_drm_drawable *drawable)
00129 {
00130         struct intel_framebuffer *intelfb = (struct intel_framebuffer *)drawable->priv;
00131         drawable->priv = NULL;
00132 
00133         assert(intelfb->stfb);
00134         st_unreference_framebuffer(&intelfb->stfb);
00135         free(intelfb);
00136         return TRUE;
00137 }

Generated on Tue Sep 29 06:25:17 2009 for Gallium3D by  doxygen 1.5.4