vfs: check userland buffers before reading them.
[haiku.git] / src / servers / app / drawing / BitmapHWInterface.cpp
blob60f9a1bd3b45a42f3b6b2a789caac6d37a1ff03d
1 /*
2 * Copyright 2002-2009, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Michael Lotz <mmlr@mlotz.ch>
7 * DarkWyrm <bpmagic@columbus.rr.com>
8 * Stephan Aßmus <superstippi@gmx.de>
9 */
12 #include <new>
13 #include <stdio.h>
14 #include <string.h>
16 #include "Bitmap.h"
17 #include "BitmapBuffer.h"
18 #include "BBitmapBuffer.h"
20 #include "BitmapHWInterface.h"
22 using std::nothrow;
25 BitmapHWInterface::BitmapHWInterface(ServerBitmap* bitmap)
27 HWInterface(false, false),
28 fBackBuffer(NULL),
29 fFrontBuffer(new(nothrow) BitmapBuffer(bitmap))
34 BitmapHWInterface::~BitmapHWInterface()
36 delete fBackBuffer;
37 delete fFrontBuffer;
41 status_t
42 BitmapHWInterface::Initialize()
44 status_t ret = HWInterface::Initialize();
45 if (ret < B_OK)
46 return ret;
48 ret = fFrontBuffer->InitCheck();
49 if (ret < B_OK)
50 return ret;
52 // TODO: Remove once unnecessary...
53 // fall back to double buffered mode until Painter knows how
54 // to draw onto non 32-bit surfaces...
55 if (fFrontBuffer->ColorSpace() != B_RGB32
56 && fFrontBuffer->ColorSpace() != B_RGBA32) {
57 BBitmap* backBitmap = new BBitmap(fFrontBuffer->Bounds(),
58 B_BITMAP_NO_SERVER_LINK, B_RGBA32);
59 fBackBuffer = new BBitmapBuffer(backBitmap);
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(), fFrontBuffer->BytesPerRow(), 0,
70 fFrontBuffer->ColorSpace());
74 return ret;
78 status_t
79 BitmapHWInterface::Shutdown()
81 return B_OK;
85 status_t
86 BitmapHWInterface::SetMode(const display_mode& mode)
88 return B_UNSUPPORTED;
92 void
93 BitmapHWInterface::GetMode(display_mode* mode)
95 if (mode != NULL)
96 memset(mode, 0, sizeof(display_mode));
100 status_t
101 BitmapHWInterface::GetDeviceInfo(accelerant_device_info* info)
103 return B_UNSUPPORTED;
107 status_t
108 BitmapHWInterface::GetFrameBufferConfig(frame_buffer_config& config)
110 return B_UNSUPPORTED;
114 status_t
115 BitmapHWInterface::GetModeList(display_mode** modes, uint32 *count)
117 return B_UNSUPPORTED;
121 status_t
122 BitmapHWInterface::GetPixelClockLimits(display_mode* mode, uint32* low,
123 uint32* high)
125 return B_UNSUPPORTED;
129 status_t
130 BitmapHWInterface::GetTimingConstraints(display_timing_constraints* constraints)
132 return B_UNSUPPORTED;
136 status_t
137 BitmapHWInterface::ProposeMode(display_mode* candidate, const display_mode* low,
138 const display_mode* high)
140 return B_UNSUPPORTED;
144 sem_id
145 BitmapHWInterface::RetraceSemaphore()
147 return -1;
151 status_t
152 BitmapHWInterface::WaitForRetrace(bigtime_t timeout)
154 return B_UNSUPPORTED;
158 status_t
159 BitmapHWInterface::SetDPMSMode(uint32 state)
161 return B_UNSUPPORTED;
165 uint32
166 BitmapHWInterface::DPMSMode()
168 return 0;
172 uint32
173 BitmapHWInterface::DPMSCapabilities()
175 return 0;
179 status_t
180 BitmapHWInterface::SetBrightness(float)
182 return B_UNSUPPORTED;
186 status_t
187 BitmapHWInterface::GetBrightness(float*)
189 return B_UNSUPPORTED;
193 RenderingBuffer*
194 BitmapHWInterface::FrontBuffer() const
196 return fFrontBuffer;
200 RenderingBuffer*
201 BitmapHWInterface::BackBuffer() const
203 return fBackBuffer;
207 bool
208 BitmapHWInterface::IsDoubleBuffered() const
210 // overwrite double buffered preference
211 if (fFrontBuffer)
212 return fBackBuffer != NULL;
214 return HWInterface::IsDoubleBuffered();