1 /* 2 * Copyright 2001-2007, 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 ServerBitmap; 28 class ServerCursor; 29 class ServerFont; 30 31 typedef struct { 32 BPoint pt1; 33 BPoint pt2; 34 rgb_color color; 35 36 } LineArrayData; 37 38 class DrawingEngine : public HWInterfaceListener { 39 public: 40 DrawingEngine(HWInterface* interface = NULL); 41 virtual ~DrawingEngine(); 42 43 // HWInterfaceListener interface 44 virtual void FrameBufferChanged(); 45 46 // for "changing" hardware 47 void SetHWInterface(HWInterface* interface); 48 49 // locking 50 bool LockParallelAccess(); 51 bool IsParallelAccessLocked(); 52 void UnlockParallelAccess(); 53 54 bool LockExclusiveAccess(); 55 bool IsExclusiveAccessLocked(); 56 void UnlockExclusiveAccess(); 57 58 // for screen shots 59 bool DumpToFile(const char *path); 60 ServerBitmap* DumpToBitmap(); 61 status_t ReadBitmap(ServerBitmap *bitmap, bool drawCursor, 62 BRect bounds); 63 64 // clipping for all drawing functions, passing a NULL region 65 // will remove any clipping (drawing allowed everywhere) 66 void ConstrainClippingRegion(const BRegion* region); 67 68 void SetDrawState(const DrawState* state, 69 int32 xOffset = 0, int32 yOffset = 0); 70 71 void SetHighColor(const rgb_color& color); 72 void SetLowColor(const rgb_color& color); 73 void SetPenSize(float size); 74 void SetStrokeMode(cap_mode lineCap, join_mode joinMode, 75 float miterLimit); 76 void SetPattern(const struct pattern& pattern); 77 void SetDrawingMode(drawing_mode mode); 78 void SetBlendingMode(source_alpha srcAlpha, 79 alpha_function alphaFunc); 80 void SetFont(const ServerFont& font); 81 void SetFont(const DrawState* state); 82 83 void SuspendAutoSync(); 84 void Sync(); 85 86 // drawing functions 87 void CopyRegion(/*const*/ BRegion* region, 88 int32 xOffset, int32 yOffset); 89 90 void InvertRect(BRect r); 91 92 void DrawBitmap(ServerBitmap *bitmap, 93 const BRect &source, const BRect &dest); 94 // drawing primitives 95 96 void DrawArc(BRect r, const float &angle, 97 const float &span, bool filled); 98 99 void DrawBezier(BPoint *pts, bool filled); 100 101 void DrawEllipse(BRect r, bool filled); 102 103 void DrawPolygon(BPoint *ptlist, int32 numpts, 104 BRect bounds, bool filled, bool closed); 105 106 // these rgb_color versions are used internally by the server 107 void StrokePoint(const BPoint& pt, 108 const rgb_color& color); 109 void StrokeRect(BRect r, const rgb_color &color); 110 void FillRect(BRect r, const rgb_color &color); 111 void FillRegion(BRegion& r, const rgb_color& color); 112 113 void StrokeRect(BRect r); 114 void FillRect(BRect r); 115 116 void FillRegion(BRegion& r); 117 118 void DrawRoundRect(BRect r, float xrad, 119 float yrad, bool filled); 120 121 void DrawShape(const BRect& bounds, 122 int32 opcount, const uint32* oplist, 123 int32 ptcount, const BPoint* ptlist, 124 bool filled); 125 126 void DrawTriangle(BPoint* pts, const BRect& bounds, 127 bool filled); 128 129 // this version used by Decorator 130 void StrokeLine(const BPoint& start, 131 const BPoint& end, const rgb_color& color); 132 133 void StrokeLine(const BPoint& start, 134 const BPoint& end); 135 136 void StrokeLineArray(int32 numlines, 137 const LineArrayData* data); 138 139 // -------- text related calls 140 141 // returns the pen position behind the (virtually) drawn 142 // string 143 BPoint DrawString(const char* string, int32 length, 144 const BPoint& pt, 145 escapement_delta* delta = NULL); 146 147 float StringWidth(const char* string, int32 length, 148 escapement_delta* delta = NULL); 149 150 // convenience function which is independent of graphics 151 // state (to be used by Decorator or ServerApp etc) 152 float StringWidth(const char* string, 153 int32 length, const ServerFont& font, 154 escapement_delta* delta = NULL); 155 156 private: 157 BRect _CopyRect(BRect r, int32 xOffset, 158 int32 yOffset) const; 159 160 void _CopyRect(uint8* bits, uint32 width, 161 uint32 height, uint32 bytesPerRow, 162 int32 xOffset, int32 yOffset) const; 163 164 Painter* fPainter; 165 HWInterface* fGraphicsCard; 166 uint32 fAvailableHWAccleration; 167 int32 fSuspendSyncLevel; 168 }; 169 170 #endif // DRAWING_ENGINE_H_ 171