RemoteDesktop: Implement support for BAffineTransform.
[haiku.git] / src / servers / app / drawing / BitmapDrawingEngine.cpp
blob7a9e0ef5048d6a8d068eba123a816c2af1f0ecbd
1 #include "BitmapDrawingEngine.h"
2 #include "BitmapHWInterface.h"
3 #include "ServerBitmap.h"
4 #include <new>
7 BitmapDrawingEngine::BitmapDrawingEngine(color_space colorSpace)
8 : DrawingEngine(),
9 fColorSpace(colorSpace),
10 fHWInterface(NULL),
11 fBitmap(NULL)
16 BitmapDrawingEngine::~BitmapDrawingEngine()
18 SetSize(0, 0);
22 #if DEBUG
23 bool
24 BitmapDrawingEngine::IsParallelAccessLocked() const
26 // We don't share the HWInterface instance that the Painter is
27 // attached to, so we never need to be locked.
28 return true;
30 #endif
33 bool
34 BitmapDrawingEngine::IsExclusiveAccessLocked() const
36 // See IsParallelAccessLocked().
37 return true;
41 status_t
42 BitmapDrawingEngine::SetSize(int32 newWidth, int32 newHeight)
44 if (fBitmap != NULL && newWidth > 0 && newHeight > 0
45 && fBitmap->Bounds().IntegerWidth() >= newWidth
46 && fBitmap->Bounds().IntegerHeight() >= newHeight) {
47 return B_OK;
50 SetHWInterface(NULL);
51 if (fHWInterface != NULL) {
52 fHWInterface->LockExclusiveAccess();
53 fHWInterface->Shutdown();
54 fHWInterface->UnlockExclusiveAccess();
55 delete fHWInterface;
56 fHWInterface = NULL;
59 if (fBitmap != NULL) {
60 fBitmap->ReleaseReference();
61 fBitmap = NULL;
64 if (newWidth <= 0 || newHeight <= 0)
65 return B_OK;
67 fBitmap = new(std::nothrow) UtilityBitmap(BRect(0, 0, newWidth - 1,
68 newHeight - 1), fColorSpace, 0);
69 if (fBitmap == NULL)
70 return B_NO_MEMORY;
72 fHWInterface = new(std::nothrow) BitmapHWInterface(fBitmap);
73 if (fHWInterface == NULL)
74 return B_NO_MEMORY;
76 status_t result = fHWInterface->Initialize();
77 if (result != B_OK)
78 return result;
80 // we have to set a valid clipping first
81 fClipping.Set(fBitmap->Bounds());
82 ConstrainClippingRegion(&fClipping);
83 SetHWInterface(fHWInterface);
84 return B_OK;
88 UtilityBitmap*
89 BitmapDrawingEngine::ExportToBitmap(int32 width, int32 height,
90 color_space space)
92 if (width <= 0 || height <= 0)
93 return NULL;
95 UtilityBitmap *result = new(std::nothrow) UtilityBitmap(BRect(0, 0,
96 width - 1, height - 1), space, 0);
97 if (result == NULL)
98 return NULL;
100 if (result->ImportBits(fBitmap->Bits(), fBitmap->BitsLength(),
101 fBitmap->BytesPerRow(), fBitmap->ColorSpace()) != B_OK) {
102 delete result;
103 return NULL;
106 return result;