Blender V2.61 - r43446

wm_apple.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2007 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * 
00022  * Contributor(s): Blender Foundation
00023  *
00024  * ***** END GPL LICENSE BLOCK *****
00025  */
00026 
00031 /* note, this file builds on apple-carbon only! */
00032 
00033 #include "BKE_context.h"
00034 #include "BKE_global.h"
00035 #include "WM_api.h"
00036 
00037 #include <OpenGL/OpenGL.h>
00038 #define __CARBONSOUND__
00039 /* XXX BIG WARNING: carbon.h can not be included in blender code, it conflicts with struct ID */
00040 #define ID ID_
00041 #include <Carbon/Carbon.h>
00042 
00043 
00044 /* To avoid killing small end comps, we want to allow
00045 blender to start maximised if all the followings are true :
00046 - Renderer is OpenGL capable
00047 - Hardware acceleration
00048 - VRAM > 16 Mo
00049 
00050     We will bail out if VRAM is less than 8Mo
00051     */
00052 /* bad global, used in wm_window.c to open windows */
00053 int macPrefState = 0;
00054 
00055 static int checkAppleVideoCard(void) 
00056 {
00057     CGLRendererInfoObj rend;
00058     long theErr;
00059     unsigned long display_mask;
00060     long nrend;
00061     int j;
00062     long value;
00063     long maxvram = 0;   /* we get always more than 1 renderer, check one, at least, has 8 Mo */
00064     
00065     display_mask = CGDisplayIDToOpenGLDisplayMask (CGMainDisplayID() ); 
00066     
00067     theErr = CGLQueryRendererInfo( display_mask, &rend, &nrend);
00068     if (theErr == 0) {
00069         theErr = CGLDescribeRenderer (rend, 0, kCGLRPRendererCount, &nrend);
00070         if (theErr == 0) {
00071             for (j = 0; j < nrend; j++) {
00072                 theErr = CGLDescribeRenderer (rend, j, kCGLRPVideoMemory, &value); 
00073                 if (value > maxvram)
00074                     maxvram = value;
00075                 if ((theErr == 0) && (value >= 20000000)) {
00076                     theErr = CGLDescribeRenderer (rend, j, kCGLRPAccelerated, &value); 
00077                     if ((theErr == 0) && (value != 0)) {
00078                         theErr = CGLDescribeRenderer (rend, j, kCGLRPCompliant, &value); 
00079                         if ((theErr == 0) && (value != 0)) {
00080                             /*fprintf(stderr,"make it big\n");*/
00081                             CGLDestroyRendererInfo (rend);
00082                             macPrefState = 8;
00083                             return 1;
00084                         }
00085                     }
00086                 }
00087             }
00088         }
00089     }
00090     if (maxvram < 7500000 ) {       /* put a standard alert and quit*/ 
00091         SInt16 junkHit;
00092         char  inError[] = "* Not enough VRAM    ";
00093         char  inText[] = "* blender needs at least 8Mb    ";
00094         inError[0] = 16;
00095         inText[0] = 28;
00096         
00097         fprintf(stderr, " vram is %li . not enough, aborting\n", maxvram);
00098         StandardAlert (   kAlertStopAlert, (ConstStr255Param) &inError, (ConstStr255Param)&inText,NULL,&junkHit);
00099         abort();
00100     }
00101     CGLDestroyRendererInfo (rend);
00102     return 0;
00103 }
00104 
00105 static void getMacAvailableBounds(short *top, short *left, short *bottom, short *right) 
00106 {
00107     Rect outAvailableRect;
00108     
00109     GetAvailableWindowPositioningBounds ( GetMainDevice(), &outAvailableRect);
00110     
00111     *top = outAvailableRect.top;  
00112     *left = outAvailableRect.left;
00113     *bottom = outAvailableRect.bottom; 
00114     *right = outAvailableRect.right;
00115 }
00116 
00117 
00118 void wm_set_apple_prefsize(int scr_x, int scr_y)
00119 {
00120     
00121     /* first let us check if we are hardware accelerated and with VRAM > 16 Mo */
00122     
00123     if (checkAppleVideoCard()) {
00124         short top, left, bottom, right;
00125         
00126         getMacAvailableBounds(&top, &left, &bottom, &right);
00127         WM_setprefsize(left +10,scr_y - bottom +10,right-left -20,bottom - 64);
00128         G.windowstate= 0;
00129         
00130     } else {
00131         
00132         /* 40 + 684 + (headers) 22 + 22 = 768, the powerbook screen height */
00133         WM_setprefsize(120, 40, 850, 684);
00134         G.windowstate= 0;
00135     }
00136 }