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