xref: /haiku/src/servers/app/drawing/DrawingEngine.h (revision cfc3fa87da824bdf593eb8b817a83b6376e77935)
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 
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 			void			SetCopyToFrontEnabled(bool enable);
50 			bool			CopyToFrontEnabled() const
51 								{ return fCopyToFront; }
52 			void			CopyToFront(/*const*/ BRegion& region);
53 
54 			// locking
55 			bool			LockParallelAccess();
56 			bool			IsParallelAccessLocked();
57 			void			UnlockParallelAccess();
58 
59 			bool			LockExclusiveAccess();
60 			bool			IsExclusiveAccessLocked();
61 			void			UnlockExclusiveAccess();
62 
63 			// for screen shots
64 			bool			DumpToFile(const char *path);
65 			ServerBitmap*	DumpToBitmap();
66 			status_t		ReadBitmap(ServerBitmap *bitmap, bool drawCursor,
67 								BRect bounds);
68 
69 			// clipping for all drawing functions, passing a NULL region
70 			// will remove any clipping (drawing allowed everywhere)
71 			void			ConstrainClippingRegion(const BRegion* region);
72 
73 			void			SetDrawState(const DrawState* state,
74 								int32 xOffset = 0, int32 yOffset = 0);
75 
76 			void			SetHighColor(const rgb_color& color);
77 			void			SetLowColor(const rgb_color& color);
78 			void			SetPenSize(float size);
79 			void			SetStrokeMode(cap_mode lineCap, join_mode joinMode,
80 								float miterLimit);
81 			void			SetPattern(const struct pattern& pattern);
82 			void			SetDrawingMode(drawing_mode mode);
83 			void			SetBlendingMode(source_alpha srcAlpha,
84 								alpha_function alphaFunc);
85 			void			SetFont(const ServerFont& font);
86 			void			SetFont(const DrawState* state);
87 
88 			void			SuspendAutoSync();
89 			void			Sync();
90 
91 			// drawing functions
92 			void			CopyRegion(/*const*/ BRegion* region,
93 								int32 xOffset, int32 yOffset);
94 
95 			void			InvertRect(BRect r);
96 
97 			void			DrawBitmap(ServerBitmap *bitmap,
98 								const BRect &source, const BRect &dest);
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