xref: /haiku/src/servers/app/drawing/BitmapHWInterface.cpp (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
1 /*
2  * Copyright 2002-2005, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Lotz <mmlr@mlotz.ch>
7  *		DarkWyrm <bpmagic@columbus.rr.com>
8  *		Stephan Aßmus <superstippi@gmx.de>
9  */
10 
11 
12 #include <new>
13 #include <stdio.h>
14 #include <string.h>
15 
16 #include "Bitmap.h"
17 #include "BitmapBuffer.h"
18 #include "BBitmapBuffer.h"
19 
20 #include "BitmapHWInterface.h"
21 
22 using std::nothrow;
23 
24 
25 BitmapHWInterface::BitmapHWInterface(ServerBitmap* bitmap)
26 	: HWInterface(),
27 	  fBackBuffer(NULL),
28 	  fFrontBuffer(new(nothrow) BitmapBuffer(bitmap))
29 {
30 }
31 
32 
33 BitmapHWInterface::~BitmapHWInterface()
34 {
35 	delete fBackBuffer;
36 	delete fFrontBuffer;
37 }
38 
39 
40 status_t
41 BitmapHWInterface::Initialize()
42 {
43 	status_t ret = HWInterface::Initialize();
44 	if (ret < B_OK)
45 		return ret;
46 
47 	ret = fFrontBuffer->InitCheck();
48 	if (ret < B_OK)
49 		return ret;
50 
51 // TODO: Remove once unnecessary...
52 	// fall back to double buffered mode until Painter knows how
53 	// to draw onto non 32-bit surfaces...
54 	if (fFrontBuffer->ColorSpace() != B_RGB32
55 		&& fFrontBuffer->ColorSpace() != B_RGBA32) {
56 		BBitmap* backBitmap = new BBitmap(fFrontBuffer->Bounds(),
57 										  B_BITMAP_NO_SERVER_LINK,
58 										  B_RGBA32);
59 		fBackBuffer = new BBitmapBuffer(backBitmap);
60 
61 		ret = fBackBuffer->InitCheck();
62 		if (ret < B_OK) {
63 			delete fBackBuffer;
64 			fBackBuffer = NULL;
65 		} else {
66 			// import the current contents of the bitmap
67 			// into the back bitmap
68 			backBitmap->ImportBits(fFrontBuffer->Bits(),
69 								   fFrontBuffer->BitsLength(),
70 								   fFrontBuffer->BytesPerRow(),
71 								   0,
72 								   fFrontBuffer->ColorSpace());
73 		}
74 	}
75 
76 	return ret;
77 }
78 
79 
80 status_t
81 BitmapHWInterface::Shutdown()
82 {
83 	return B_OK;
84 }
85 
86 
87 status_t
88 BitmapHWInterface::SetMode(const display_mode &mode)
89 {
90 	return B_UNSUPPORTED;
91 }
92 
93 
94 void
95 BitmapHWInterface::GetMode(display_mode *mode)
96 {
97 	if (mode) {
98 		memset(mode, 0, sizeof(display_mode));
99 	}
100 }
101 
102 
103 status_t
104 BitmapHWInterface::GetDeviceInfo(accelerant_device_info *info)
105 {
106 	return B_UNSUPPORTED;
107 }
108 
109 
110 status_t
111 BitmapHWInterface::GetFrameBufferConfig(frame_buffer_config& config)
112 {
113 	return B_UNSUPPORTED;
114 }
115 
116 
117 status_t
118 BitmapHWInterface::GetModeList(display_mode** modes, uint32 *count)
119 {
120 	return B_UNSUPPORTED;
121 }
122 
123 // GetPixelClockLimits
124 status_t
125 BitmapHWInterface::GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high)
126 {
127 	return B_UNSUPPORTED;
128 }
129 
130 // GetPixelClockLimits
131 status_t
132 BitmapHWInterface::GetTimingConstraints(display_timing_constraints *dtc)
133 {
134 	return B_UNSUPPORTED;
135 }
136 
137 // ProposeMode
138 status_t
139 BitmapHWInterface::ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high)
140 {
141 	return B_UNSUPPORTED;
142 }
143 
144 // RetraceSemaphore
145 sem_id
146 BitmapHWInterface::RetraceSemaphore()
147 {
148 	return B_ERROR;
149 }
150 
151 // WaitForRetrace
152 status_t
153 BitmapHWInterface::WaitForRetrace(bigtime_t timeout)
154 {
155 	return B_UNSUPPORTED;
156 }
157 
158 // SetDPMSMode
159 status_t
160 BitmapHWInterface::SetDPMSMode(const uint32 &state)
161 {
162 	return B_UNSUPPORTED;
163 }
164 
165 // DPMSMode
166 uint32
167 BitmapHWInterface::DPMSMode()
168 {
169 	return 0;
170 }
171 
172 // DPMSCapabilities
173 uint32
174 BitmapHWInterface::DPMSCapabilities()
175 {
176 	return 0;
177 }
178 
179 // FrontBuffer
180 RenderingBuffer *
181 BitmapHWInterface::FrontBuffer() const
182 {
183 	return fFrontBuffer;
184 }
185 
186 // BackBuffer
187 RenderingBuffer *
188 BitmapHWInterface::BackBuffer() const
189 {
190 	return fBackBuffer;
191 }
192 
193 // IsDoubleBuffered
194 bool
195 BitmapHWInterface::IsDoubleBuffered() const
196 {
197 	// overwrite double buffered preference
198 	if (fFrontBuffer)
199 		return fBackBuffer != NULL;
200 
201 	return HWInterface::IsDoubleBuffered();
202 }
203 
204 
205