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