xref: /haiku/src/apps/mandelbrot/FractalEngine.h (revision 05fc1277c47440dc36134816d70e5723c99cfcd2)
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 class FractalEngine : public BLooper {
20 public:
21 	enum {
22 		MSG_CHANGE_SET = 'Frct',
23 		MSG_SET_PALETTE,
24 		MSG_SET_ITERATIONS,
25 		MSG_RESIZE,
26 		MSG_RENDER,
27 		MSG_RENDER_COMPLETE,
28 	};
29 
30 	FractalEngine(BHandler* parent, BLooper* looper);
31 	~FractalEngine();
32 
33 	virtual void MessageReceived(BMessage* msg);
34 
35 private:
36 	BMessenger fMessenger;
37 	BBitmap* fBitmapStandby;
38 	BBitmap* fBitmapDisplay;
39 
40 	uint8 fThreadCount;
41 	thread_id fRenderThreads[4];
42 	sem_id fRenderSem;
43 	sem_id fRenderFinishedSem;
44 
45 	double fLocationX;
46 	double fLocationY;
47 	double fSize;
48 
49 	uint16 fIterations;
50 	uint16 fWidth;
51 	uint16 fHeight;
52 
53 	uint8* fRenderBuffer;
54 	uint32 fRenderBufferLen;
55 
56 	const uint8* fColorset;
57 
58 	int32 (FractalEngine::*fDoSet)(double real, double imaginary);
59 
60 	void Render(double locationX, double locationY, double size);
61 	static status_t RenderThread(void* data);
62 	void RenderPixel(uint32 x, uint32 y, double real, double imaginary);
63 
64 	int32 DoSet_Mandelbrot(double real, double imaginary);
65 	int32 DoSet_BurningShip(double real, double imaginary);
66 	int32 DoSet_Tricorn(double real, double imaginary);
67 	int32 DoSet_Julia(double real, double imaginary);
68 	int32 DoSet_OrbitTrap(double real, double imaginary);
69 	int32 DoSet_Multibrot(double real, double imaginary);
70 };
71 
72 
73 #endif	/* FRACTALENGINE_H */
74