1 /* 2 * Copyright 2001-2005, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm <bpmagic@columbus.rr.com> 7 * Gabe Yoder <gyoder@stny.rr.com> 8 * Stephan Aßmus <superstippi@gmx.de> 9 */ 10 #ifndef DRAWING_ENGINE_H_ 11 #define DRAWING_ENGINE_H_ 12 13 14 #include <Accelerant.h> 15 #include <Font.h> 16 #include <Locker.h> 17 #include <Point.h> 18 19 #include "HWInterface.h" 20 21 class BPoint; 22 class BRect; 23 class BRegion; 24 25 class DrawState; 26 class Painter; 27 class RGBColor; 28 class ServerBitmap; 29 class ServerCursor; 30 class ServerFont; 31 32 typedef struct { 33 BPoint pt1; 34 BPoint pt2; 35 rgb_color color; 36 37 } LineArrayData; 38 39 class DrawingEngine : public HWInterfaceListener { 40 public: 41 DrawingEngine(HWInterface* interface = NULL); 42 virtual ~DrawingEngine(); 43 44 // HWInterfaceListener interface 45 virtual void FrameBufferChanged(); 46 47 // for "changing" hardware 48 void SetHWInterface(HWInterface* interface); 49 50 // locking 51 bool LockParallelAccess(); 52 bool IsParallelAccessLocked(); 53 void UnlockParallelAccess(); 54 55 bool LockExclusiveAccess(); 56 bool IsExclusiveAccessLocked(); 57 void UnlockExclusiveAccess(); 58 59 // for screen shots 60 bool DumpToFile(const char *path); 61 ServerBitmap* DumpToBitmap(); 62 status_t ReadBitmap(ServerBitmap *bitmap, bool drawCursor, 63 BRect bounds); 64 65 // clipping for all drawing functions, passing a NULL region 66 // will remove any clipping (drawing allowed everywhere) 67 void ConstrainClippingRegion(const BRegion* region); 68 69 void SuspendAutoSync(); 70 void Sync(); 71 72 // drawing functions 73 void CopyRegion(/*const*/ BRegion* region, 74 int32 xOffset, int32 yOffset); 75 76 void InvertRect(BRect r); 77 78 void DrawBitmap(ServerBitmap *bitmap, 79 const BRect &source, const BRect &dest, 80 const DrawState *d); 81 // drawing primitives 82 83 void DrawArc(BRect r, const float &angle, 84 const float &span, 85 const DrawState *d, 86 bool filled); 87 88 void DrawBezier(BPoint *pts, const DrawState *d, 89 bool filled); 90 91 void DrawEllipse(BRect r, const DrawState *d, 92 bool filled); 93 94 void DrawPolygon(BPoint *ptlist, int32 numpts, 95 BRect bounds, const DrawState *d, 96 bool filled, bool closed); 97 98 // these RGBColor versions are used internally by the server 99 void StrokePoint(const BPoint& pt, 100 const RGBColor& color); 101 void StrokeRect(BRect r, const RGBColor &color); 102 void FillRect(BRect r, const RGBColor &color); 103 void FillRegion(BRegion& r, const RGBColor& color); 104 105 void StrokeRect(BRect r, const DrawState *d); 106 void FillRect(BRect r, const DrawState *d); 107 108 void FillRegion(BRegion& r, const DrawState *d); 109 110 void DrawRoundRect(BRect r, float xrad, 111 float yrad, const DrawState *d, 112 bool filled); 113 114 void DrawShape(const BRect& bounds, 115 int32 opcount, const uint32* oplist, 116 int32 ptcount, const BPoint* ptlist, 117 const DrawState* d, bool filled); 118 119 void DrawTriangle(BPoint* pts, const BRect& bounds, 120 const DrawState* d, bool filled); 121 122 // this version used by Decorator 123 void StrokeLine(const BPoint& start, 124 const BPoint& end, const RGBColor& color); 125 126 void StrokeLine(const BPoint& start, 127 const BPoint& end, DrawState* d); 128 129 void StrokeLineArray(int32 numlines, 130 const LineArrayData* data, 131 const DrawState* d); 132 133 // -------- text related calls 134 135 // DrawState is NOT const because this call updates the 136 // pen position in the passed DrawState 137 BPoint DrawString(const char* string, int32 length, 138 const BPoint& pt, DrawState* d, 139 escapement_delta* delta = NULL); 140 141 float StringWidth(const char* string, int32 length, 142 const DrawState* d, 143 escapement_delta* delta = NULL); 144 145 float StringWidth(const char* string, 146 int32 length, const ServerFont& font, 147 escapement_delta* delta = NULL); 148 149 float StringHeight(const char* string, 150 int32 length, const DrawState* d); 151 152 private: 153 BRect _CopyRect(BRect r, int32 xOffset, 154 int32 yOffset) const; 155 156 void _CopyRect(uint8* bits, uint32 width, 157 uint32 height, uint32 bytesPerRow, 158 int32 xOffset, int32 yOffset) const; 159 160 Painter* fPainter; 161 HWInterface* fGraphicsCard; 162 uint32 fAvailableHWAccleration; 163 int32 fSuspendSyncLevel; 164 }; 165 166 #endif // DRAWING_ENGINE_H_ 167