xref: /haiku/src/servers/app/drawing/DrawingEngine.h (revision 582da17386c4a192ca30270d6b0b95f561cf5843)
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 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			SetDrawState(const DrawState* state,
70 								int32 xOffset = 0, int32 yOffset = 0);
71 
72 			void			SetHighColor(const rgb_color& color);
73 			void			SetLowColor(const rgb_color& color);
74 			void			SetPenSize(float size);
75 			void			SetPattern(const struct pattern& pattern);
76 			void			SetDrawingMode(drawing_mode mode);
77 
78 			void			SuspendAutoSync();
79 			void			Sync();
80 
81 			// drawing functions
82 			void			CopyRegion(/*const*/ BRegion* region,
83 								int32 xOffset, int32 yOffset);
84 
85 			void			InvertRect(BRect r);
86 
87 			void			DrawBitmap(ServerBitmap *bitmap,
88 								const BRect &source, const BRect &dest,
89 								const DrawState *d);
90 			// drawing primitives
91 
92 			void			DrawArc(BRect r, const float &angle,
93 								const float &span,
94 								const DrawState *d,
95 								bool filled);
96 
97 			void			DrawBezier(BPoint *pts, const DrawState *d,
98 								bool filled);
99 
100 			void			DrawEllipse(BRect r, const DrawState *d,
101 								bool filled);
102 
103 			void			DrawPolygon(BPoint *ptlist, int32 numpts,
104 								BRect bounds, const DrawState *d,
105 								bool filled, bool closed);
106 
107 			// these RGBColor versions are used internally by the server
108 			void			StrokePoint(const BPoint& pt,
109 								const RGBColor& color);
110 			void			StrokeRect(BRect r, const RGBColor &color);
111 			void			FillRect(BRect r, const RGBColor &color);
112 			void			FillRegion(BRegion& r, const RGBColor& color);
113 
114 			void			StrokeRect(BRect r, const DrawState *d);
115 			void			FillRect(BRect r, const DrawState *d);
116 
117 			void			FillRegion(BRegion& r, const DrawState *d);
118 
119 			void			DrawRoundRect(BRect r, float xrad,
120 								float yrad, const DrawState *d,
121 								bool filled);
122 
123 			void			DrawShape(const BRect& bounds,
124 								int32 opcount, const uint32* oplist,
125 								int32 ptcount, const BPoint* ptlist,
126 								const DrawState* d, bool filled);
127 
128 			void			DrawTriangle(BPoint* pts, const BRect& bounds,
129 								const DrawState* d, bool filled);
130 
131 			// this version used by Decorator
132 			void			StrokeLine(const BPoint& start,
133 								const BPoint& end, const RGBColor& color);
134 
135 			void			StrokeLine(const BPoint& start,
136 								const BPoint& end, DrawState* d);
137 
138 			void			StrokeLineArray(int32 numlines,
139 								const LineArrayData* data,
140 								const DrawState* d);
141 
142 			// -------- text related calls
143 
144 			// DrawState is NOT const because this call updates the
145 			// pen position in the passed DrawState
146 			BPoint			DrawString(const char* string, int32 length,
147 								const BPoint& pt, DrawState* d,
148 								escapement_delta* delta = NULL);
149 
150 			float			StringWidth(const char* string, int32 length,
151 								const DrawState* d,
152 								escapement_delta* delta = NULL);
153 
154 			float			StringWidth(const char* string,
155 								int32 length, const ServerFont& font,
156 								escapement_delta* delta = NULL);
157 
158 			float			StringHeight(const char* string,
159 								int32 length, const DrawState* d);
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 			Painter*		fPainter;
170 			HWInterface*	fGraphicsCard;
171 			uint32			fAvailableHWAccleration;
172 			int32			fSuspendSyncLevel;
173 };
174 
175 #endif // DRAWING_ENGINE_H_
176