xref: /haiku/src/tests/servers/app/newerClipping/WindowLayer.h (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 
2 #ifndef WINDOW_LAYER_H
3 #define WINDOW_LAYER_H
4 
5 #include <List.h>
6 #include <Looper.h>
7 #include <Region.h>
8 #include <String.h>
9 
10 #include "ViewLayer.h"
11 
12 class ClientLooper;
13 class Desktop;
14 class DrawingEngine;
15 
16 enum {
17 	MSG_REDRAW				= 'rdrw',
18 
19 	// client messages
20 	MSG_BEGIN_UPDATE		= 'bgud',
21 	MSG_END_UPDATE			= 'edud',
22 	MSG_DRAWING_COMMAND		= 'draw',
23 
24 	MSG_SHOW				= 'show',
25 
26 	MSG_INVALIDATE_VIEW		= 'invl',
27 	MSG_DRAW_POLYGON		= 'drwp',
28 };
29 
30 class UpdateSession {
31  public:
32 									UpdateSession();
33 	virtual							~UpdateSession();
34 
35 			void					Include(BRegion* additionalDirty);
36 			void					Exclude(BRegion* dirtyInNextSession);
37 
38 	inline	BRegion&				DirtyRegion()
39 										{ return fDirtyRegion; }
40 
41 			void					MoveBy(int32 x, int32 y);
42 
43 			void					SetUsed(bool used);
44 	inline	bool					IsUsed() const
45 										{ return fInUse; }
46 
47 			UpdateSession&			operator=(const UpdateSession& other);
48 
49  private:
50 			BRegion					fDirtyRegion;
51 			bool					fInUse;
52 };
53 
54 class WindowLayer : public BLooper {
55  public:
56 									WindowLayer(BRect frame, const char* name,
57 												DrawingEngine* drawingEngine,
58 												Desktop* desktop);
59 	virtual							~WindowLayer();
60 
61 	virtual	void					MessageReceived(BMessage* message);
62 	virtual	bool					QuitRequested();
63 
64 	inline	BRect					Frame() const
65 										{ return fFrame; }
66 			// setting and getting the "hard" clipping
67 			void					SetClipping(BRegion* stillAvailableOnScreen);
68 	inline	BRegion&				VisibleRegion()
69 										{ return fVisibleRegion; }
70 			BRegion&				VisibleContentRegion();
71 
72 			void					GetFullRegion(BRegion* region) const;
73 			void					GetBorderRegion(BRegion* region);
74 			void					GetContentRegion(BRegion* region);
75 
76 			void					SetFocus(bool focus);
77 
78 			void					MoveBy(int32 x, int32 y);
79 			void					ResizeBy(int32 x, int32 y, BRegion* dirtyRegion);
80 
81 			void					ScrollViewBy(ViewLayer* view, int32 dx, int32 dy);
82 
83 			void					AddChild(ViewLayer* layer);
84 
85 			ViewLayer*				ViewAt(const BPoint& where);
86 
87 			void					SetHidden(bool hidden);
88 	inline	bool					IsHidden() const
89 										{ return fHidden; }
90 
91 			void					MarkDirty(BRegion* regionOnScreen);
92 			void					MarkContentDirty(BRegion* regionOnScreen);
93 			void					InvalidateView(int32 token);
94 
95 			void					ProcessDirtyRegion(BRegion* region);
96 
97 			DrawingEngine*			GetDrawingEngine() const
98 										{ return fDrawingEngine; }
99 
100 			void					CopyContents(BRegion* region,
101 												 int32 xOffset, int32 yOffset);
102 
103  private:
104 			void					_ShiftPartOfRegion(BRegion* region, BRegion* regionToShift,
105 													   int32 xOffset, int32 yOffset);
106 
107 			// different types of drawing
108 			void					_TriggerContentRedraw();
109 			void					_DrawClient(int32 token);
110 			void					_DrawClientPolygon(int32 token, BPoint polygon[4]);
111 			void					_DrawBorder();
112 
113 			// handling update sessions
114 			void					_MarkContentDirty(BRegion* contentDirtyRegion);
115 			void					_BeginUpdate();
116 			void					_EndUpdate();
117 
118 			void					_UpdateContentRegion();
119 
120 			BRect					fFrame;
121 
122 			// the visible region is only recalculated from the
123 			// Desktop thread, when using it, Desktop::ReadLockClipping()
124 			// has to be called
125 			BRegion					fVisibleRegion;
126 			BRegion					fVisibleContentRegion;
127 			bool					fVisibleContentRegionValid;
128 			// our part of the "global" dirty region
129 			// it is calculated from the desktop thread,
130 			// but we can write to it when we read locked
131 			// the clipping, since it is local and the desktop
132 			// thread is blocked
133 			BRegion					fDirtyRegion;
134 
135 			// caching local regions
136 			BRegion					fBorderRegion;
137 			bool					fBorderRegionValid;
138 			BRegion					fContentRegion;
139 			bool					fContentRegionValid;
140 			BRegion					fEffectiveDrawingRegion;
141 			bool					fEffectiveDrawingRegionValid;
142 
143 			bool					fFocus;
144 
145 			ViewLayer*				fTopLayer;
146 
147 			bool					fHidden;
148 
149 			DrawingEngine*			fDrawingEngine;
150 			Desktop*				fDesktop;
151 
152 			// for mapping drawing requests from the client
153 			// to the local view pointers
154 			BList					fTokenViewMap;
155 
156 			// the client looper, which will do asynchronous
157 			// drawing (the window will clear the content
158 			// and the client is supposed to draw onto
159 			// the cleared regions)
160 			ClientLooper*			fClient;
161 			// The synchronization, which client drawing commands
162 			// belong to the redraw of which region is handled
163 			// through an UpdateSession. When the client has
164 			// been informed that it should redraw stuff, then
165 			// this is the current update session. All new
166 			// redraw requests from the root layer will go
167 			// into the pending update session.
168 			UpdateSession			fCurrentUpdateSession;
169 			UpdateSession			fPendingUpdateSession;
170 			// these two flags are supposed to ensure a sane
171 			// and consistent update session
172 			bool					fUpdateRequested;
173 			bool					fInUpdate;
174 };
175 
176 #endif // WINDOW_LAYER_H
177