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