Cycles: Code cleanup, spaces around keywords
[blender-staging.git] / intern / cycles / device / device_task.cpp
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include "device_task.h"
21
22 #include "util_algorithm.h"
23 #include "util_time.h"
24
25 CCL_NAMESPACE_BEGIN
26
27 /* Device Task */
28
29 DeviceTask::DeviceTask(Type type_)
30 : type(type_), x(0), y(0), w(0), h(0), rgba_byte(0), rgba_half(0), buffer(0),
31   sample(0), num_samples(1),
32   shader_input(0), shader_output(0),
33   shader_eval_type(0), shader_x(0), shader_w(0)
34 {
35         last_update_time = time_dt();
36 }
37
38 int DeviceTask::get_subtask_count(int num, int max_size)
39 {
40         if(max_size != 0) {
41                 int max_size_num;
42
43                 if(type == SHADER) {
44                         max_size_num = (shader_w + max_size - 1)/max_size;
45                 }
46                 else {
47                         max_size = max(1, max_size/w);
48                         max_size_num = (h + max_size - 1)/max_size;
49                 }
50
51                 num = max(max_size_num, num);
52         }
53
54         if(type == SHADER) {
55                 num = min(shader_w, num);
56         }
57         else if(type == PATH_TRACE) {
58         }
59         else {
60                 num = min(h, num);
61         }
62
63         return num;
64 }
65
66 void DeviceTask::split(list<DeviceTask>& tasks, int num, int max_size)
67 {
68         num = get_subtask_count(num, max_size);
69
70         if(type == SHADER) {
71                 for(int i = 0; i < num; i++) {
72                         int tx = shader_x + (shader_w/num)*i;
73                         int tw = (i == num-1)? shader_w - i*(shader_w/num): shader_w/num;
74
75                         DeviceTask task = *this;
76
77                         task.shader_x = tx;
78                         task.shader_w = tw;
79
80                         tasks.push_back(task);
81                 }
82         }
83         else if(type == PATH_TRACE) {
84                 for(int i = 0; i < num; i++)
85                         tasks.push_back(*this);
86         }
87         else {
88                 for(int i = 0; i < num; i++) {
89                         int ty = y + (h/num)*i;
90                         int th = (i == num-1)? h - i*(h/num): h/num;
91
92                         DeviceTask task = *this;
93
94                         task.y = ty;
95                         task.h = th;
96
97                         tasks.push_back(task);
98                 }
99         }
100 }
101
102 void DeviceTask::update_progress(RenderTile *rtile)
103 {
104         if((type != PATH_TRACE) &&
105            (type != SHADER))
106                 return;
107
108         if(update_progress_sample)
109                 update_progress_sample();
110
111         if(update_tile_sample) {
112                 double current_time = time_dt();
113
114                 if(current_time - last_update_time >= 1.0) {
115                         update_tile_sample(*rtile);
116
117                         last_update_time = current_time;
118                 }
119         }
120 }
121
122 CCL_NAMESPACE_END
123