xref: /haiku/src/servers/app/drawing/DrawingEngine.h (revision fe2557b6eb55be3c2d36e1ee396e0f10e41bd214)
1 /*
2  * Copyright 2001-2015, 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  *		Julian Harnath <julian.harnath@rwth-aachen.de>
10  */
11 #ifndef DRAWING_ENGINE_H_
12 #define DRAWING_ENGINE_H_
13 
14 
15 #include <Accelerant.h>
16 #include <Font.h>
17 #include <Locker.h>
18 #include <Point.h>
19 #include <Gradient.h>
20 #include <ServerProtocolStructs.h>
21 
22 #include "HWInterface.h"
23 
24 
25 class BPoint;
26 class BRect;
27 class BRegion;
28 
29 class DrawState;
30 class Painter;
31 class ServerBitmap;
32 class ServerCursor;
33 class ServerFont;
34 
35 
36 class DrawingEngine : public HWInterfaceListener {
37 public:
38 							DrawingEngine(HWInterface* interface = NULL);
39 	virtual					~DrawingEngine();
40 
41 	// HWInterfaceListener interface
42 	virtual	void			FrameBufferChanged();
43 
44 	// for "changing" hardware
45 			void			SetHWInterface(HWInterface* interface);
46 
47 	virtual	void			SetCopyToFrontEnabled(bool enable);
48 			bool			CopyToFrontEnabled() const
49 								{ return fCopyToFront; }
50 	virtual	void			CopyToFront(/*const*/ BRegion& region);
51 
52 	// locking
53 			bool			LockParallelAccess();
54 #if DEBUG
55 	virtual	bool			IsParallelAccessLocked() const;
56 #endif
57 			void			UnlockParallelAccess();
58 
59 			bool			LockExclusiveAccess();
60 	virtual	bool			IsExclusiveAccessLocked() const;
61 			void			UnlockExclusiveAccess();
62 
63 	// for screen shots
64 			ServerBitmap*	DumpToBitmap();
65 	virtual	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 	virtual	void			ConstrainClippingRegion(const BRegion* region);
71 
72 	virtual	void			SetDrawState(const DrawState* state,
73 								int32 xOffset = 0, int32 yOffset = 0);
74 
75 	virtual	void			SetHighColor(const rgb_color& color);
76 	virtual	void			SetLowColor(const rgb_color& color);
77 	virtual	void			SetPenSize(float size);
78 	virtual	void			SetStrokeMode(cap_mode lineCap, join_mode joinMode,
79 								float miterLimit);
80 	virtual void			SetFillRule(int32 fillRule);
81 	virtual	void			SetPattern(const struct pattern& pattern);
82 	virtual	void			SetDrawingMode(drawing_mode mode);
83 	virtual	void			SetDrawingMode(drawing_mode mode,
84 								drawing_mode& oldMode);
85 	virtual	void			SetBlendingMode(source_alpha srcAlpha,
86 								alpha_function alphaFunc);
87 	virtual	void			SetFont(const ServerFont& font);
88 	virtual	void			SetFont(const DrawState* state);
89 	virtual	void			SetTransform(const BAffineTransform& transform);
90 
91 			void			SuspendAutoSync();
92 			void			Sync();
93 
94 	// drawing functions
95 	virtual	void			CopyRegion(/*const*/ BRegion* region,
96 								int32 xOffset, int32 yOffset);
97 
98 	virtual	void			InvertRect(BRect r);
99 
100 	virtual	void			DrawBitmap(ServerBitmap* bitmap,
101 								const BRect& bitmapRect, const BRect& viewRect,
102 								uint32 options = 0);
103 	// drawing primitives
104 	virtual	void			DrawArc(BRect r, const float& angle,
105 								const float& span, bool filled);
106 	virtual	void			FillArc(BRect r, const float& angle,
107 								const float& span, const BGradient& gradient);
108 
109 	virtual	void			DrawBezier(BPoint* pts, bool filled);
110 	virtual	void			FillBezier(BPoint* pts, const BGradient& gradient);
111 
112 	virtual	void			DrawEllipse(BRect r, bool filled);
113 	virtual	void			FillEllipse(BRect r, const BGradient& gradient);
114 
115 	virtual	void			DrawPolygon(BPoint* ptlist, int32 numpts,
116 								BRect bounds, bool filled, bool closed);
117 	virtual	void			FillPolygon(BPoint* ptlist, int32 numpts,
118 								BRect bounds, const BGradient& gradient,
119 								bool closed);
120 
121 	// these rgb_color versions are used internally by the server
122 	virtual	void			StrokePoint(const BPoint& point,
123 								const rgb_color& color);
124 	virtual	void			StrokeRect(BRect rect, const rgb_color &color);
125 	virtual	void			FillRect(BRect rect, const rgb_color &color);
126 	virtual	void			FillRegion(BRegion& region, const rgb_color& color);
127 
128 	virtual	void			StrokeRect(BRect rect);
129 	virtual	void			FillRect(BRect rect);
130 	virtual	void			FillRect(BRect rect, const BGradient& gradient);
131 
132 	virtual	void			FillRegion(BRegion& region);
133 	virtual	void			FillRegion(BRegion& region,
134 								const BGradient& gradient);
135 
136 	virtual	void			DrawRoundRect(BRect rect, float xrad,
137 								float yrad, bool filled);
138 	virtual	void			FillRoundRect(BRect rect, float xrad,
139 								float yrad, const BGradient& gradient);
140 
141 	virtual	void			DrawShape(const BRect& bounds,
142 								int32 opcount, const uint32* oplist,
143 								int32 ptcount, const BPoint* ptlist,
144 								bool filled, const BPoint& viewToScreenOffset,
145 								float viewScale);
146 	virtual	void			FillShape(const BRect& bounds,
147 								int32 opcount, const uint32* oplist,
148 							 	int32 ptcount, const BPoint* ptlist,
149 							 	const BGradient& gradient,
150 							 	const BPoint& viewToScreenOffset,
151 								float viewScale);
152 
153 	virtual	void			DrawTriangle(BPoint* points, const BRect& bounds,
154 								bool filled);
155 	virtual	void			FillTriangle(BPoint* points, const BRect& bounds,
156 								const BGradient& gradient);
157 
158 	// these versions are used by the Decorator
159 	virtual	void			StrokeLine(const BPoint& start,
160 								const BPoint& end, const rgb_color& color);
161 
162 	virtual	void			StrokeLine(const BPoint& start,
163 								const BPoint& end);
164 
165 	virtual	void			StrokeLineArray(int32 numlines,
166 								const ViewLineArrayInfo* data);
167 
168 	// -------- text related calls
169 
170 	// returns the pen position behind the (virtually) drawn
171 	// string
172 	virtual	BPoint			DrawString(const char* string, int32 length,
173 								const BPoint& pt,
174 								escapement_delta* delta = NULL);
175 	virtual	BPoint			DrawString(const char* string, int32 length,
176 								const BPoint* offsets);
177 
178 			float			StringWidth(const char* string, int32 length,
179 								escapement_delta* delta = NULL);
180 
181 	// convenience function which is independent of graphics
182 	// state (to be used by Decorator or ServerApp etc)
183 			float			StringWidth(const char* string,
184 								int32 length, const ServerFont& font,
185 								escapement_delta* delta = NULL);
186 
187 	// software rendering backend invoked by CopyRegion() for the sorted
188 	// individual rects
189 	virtual	BRect			CopyRect(BRect rect, int32 xOffset,
190 								int32 yOffset) const;
191 
192 			void			SetRendererOffset(int32 offsetX, int32 offsetY);
193 
194 private:
195 			void			_CopyRect(uint8* bits, uint32 width,
196 								uint32 height, uint32 bytesPerRow,
197 								int32 xOffset, int32 yOffset) const;
198 
199 	inline	void			_CopyToFront(const BRect& frame);
200 
201 			Painter*		fPainter;
202 			HWInterface*	fGraphicsCard;
203 			uint32			fAvailableHWAccleration;
204 			int32			fSuspendSyncLevel;
205 			bool			fCopyToFront;
206 };
207 
208 #endif // DRAWING_ENGINE_H_
209