framebuffer.cpp revision 1.7 1 /* -*-C++-*- $NetBSD: framebuffer.cpp,v 1.7 2001/04/24 19:27:59 uch Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <hpcmenu.h>
40 #include <machine/bootinfo.h>
41 #include <machine/platid.h>
42 #include <machine/platid_mask.h>
43
44 #include <framebuffer.h>
45
46 //
47 // framebuffer configuration table can be found in machine_config.cpp
48 //
49
50 FrameBufferInfo::FrameBufferInfo(u_int32_t cpu, u_int32_t machine)
51 {
52 struct framebuffer_info *tab = _table;
53 platid_mask_t target, entry;
54
55 target.dw.dw0 = cpu;
56 target.dw.dw1 = machine;
57 // search apriori setting if any.
58 for (; tab->cpu; tab++) {
59 entry.dw.dw0 = tab->cpu;
60 entry.dw.dw1 = tab->machine;
61 if (platid_match(&target, &entry)) {
62 _fb = tab;
63 return;
64 }
65 }
66
67 // fill default setting.
68 memset(&_default, 0, sizeof(struct framebuffer_info));
69
70 _default.cpu = cpu;
71 _default.machine = machine;
72 HDC hdc = GetDC(0);
73 _default.bpp = GetDeviceCaps(hdc, BITSPIXEL);
74 _default.width = GetDeviceCaps(hdc, HORZRES);
75 _default.height = GetDeviceCaps(hdc, VERTRES);
76 ReleaseDC(0, hdc);
77 _fb = &_default;
78 }
79
80 FrameBufferInfo::~FrameBufferInfo()
81 {
82 /* NO-OP */
83 }
84
85 int
86 FrameBufferInfo::type()
87 {
88 BOOL reverse = HPC_PREFERENCE.reverse_video;
89 int type;
90
91 switch(_fb->bpp) {
92 default:
93 // FALLTHROUGH
94 case 2:
95 type = reverse ? BIFB_D2_M2L_3 : BIFB_D2_M2L_0;
96 break;
97 case 4:
98 type = reverse ? BIFB_D4_M2L_F : BIFB_D4_M2L_0;
99 break;
100 case 8:
101 type = reverse ? BIFB_D8_FF : BIFB_D8_00;
102 break;
103 case 16:
104 type = reverse ? BIFB_D16_FFFF : BIFB_D16_0000;
105 break;
106 }
107
108 return type;
109 }
110