1/*
2 * Copyright 2009, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Michael Lotz <mmlr@mlotz.ch>
7 */
8#ifndef REMOTE_DRAWING_ENGINE_H
9#define REMOTE_DRAWING_ENGINE_H
10
11#include "DrawingEngine.h"
12#include "DrawState.h"
13#include "RemoteHWInterface.h"
14#include "ServerFont.h"
15
16#include <AutoDeleter.h>
17
18class BPoint;
19class BRect;
20class BRegion;
21
22class BitmapDrawingEngine;
23class ServerBitmap;
24
25class RemoteDrawingEngine : public DrawingEngine {
26public:
27								RemoteDrawingEngine(
28									RemoteHWInterface* interface);
29	virtual						~RemoteDrawingEngine();
30
31	// HWInterfaceListener interface
32	virtual	void				FrameBufferChanged();
33
34	virtual	void				SetCopyToFrontEnabled(bool enabled);
35
36	// for screen shots
37	virtual	status_t			ReadBitmap(ServerBitmap* bitmap,
38									bool drawCursor, BRect bounds);
39
40	// clipping for all drawing functions, passing a NULL region
41	// will remove any clipping (drawing allowed everywhere)
42	virtual	void				ConstrainClippingRegion(const BRegion* region);
43
44	virtual	void				SetDrawState(const DrawState* state,
45									int32 xOffset = 0, int32 yOffset = 0);
46
47	virtual	void				SetHighColor(const rgb_color& color);
48	virtual	void				SetLowColor(const rgb_color& color);
49	virtual	void				SetPenSize(float size);
50	virtual	void				SetStrokeMode(cap_mode lineCap,
51									join_mode joinMode, float miterLimit);
52	virtual	void				SetPattern(const struct pattern& pattern);
53	virtual	void				SetDrawingMode(drawing_mode mode);
54	virtual	void				SetDrawingMode(drawing_mode mode,
55									drawing_mode& oldMode);
56	virtual	void				SetBlendingMode(source_alpha srcAlpha,
57									alpha_function alphaFunc);
58	virtual	void				SetFont(const ServerFont& font);
59	virtual	void				SetFont(const DrawState* state);
60	virtual	void				SetTransform(const BAffineTransform& transform,
61									int32 xOffset, int32 yOffset);
62
63	// drawing functions
64	virtual	void				InvertRect(BRect rect);
65
66	virtual	void				DrawBitmap(ServerBitmap* bitmap,
67									const BRect& bitmapRect,
68									const BRect& viewRect, uint32 options = 0);
69
70	// drawing primitives
71	virtual	void				DrawArc(BRect rect, const float& angle,
72									const float& span, bool filled);
73	virtual	void				FillArc(BRect rect, const float& angle,
74									const float& span,
75									const BGradient& gradient);
76
77	virtual	void				DrawBezier(BPoint* points, bool filled);
78	virtual	void				FillBezier(BPoint* points,
79									const BGradient& gradient);
80
81	virtual	void				DrawEllipse(BRect rect, bool filled);
82	virtual	void				FillEllipse(BRect rect,
83									const BGradient& gradient);
84
85	virtual	void				DrawPolygon(BPoint* pointList, int32 numPoints,
86									BRect bounds, bool filled, bool closed);
87	virtual	void				FillPolygon(BPoint* pointList, int32 numPoints,
88									BRect bounds, const BGradient& gradient,
89									bool closed);
90
91	// these rgb_color versions are used internally by the server
92	virtual	void				StrokePoint(const BPoint& point,
93									const rgb_color& color);
94	virtual	void				StrokeRect(BRect rect, const rgb_color &color);
95	virtual	void				FillRect(BRect rect, const rgb_color &color);
96	virtual	void				FillRegion(BRegion& region,
97									const rgb_color& color);
98
99	virtual	void				StrokeRect(BRect rect);
100	virtual	void				FillRect(BRect rect);
101	virtual	void				FillRect(BRect rect, const BGradient& gradient);
102
103	virtual	void				FillRegion(BRegion& region);
104	virtual	void				FillRegion(BRegion& region,
105									const BGradient& gradient);
106
107	virtual	void				DrawRoundRect(BRect rect, float xRadius,
108									float yRadius, bool filled);
109	virtual	void				FillRoundRect(BRect rect, float xRadius,
110									float yRadius, const BGradient& gradient);
111
112	virtual	void				DrawShape(const BRect& bounds,
113									int32 opCount, const uint32* opList,
114									int32 pointCount, const BPoint* pointList,
115									bool filled,
116									const BPoint& viewToScreenOffset,
117									float viewScale);
118	virtual	void				FillShape(const BRect& bounds,
119									int32 opCount, const uint32* opList,
120									int32 pointCount, const BPoint* pointList,
121									const BGradient& gradient,
122									const BPoint& viewToScreenOffset,
123									float viewScale);
124
125	virtual	void				DrawTriangle(BPoint* points,
126									const BRect& bounds, bool filled);
127	virtual	void				FillTriangle(BPoint* points,
128									const BRect& bounds,
129									const BGradient& gradient);
130
131	// these versions are used by the Decorator
132	virtual	void				StrokeLine(const BPoint& start,
133									const BPoint& end, const rgb_color& color);
134	virtual	void				StrokeLine(const BPoint& start,
135									const BPoint& end);
136	virtual	void				StrokeLineArray(int32 numlines,
137									const ViewLineArrayInfo* data);
138
139	// returns the pen position behind the (virtually) drawn string
140	virtual	BPoint				DrawString(const char* string, int32 length,
141									const BPoint& point,
142									escapement_delta* delta = NULL);
143	virtual	BPoint				DrawString(const char* string, int32 length,
144									const BPoint* offsets);
145
146	virtual	float				StringWidth(const char* string, int32 length,
147									escapement_delta* delta = NULL);
148
149	// software rendering backend invoked by CopyRegion() for the sorted
150	// individual rects
151	virtual	BRect				CopyRect(BRect rect, int32 xOffset,
152									int32 yOffset) const;
153
154private:
155			status_t			_AddCallback();
156
157	static	bool				_DrawingEngineResult(void* cookie,
158									RemoteMessage& message);
159
160			BRect				_BuildBounds(BPoint* points, int32 pointCount);
161			status_t			_ExtractBitmapRegions(ServerBitmap& bitmap,
162									uint32 options, const BRect& bitmapRect,
163									const BRect& viewRect, double xScale,
164									double yScale, BRegion& region,
165									UtilityBitmap**& bitmaps);
166
167			RemoteHWInterface*	fHWInterface;
168			int32				fToken;
169
170			DrawState			fState;
171			BRegion				fClippingRegion;
172			float				fExtendWidth;
173
174			bool				fCallbackAdded;
175			sem_id				fResultNotify;
176			BPoint				fDrawStringResult;
177			float				fStringWidthResult;
178			BBitmap*			fReadBitmapResult;
179
180			ObjectDeleter<BitmapDrawingEngine>
181								fBitmapDrawingEngine;
182};
183
184#endif // REMOTE_DRAWING_ENGINE_H
185