1 //------------------------------------------------------------------------------
2 // emViewRenderer.h
3 //
4 // Copyright (C) 2016-2017 Oliver Hamann.
5 //
6 // Homepage: http://eaglemode.sourceforge.net/
7 //
8 // This program is free software: you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License version 3 as published by the
10 // Free Software Foundation.
11 //
12 // This program is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
15 // more details.
16 //
17 // You should have received a copy of the GNU General Public License version 3
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //------------------------------------------------------------------------------
20 
21 #ifndef emViewRenderer_h
22 #define emViewRenderer_h
23 
24 #ifndef emClipRects_h
25 #include <emCore/emClipRects.h>
26 #endif
27 
28 #ifndef emRenderThreadPool_h
29 #include <emCore/emRenderThreadPool.h>
30 #endif
31 
32 #ifndef emView_h
33 #include <emCore/emView.h>
34 #endif
35 
36 
37 //==============================================================================
38 //=============================== emViewRenderer ===============================
39 //==============================================================================
40 
41 class emViewRenderer : public emUncopyable {
42 
43 public:
44 
45 	// Helper class for rendering views by multiple threads concurrently.
46 	// This uses emRenderThreadPool.
47 
48 	emViewRenderer(emRootContext & rootContext);
49 	virtual ~emViewRenderer();
50 
51 	void RenderView(
52 		const emViewPort & viewPort,
53 		const emClipRects<int> & invalidRects
54 	);
55 		// Render a view.
56 		// Arguments:
57 		//   viewPort     - The view port of the view.
58 		//   invalidRects - Which parts of the view are to be rendered, in
59 		//                  screen coordinates.
60 
61 protected:
62 
63 	virtual void PrepareBuffers(
64 		int bufCount, int maxWidth, int maxHeight
65 	) = 0;
66 		// Prepare image buffers for rendering. Called rarely.
67 		// Arguments:
68 		//   bufCount  - Number of buffers.
69 		//   maxWidth  - Maximum used width of the buffer, in pixels.
70 		//   maxHeight - Maximum used height of the buffer, in pixels.
71 
72 	virtual emPainter GetBufferPainter(
73 		int bufIndex, int x, int y, int w, int h
74 	) = 0;
75 		// Get a painter for painting to a buffer.
76 		// Arguments:
77 		//   bufIndex  - Buffer index.
78 		//   x,y,w,h   - Rectangle on the screen to be updated.
79 		//               w and h are never larger than said with
80 		//               PrepareBuffers(...).
81 
82 	virtual void AsyncFlushBuffer(
83 		int bufIndex, int x, int y, int w, int h
84 	) = 0;
85 		// Flush a buffer to the screen. This has to be thread-safe.
86 		// The Arguments:
87 		//   bufIndex  - Buffer index.
88 		//   x,y,w,h   - Rectangle on the screen to be updated (same
89 		//               as in call to GetBufferPainter(...) before).
90 
91 private:
92 
93 	struct TodoRect {
94 		int x,y,w,h;
95 	};
96 
97 	static void ThreadFunc(void * data, int bufIndex);
98 	void ThreadRun(int bufIndex);
99 
100 	emRef<emRenderThreadPool> ThreadPool;
101 	int BufCount;
102 	int BufWidth;
103 	int BufHeight;
104 	const emViewPort * CurrentViewPort;
105 	emThreadMiniMutex UserSpaceMutex;
106 	emArray<TodoRect> TodoRects;
107 	int TrIndex;
108 };
109 
110 
111 #endif
112