xref: /haiku/src/apps/mandelbrot/FractalEngine.h (revision 151343ebc86cf0ce61a6c7789f853dff35c57e9c)
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_RESIZE,
29 		MSG_BUFFER_CREATED,
30 		MSG_RENDER,
31 		MSG_RENDER_COMPLETE,
32 		MSG_THREAD_RENDER_COMPLETE,
33 	};
34 
35 	FractalEngine(BHandler* parent, BLooper* looper);
36 	~FractalEngine();
37 
38 	virtual void MessageReceived(BMessage* msg);
39 	void WriteToBitmap(BBitmap*);
40 
41 private:
42 	uint16 fWidth;
43 	uint16 fHeight;
44 
45 	uint8* fRenderBuffer;
46 	uint32 fRenderBufferLen;
47 
48 	BMessenger fMessenger;
49 
50 	uint8 fThreadCount;
51 	thread_id fRenderThreads[MAX_RENDER_THREADS];
52 	sem_id fRenderSem;
53 	sem_id fRenderStoppedSem;
54 
55 	bool fStopRender;
56 	bool fRenderStopped;
57 
58 	double fLocationX;
59 	double fLocationY;
60 	double fSize;
61 
62 	uint16 fIterations;
63 
64 	const uint8* fColorset;
65 
66 	int32 (FractalEngine::*fDoSet)(double real, double imaginary);
67 
68 	void Render(double locationX, double locationY, double size);
69 	void StopRender();
70 	static status_t RenderThread(void* data);
71 	void RenderPixel(uint32 x, uint32 y);
72 
73 	int32 DoSet_Mandelbrot(double real, double imaginary);
74 	int32 DoSet_BurningShip(double real, double imaginary);
75 	int32 DoSet_Tricorn(double real, double imaginary);
76 	int32 DoSet_Julia(double real, double imaginary);
77 	int32 DoSet_OrbitTrap(double real, double imaginary);
78 	int32 DoSet_Multibrot(double real, double imaginary);
79 };
80 
81 
82 #endif	/* FRACTALENGINE_H */
83