Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Wed, 2 Aug 2017 21:14:02 +0000 (07:14 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 2 Aug 2017 21:14:02 +0000 (07:14 +1000)
14 files changed:
doc/doxygen/Doxyfile
intern/cycles/kernel/kernels/opencl/kernel_split.cl
intern/cycles/util/util_path.cpp
release/datafiles/splash.png
release/datafiles/splash_2x.png
release/scripts/presets/interface_theme/dark_blue_gradient.xml
release/scripts/presets/interface_theme/elsyiun.xml
release/scripts/presets/interface_theme/science_lab.xml
source/blender/blenkernel/intern/unit.c
source/blender/blenlib/BLI_math_base.h
source/blender/blenlib/intern/math_base_inline.c
source/blender/blenloader/intern/versioning_270.c
source/blender/editors/interface/interface.c
tests/python/bl_pyapi_bpy_utils_units.py

index 8b3a97816baa5ac80bb96c22edd3f159a4c9d5ff..a3ccf9227d3d6944797cd1c5767a86298be6865f 100644 (file)
@@ -38,7 +38,7 @@ PROJECT_NAME           = Blender
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER         = "V2.8x"
+PROJECT_NUMBER         = "V2.79"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
index 651addb02f4ff300d3e380082080a8added7468f..4cbda1bc2e764707d38821012f23f4a04a2b414a 100644 (file)
@@ -14,6 +14,9 @@
  * limitations under the License.
  */
 
+#include "kernel/kernel_compat_opencl.h"  // PRECOMPILED
+#include "kernel/split/kernel_split_common.h"  // PRECOMPILED
+
 #include "kernel/kernels/opencl/kernel_state_buffer_size.cl"
 #include "kernel/kernels/opencl/kernel_data_init.cl"
 #include "kernel/kernels/opencl/kernel_path_init.cl"
index f9c3b4bb139b2904a6bb34277ec6a5ff39c71cf1..c2bff61ada7d2ad146e13212db5b342ef1a8cd42 100644 (file)
@@ -45,6 +45,7 @@ OIIO_NAMESPACE_USING
 #  include <shlwapi.h>
 #endif
 
+#include "util/util_map.h"
 #include "util/util_windows.h"
 
 CCL_NAMESPACE_BEGIN
@@ -768,15 +769,35 @@ bool path_remove(const string& path)
        return remove(path.c_str()) == 0;
 }
 
-static string line_directive(const string& base, const string& path, int line)
+struct SourceReplaceState {
+       typedef map<string, string> ProcessedMapping;
+       /* Base director for all relative include headers. */
+       string base;
+       /* Result of processed files. */
+       ProcessedMapping processed_files;
+       /* Set of files which are considered "precompiled" and which are replaced
+        * with and empty string on a subsequent occurrence in include statement.
+        */
+       set<string> precompiled_headers;
+};
+
+static string path_source_replace_includes_recursive(
+        const string& source,
+        const string& source_filepath,
+        SourceReplaceState *state);
+
+static string line_directive(const SourceReplaceState& state,
+                             const string& path,
+                             const int line)
 {
        string escaped_path = path;
        /* First we make path relative. */
-       if(string_startswith(escaped_path, base.c_str())) {
-               const string base_file = path_filename(base);
-               const size_t base_len = base.length();
-               escaped_path = base_file + escaped_path.substr(base_len,
-                                                              escaped_path.length() - base_len);
+       if(string_startswith(escaped_path, state.base.c_str())) {
+               const string base_file = path_filename(state.base);
+               const size_t base_len = state.base.length();
+               escaped_path = base_file +
+                       escaped_path.substr(base_len,
+                                           escaped_path.length() - base_len);
        }
        /* Second, we replace all unsafe characters. */
        string_replace(escaped_path, "\"", "\\\"");
@@ -786,50 +807,106 @@ static string line_directive(const string& base, const string& path, int line)
        return string_printf("#line %d \"%s\"", line, escaped_path.c_str());
 }
 
+static string path_source_handle_preprocessor(
+        const string& preprocessor_line,
+        const string& source_filepath,
+        const size_t line_number,
+        SourceReplaceState *state)
+{
+       string result = preprocessor_line;
+       string token = string_strip(
+               preprocessor_line.substr(1, preprocessor_line.size() - 1));
+       if(string_startswith(token, "include")) {
+               token = string_strip(token.substr(7, token.size() - 7));
+               if(token[0] == '"') {
+                       const size_t n_start = 1;
+                       const size_t n_end = token.find("\"", n_start);
+                       const string filename = token.substr(n_start, n_end - n_start);
+                       const bool is_precompiled = string_endswith(token, "// PRECOMPILED");
+                       string filepath = path_join(state->base, filename);
+                       if(!path_exists(filepath)) {
+                               filepath = path_join(path_dirname(source_filepath),
+                                                    filename);
+                       }
+                       if(is_precompiled) {
+                               state->precompiled_headers.insert(filepath);
+                       }
+                       string text;
+                       if(path_read_text(filepath, text)) {
+                               text = path_source_replace_includes_recursive(
+                                       text, filepath, state);
+                               /* Use line directives for better error messages. */
+                               result = line_directive(*state, filepath, 1) + "\n"
+                                    + text + "\n"
+                                    + line_directive(*state, source_filepath, line_number + 1);
+                       }
+               }
+       }
+       return result;
+}
+
+/* Our own little c preprocessor that replaces #includes with the file
+ * contents, to work around issue of OpenCL drivers not supporting
+ * include paths with spaces in them.
+ */
 static string path_source_replace_includes_recursive(
-        const string& base,
         const string& source,
-        const string& source_filepath)
+        const string& source_filepath,
+        SourceReplaceState *state)
 {
-       /* Our own little c preprocessor that replaces #includes with the file
-        * contents, to work around issue of OpenCL drivers not supporting
-        * include paths with spaces in them.
+       /* Try to re-use processed file without spending time on replacing all
+        * include directives again.
         */
-
+       SourceReplaceState::ProcessedMapping::iterator replaced_file =
+               state->processed_files.find(source_filepath);
+       if(replaced_file != state->processed_files.end()) {
+               if(state->precompiled_headers.find(source_filepath) !=
+                       state->precompiled_headers.end()) {
+                       return "";
+               }
+               return replaced_file->second;
+       }
+       /* Perform full file processing.  */
        string result = "";
-       vector<string> lines;
-       string_split(lines, source, "\n", false);
-
-       for(size_t i = 0; i < lines.size(); ++i) {
-               string line = lines[i];
-               if(line[0] == '#') {
-                       string token = string_strip(line.substr(1, line.size() - 1));
-                       if(string_startswith(token, "include")) {
-                               token = string_strip(token.substr(7, token.size() - 7));
-                               if(token[0] == '"') {
-                                       const size_t n_start = 1;
-                                       const size_t n_end = token.find("\"", n_start);
-                                       const string filename = token.substr(n_start, n_end - n_start);
-                                       string filepath = path_join(base, filename);
-                                       if(!path_exists(filepath)) {
-                                               filepath = path_join(path_dirname(source_filepath),
-                                                                    filename);
-                                       }
-                                       string text;
-                                       if(path_read_text(filepath, text)) {
-                                               text = path_source_replace_includes_recursive(
-                                                       base, text, filepath);
-                                               /* Use line directives for better error messages. */
-                                               line = line_directive(base, filepath, 1)
-                                                    + token.replace(0, n_end + 1, "\n" + text + "\n")
-                                                    + line_directive(base, source_filepath, i + 1);
-                                       }
-                               }
+       const size_t source_length = source.length();
+       size_t index = 0;
+       size_t line_number = 0, column_number = 1;
+       bool inside_preprocessor = false;
+       string preprocessor_line = "";
+       while(index < source_length) {
+               const char ch = source[index];
+               if(ch == '\n') {
+                       if(inside_preprocessor) {
+                               result += path_source_handle_preprocessor(preprocessor_line,
+                                                                         source_filepath,
+                                                                         line_number,
+                                                                         state);
                        }
+                       inside_preprocessor = false;
+                       preprocessor_line = "";
+                       column_number = 0;
+                       ++line_number;
                }
-               result += line + "\n";
+               else if(ch == '#' && column_number == 1) {
+                       inside_preprocessor = true;
+               }
+               if(inside_preprocessor) {
+                       preprocessor_line += ch;
+               }
+               else {
+                       result += ch;
+               }
+               ++index;
+               ++column_number;
        }
-
+       if(inside_preprocessor) {
+               result += path_source_handle_preprocessor(preprocessor_line,
+                                                         source_filepath,
+                                                         line_number,
+                                                         state);
+       }
+       /* Store result for further reuse. */
+       state->processed_files[source_filepath] = result;
        return result;
 }
 
@@ -837,10 +914,12 @@ string path_source_replace_includes(const string& source,
                                     const string& path,
                                     const string& source_filename)
 {
+       SourceReplaceState state;
+       state.base = path;
        return path_source_replace_includes_recursive(
-               path,
                source,
-               path_join(path, source_filename));
+               path_join(path, source_filename),
+               &state);
 }
 
 FILE *path_fopen(const string& path, const string& mode)
index 60956db2576af6de5a1d3989bbce02997cb19f7a..1cd817a8e8ce53fe4dd1bf9d076c94f018152516 100644 (file)
Binary files a/release/datafiles/splash.png and b/release/datafiles/splash.png differ
index 3a5000c6bbcba052a759fe05419d65722258d6f3..2ba54b92cffc82e15bebbbe8ffc1f20d9e01bd6c 100644 (file)
Binary files a/release/datafiles/splash_2x.png and b/release/datafiles/splash_2x.png differ
index d3d0f5bb52204f5a934386813056df59a35a2a21..d226f8531b2b57882d8ad50c05f86362fd99c0f3 100644 (file)
                              inner="#39424bcc"
                              inner_sel="#667686bf"
                              item="#191919ff"
-                             text="#000000"
+                             text="#b8b8b8"
                              text_sel="#ffffff"
                              show_shaded="TRUE"
                              shadetop="25"
index 7a3d5146636895d3a67c3220413353d7b4f01b6b..b9292856fe958748c0992bbd3ccc1eabb52f32e2 100644 (file)
                              inner="#4b4b4bff"
                              inner_sel="#646464ff"
                              item="#191919ff"
-                             text="#000000"
+                             text="#b8b8b8"
                              text_sel="#ffffff"
                              show_shaded="TRUE"
                              shadetop="0"
index 9341e945375bc7775832df46473c93c130695de6..2fe4cf99e41dbad7fd1b42c2468104c483fda753 100644 (file)
                              inner="#303030ff"
                              inner_sel="#678db2ff"
                              item="#191919ff"
-                             text="#272727"
+                             text="#e6f1ff"
                              text_sel="#ffffff"
                              show_shaded="FALSE"
                              shadetop="0"
index f97b89f1fd5a9742c464b426f0d95f932932b8e9..8606da0743b6a71c976ab04aa8431f5084462729 100644 (file)
@@ -375,8 +375,7 @@ static size_t unit_as_string(char *str, int len_max, double value, int prec, con
        /* Adjust precision to expected number of significant digits.
         * Note that here, we shall not have to worry about very big/small numbers, units are expected to replace
         * 'scientific notation' in those cases. */
-       const int l10 = (value_conv == 0.0) ? 0 : (int)log10(fabs(value_conv));
-       prec -= l10 + (int)(l10 < 0);
+       prec -= integer_digits_d(value_conv);
        CLAMP(prec, 0, 6);
 
        /* Convert to a string */
@@ -449,12 +448,15 @@ size_t bUnit_AsString(char *str, int len_max, double value, int prec, int system
                        size_t i;
                        i = unit_as_string(str, len_max, value_a, prec, usys, unit_a, '\0');
 
+                       prec -= integer_digits_d(value_a / unit_b->scalar) - integer_digits_d(value_b / unit_b->scalar);
+                       prec = max_ii(prec, 0);
+
                        /* is there enough space for at least 1 char of the next unit? */
                        if (i + 2 < len_max) {
                                str[i++] = ' ';
 
                                /* use low precision since this is a smaller unit */
-                               i += unit_as_string(str + i, len_max - i, value_b, prec ? 1 : 0, usys, unit_b, '\0');
+                               i += unit_as_string(str + i, len_max - i, value_b, prec, usys, unit_b, '\0');
                        }
                        return i;
                }
index 0126e30d90040817ca993714f9c202f5f942c71c..c44b666faead4523a92d56b56b3905910af4d32a 100644 (file)
@@ -138,6 +138,9 @@ MINLINE int signum_i(float a);
 
 MINLINE float power_of_2(float f);
 
+MINLINE int integer_digits_f(const float f);
+MINLINE int integer_digits_d(const double d);
+
 /* these don't really fit anywhere but were being copied about a lot */
 MINLINE int is_power_of_2_i(int n);
 MINLINE int power_of_2_max_i(int n);
index 8d2d80c2a35ae60f5f86add84cdd419da552950a..6574c001a2344ccace7024d2c6b8059ec568cf37 100644 (file)
@@ -314,6 +314,21 @@ MINLINE int signum_i(float a)
        else          return  0;
 }
 
+/** Returns number of (base ten) *significant* digits of integer part of given float
+ * (negative in case of decimal-only floats, 0.01 returns -1 e.g.). */
+MINLINE int integer_digits_f(const float f)
+{
+       return (f == 0.0f) ? 0 : (int)floor(log10(fabs(f))) + 1;
+}
+
+/** Returns number of (base ten) *significant* digits of integer part of given double
+ * (negative in case of decimal-only floats, 0.01 returns -1 e.g.). */
+MINLINE int integer_digits_d(const double d)
+{
+       return (d == 0.0) ? 0 : (int)floor(log10(fabs(d))) + 1;
+}
+
+
 /* Internal helpers for SSE2 implementation.
  *
  * NOTE: Are to be called ONLY from inside `#ifdef __SSE2__` !!!
index cb7c46d24f3ec8157a2802f2c2e5f4e1822628e0..cabb1409603aa1302ae9085560e8524b67cf2aa5 100644 (file)
@@ -1659,7 +1659,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
                } FOREACH_NODETREE_END
        }
 
-       {
+       if (!MAIN_VERSION_ATLEAST(main, 279, 0)) {
                for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
                        if (scene->r.im_format.exr_codec == R_IMF_EXR_CODEC_DWAB) {
                                scene->r.im_format.exr_codec = R_IMF_EXR_CODEC_DWAA;
@@ -1697,7 +1697,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 void do_versions_after_linking_270(Main *main)
 {
        /* To be added to next subversion bump! */
-       {
+       if (!MAIN_VERSION_ATLEAST(main, 279, 0)) {
                FOREACH_NODETREE(main, ntree, id) {
                        if (ntree->type == NTREE_COMPOSIT) {
                                ntreeSetTypes(NULL, ntree);
index 656cd01381456a8b26f9252826bb6e4c5a5b0f86..bea59649440fb384dfbf1d88bd562c4e313bc4a7 100644 (file)
@@ -2226,20 +2226,24 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int
                        else {
                                int prec = (float_precision == -1) ? ui_but_calc_float_precision(but, value) : float_precision;
                                if (use_exp_float) {
-                                       const int l10 = (value == 0.0f) ? 0 : (int)log10(fabs(value));
-                                       if (l10 < -6 || l10 > 12) {
+                                       const int int_digits_num = integer_digits_f(value);
+                                       if (int_digits_num < -6 || int_digits_num > 12) {
                                                BLI_snprintf(str, maxlen, "%.*g", prec, value);
                                                if (r_use_exp_float) {
                                                        *r_use_exp_float = true;
                                                }
                                        }
                                        else {
-                                               prec -= l10 + (int)(l10 < 0);
+                                               prec -= int_digits_num;
                                                CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX);
                                                BLI_snprintf(str, maxlen, "%.*f", prec, value);
                                        }
                                }
                                else {
+#if 0                          /* TODO, but will likely break some stuff, so better after 2.79 release. */
+                                       prec -= int_digits_num;
+                                       CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX);
+#endif
                                        BLI_snprintf(str, maxlen, "%.*f", prec, value);
                                }
                        }
index f40dab4b5ebcf08b4c85308b5974c3feb399d026..251419cb9ef264408da3cdc10884d147ac9349dc 100644 (file)
@@ -32,18 +32,17 @@ class UnitsTesting(unittest.TestCase):
     OUTPUT_TESTS = (
         # system,    type,    prec, sep, compat, value, output
         ##### LENGTH
+        # Note: precision handling is a bit complicated when using multi-units...
         ('IMPERIAL', 'LENGTH', 3, False, False, 0.3048, "1'"),
         ('IMPERIAL', 'LENGTH', 3, False, True,  0.3048, "1ft"),
-        ('IMPERIAL', 'LENGTH', 3, True,  False, 0.3048 * 2 + 0.0254 * 5.5, "2' 5.5\""),
-        # Those next two fail, here again because precision ignores order magnitude :/
-        #('IMPERIAL', 'LENGTH', 3, False, False, 1609.344 * 1e6, "1000000mi"), # == 1000000.004mi!!!
-        #('IMPERIAL', 'LENGTH', 6, False, False, 1609.344 * 1e6, "1000000mi"), # == 1000000.003641mi!!!
-        ('METRIC',   'LENGTH', 3, True,  False, 1000 * 2 + 0.001 * 15, "2km 1.5cm"),
-        ('METRIC',   'LENGTH', 3, True,  False, 1234.56789, "1km 234.6m"),
-        # Note: precision seems basically unused when using multi units!
-        ('METRIC',   'LENGTH', 9, True,  False, 1234.56789, "1km 234.6m"),
-        ('METRIC',   'LENGTH', 9, False, False, 1234.56789, "1.23456789km"),
-        ('METRIC',   'LENGTH', 9, True,  False, 1000.000123456789, "1km 0.1mm"),
+        ('IMPERIAL', 'LENGTH', 4, True,  False, 0.3048 * 2 + 0.0254 * 5.5, "2' 5.5\""),
+        ('IMPERIAL', 'LENGTH', 3, False, False, 1609.344 * 1e6, "1000000mi"),
+        ('IMPERIAL', 'LENGTH', 6, False, False, 1609.344 * 1e6, "1000000mi"),
+        ('METRIC',   'LENGTH', 3, True,  False, 1000 * 2 + 0.001 * 15, "2km 2cm"),
+        ('METRIC',   'LENGTH', 5, True,  False, 1234.56789, "1km 234.6m"),
+        ('METRIC',   'LENGTH', 6, True,  False, 1234.56789, "1km 234.57m"),
+        ('METRIC',   'LENGTH', 9, False, False, 1234.56789, "1.234568km"),
+        ('METRIC',   'LENGTH', 9, True,  False, 1000.000123456789, "1km 0.123mm"),
     )
 
     def test_units_inputs(self):