90616f011ea3af64d6e90f621a1717ce76539004
[blender-staging.git] / intern / cycles / render / session.h
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 #ifndef __SESSION_H__
20 #define __SESSION_H__
21
22 #include "buffers.h"
23 #include "device.h"
24 #include "tile.h"
25
26 #include "util_progress.h"
27 #include "util_thread.h"
28
29 CCL_NAMESPACE_BEGIN
30
31 class BufferParams;
32 class Device;
33 class DeviceScene;
34 class DisplayBuffer;
35 class Progress;
36 class RenderBuffers;
37 class Scene;
38
39 /* Session Parameters */
40
41 class SessionParams {
42 public:
43         DeviceInfo device;
44         bool background;
45         string output_path;
46
47         bool progressive;
48         bool experimental;
49         int samples;
50         int tile_size;
51         int min_size;
52         int threads;
53
54         double cancel_timeout;
55         double reset_timeout;
56         double text_timeout;
57
58         SessionParams()
59         {
60                 background = false;
61                 output_path = "";
62
63                 progressive = false;
64                 experimental = false;
65                 samples = INT_MAX;
66                 tile_size = 64;
67                 min_size = 64;
68                 threads = 0;
69
70                 cancel_timeout = 0.1;
71                 reset_timeout = 0.1;
72                 text_timeout = 1.0;
73         }
74
75         bool modified(const SessionParams& params)
76         { return !(device.type == params.device.type
77                 && device.id == params.device.id
78                 && background == params.background
79                 && output_path == params.output_path
80                 /* && samples == params.samples */
81                 && progressive == params.progressive
82                 && experimental == params.experimental
83                 && tile_size == params.tile_size
84                 && min_size == params.min_size
85                 && threads == params.threads
86                 && cancel_timeout == params.cancel_timeout
87                 && reset_timeout == params.reset_timeout
88                 && text_timeout == params.text_timeout); }
89
90 };
91
92 /* Session
93  *
94  * This is the class that contains the session thread, running the render
95  * control loop and dispatching tasks. */
96
97 class Session {
98 public:
99         Device *device;
100         Scene *scene;
101         RenderBuffers *buffers;
102         DisplayBuffer *display;
103         Progress progress;
104         SessionParams params;
105         int sample;
106
107         Session(const SessionParams& params);
108         ~Session();
109
110         void start();
111         bool draw(BufferParams& params);
112         void wait();
113
114         bool ready_to_reset();
115         void reset(BufferParams& params, int samples);
116         void set_samples(int samples);
117         void set_pause(bool pause);
118
119 protected:
120         struct DelayedReset {
121                 thread_mutex mutex;
122                 bool do_reset;
123                 BufferParams params;
124                 int samples;
125         } delayed_reset;
126
127         void run();
128
129         void update_scene();
130         void update_status_time(bool show_pause = false, bool show_done = false);
131
132         void tonemap();
133         void path_trace(Tile& tile);
134         void reset_(BufferParams& params, int samples);
135
136         void run_cpu();
137         bool draw_cpu(BufferParams& params);
138         void reset_cpu(BufferParams& params, int samples);
139
140         void run_gpu();
141         bool draw_gpu(BufferParams& params);
142         void reset_gpu(BufferParams& params, int samples);
143
144         TileManager tile_manager;
145         bool device_use_gl;
146
147         thread *session_thread;
148
149         volatile bool display_outdated;
150
151         volatile bool gpu_draw_ready;
152         volatile bool gpu_need_tonemap;
153         thread_condition_variable gpu_need_tonemap_cond;
154
155         bool pause;
156         thread_condition_variable pause_cond;
157         thread_mutex pause_mutex;
158
159         bool kernels_loaded;
160
161         double start_time;
162         double reset_time;
163         double preview_time;
164         double paused_time;
165 };
166
167 CCL_NAMESPACE_END
168
169 #endif /* __SESSION_H__ */
170