xref: /haiku/src/apps/mandelbrot/FractalEngine.h (revision e705c841d784f0035a0ef3e9e96f6e017df16681)
1 /*
2  * Copyright 2016, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Augustin Cavalier <waddlesplash>
7  *		kerwizzy
8  */
9 #ifndef FRACTALENGINE_H
10 #define FRACTALENGINE_H
11 
12 #include <SupportDefs.h>
13 #include <Looper.h>
14 #include <Messenger.h>
15 
16 class BBitmap;
17 
18 
19 #define MAX_RENDER_THREADS 16
20 
21 
22 class FractalEngine : public BLooper {
23 public:
24 	enum {
25 		MSG_CHANGE_SET = 'Frct',
26 		MSG_SET_PALETTE,
27 		MSG_SET_ITERATIONS,
28 		MSG_SET_SUBSAMPLING,
29 		MSG_RESIZE,
30 		MSG_BUFFER_CREATED,
31 		MSG_RENDER,
32 		MSG_RENDER_COMPLETE,
33 		MSG_THREAD_RENDER_COMPLETE,
34 	};
35 
36 	FractalEngine(BHandler* parent, BLooper* looper);
37 	~FractalEngine();
38 
39 	virtual void MessageReceived(BMessage* msg);
40 	void WriteToBitmap(BBitmap*);
41 
42 private:
43 	uint16 fWidth;
44 	uint16 fHeight;
45 
46 	uint8* fRenderBuffer;
47 	uint32 fRenderBufferLen;
48 
49 	uint8 fSubsampling;
50 		// 1 disables subsampling.
51 
52 	BMessenger fMessenger;
53 
54 	uint8 fThreadCount;
55 	thread_id fRenderThreads[MAX_RENDER_THREADS];
56 	sem_id fRenderSem;
57 	sem_id fRenderStoppedSem;
58 
59 	bool fStopRender;
60 	bool fRenderStopped;
61 
62 	double fLocationX;
63 	double fLocationY;
64 	double fSize;
65 
66 	uint16 fIterations;
67 
68 	const uint8* fColorset;
69 
70 	int32 (FractalEngine::*fDoSet)(double real, double imaginary);
71 
72 	void Render(double locationX, double locationY, double size);
73 	void StopRender();
74 	static status_t RenderThread(void* data);
75 	void RenderPixel(uint32 x, uint32 y);
76 
77 	int32 DoSet_Mandelbrot(double real, double imaginary);
78 	int32 DoSet_BurningShip(double real, double imaginary);
79 	int32 DoSet_Tricorn(double real, double imaginary);
80 	int32 DoSet_Julia(double real, double imaginary);
81 	int32 DoSet_OrbitTrap(double real, double imaginary);
82 	int32 DoSet_Multibrot(double real, double imaginary);
83 };
84 
85 
86 #endif	/* FRACTALENGINE_H */
87