Welcome to mirror list, hosted at ThFree Co, Russian Federation.

wm_apple.c « intern « windowmanager « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 083500420a4bbf60871d5d60a4030ad08a5a2a76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * $Id$
 *
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version. 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * The Original Code is Copyright (C) 2007 Blender Foundation.
 * All rights reserved.
 *
 * 
 * Contributor(s): Blender Foundation
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/windowmanager/intern/wm_apple.c
 *  \ingroup wm
 */


#ifdef __APPLE__

#include "BKE_context.h"
#include "BKE_global.h"
#include "WM_api.h"

#include <OpenGL/OpenGL.h>
#define __CARBONSOUND__
/* XXX BIG WARNING: carbon.h can not be included in blender code, it conflicts with struct ID */
#define ID ID_
#include <Carbon/Carbon.h>


/* To avoid killing small end comps, we want to allow
blender to start maximised if all the followings are true :
- Renderer is OpenGL capable
- Hardware acceleration
- VRAM > 16 Mo

	We will bail out if VRAM is less than 8Mo
	*/
/* bad global, used in wm_window.c to open windows */
int macPrefState = 0;

static int checkAppleVideoCard(void) 
{
	CGLRendererInfoObj rend;
	long theErr;
	unsigned long display_mask;
	long nrend;
	int j;
	long value;
	long maxvram = 0;   /* we get always more than 1 renderer, check one, at least, has 8 Mo */
	
	display_mask = CGDisplayIDToOpenGLDisplayMask (CGMainDisplayID() );	
	
	theErr = CGLQueryRendererInfo( display_mask, &rend, &nrend);
	if (theErr == 0) {
		theErr = CGLDescribeRenderer (rend, 0, kCGLRPRendererCount, &nrend);
		if (theErr == 0) {
			for (j = 0; j < nrend; j++) {
				theErr = CGLDescribeRenderer (rend, j, kCGLRPVideoMemory, &value); 
				if (value > maxvram)
					maxvram = value;
				if ((theErr == 0) && (value >= 20000000)) {
					theErr = CGLDescribeRenderer (rend, j, kCGLRPAccelerated, &value); 
					if ((theErr == 0) && (value != 0)) {
						theErr = CGLDescribeRenderer (rend, j, kCGLRPCompliant, &value); 
						if ((theErr == 0) && (value != 0)) {
							/*fprintf(stderr,"make it big\n");*/
							CGLDestroyRendererInfo (rend);
							macPrefState = 8;
							return 1;
						}
					}
				}
			}
		}
	}
	if (maxvram < 7500000 ) {       /* put a standard alert and quit*/ 
		SInt16 junkHit;
		char  inError[] = "* Not enough VRAM    ";
		char  inText[] = "* blender needs at least 8Mb    ";
		inError[0] = 16;
		inText[0] = 28;
		
		fprintf(stderr, " vram is %li . not enough, aborting\n", maxvram);
		StandardAlert (   kAlertStopAlert, (ConstStr255Param) &inError, (ConstStr255Param)&inText,NULL,&junkHit);
		abort();
	}
CGLDestroyRendererInfo (rend);
return 0;
}

static void getMacAvailableBounds(short *top, short *left, short *bottom, short *right) 
{
	Rect outAvailableRect;
	
	GetAvailableWindowPositioningBounds ( GetMainDevice(), &outAvailableRect);
	
	*top = outAvailableRect.top;  
	*left = outAvailableRect.left;
	*bottom = outAvailableRect.bottom; 
	*right = outAvailableRect.right;
}


void wm_set_apple_prefsize(int scr_x, int scr_y)
{
	
	/* first let us check if we are hardware accelerated and with VRAM > 16 Mo */
	
	if (checkAppleVideoCard()) {
		short top, left, bottom, right;
		
		getMacAvailableBounds(&top, &left, &bottom, &right);
		WM_setprefsize(left +10,scr_y - bottom +10,right-left -20,bottom - 64);
		G.windowstate= 0;
		
	} else {
		
		/* 40 + 684 + (headers) 22 + 22 = 768, the powerbook screen height */
		WM_setprefsize(120, 40, 850, 684);
		G.windowstate= 0;
	}
}


#endif /* __APPLE__ */