You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@weex.apache.org by GitBox <gi...@apache.org> on 2018/09/21 12:05:53 UTC

[GitHub] YorkShen closed pull request #1561: * [android] Add deviation to meta

YorkShen closed pull request #1561: * [android] Add deviation to meta
URL: https://github.com/apache/incubator-weex/pull/1561
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/android/sdk/libs/armeabi-v7a/libweexcore.so b/android/sdk/libs/armeabi-v7a/libweexcore.so
index dc233b8ffa..b6962f546a 100644
Binary files a/android/sdk/libs/armeabi-v7a/libweexcore.so and b/android/sdk/libs/armeabi-v7a/libweexcore.so differ
diff --git a/android/sdk/libs/armeabi/libweexcore.so b/android/sdk/libs/armeabi/libweexcore.so
index afcf2e0adc..bbf824d783 100644
Binary files a/android/sdk/libs/armeabi/libweexcore.so and b/android/sdk/libs/armeabi/libweexcore.so differ
diff --git a/android/sdk/libs/x86/libweexcore.so b/android/sdk/libs/x86/libweexcore.so
index 99de85a55d..610049644e 100644
Binary files a/android/sdk/libs/x86/libweexcore.so and b/android/sdk/libs/x86/libweexcore.so differ
diff --git a/weex_core/Source/base/ViewUtils.h b/weex_core/Source/base/ViewUtils.h
index 034f81cc18..ec8866c24c 100644
--- a/weex_core/Source/base/ViewUtils.h
+++ b/weex_core/Source/base/ViewUtils.h
@@ -58,7 +58,7 @@ namespace WeexCore {
     return ret;
   }
 
-  inline float getFloat(const float &src, const float &viewport) {
+  inline float getFloat(const float &src, const float &viewport, const bool &round_off_deviation) {
     if (isnan(src))
       return NAN;
 
@@ -67,12 +67,26 @@ namespace WeexCore {
 #if OS_IOS
     return realPx;
 #else
-    float result = realPx > 0.005 && realPx < 1 ? 1.0f : realPx;
+
+    float result;
+    if (round_off_deviation) {
+      result = realPx > 0.005 && realPx < 1 ? 1.0f : realPx;
+    } else {
+      result = realPx > 0.005 && realPx < 1 ? 1.0f : rint(realPx);
+    }
     return result;
 #endif
   }
 
-  inline float getFloat(const std::string &src, const float &viewport) {
+  inline bool getBool(const std::string &src) {
+    if (strcmp(src.c_str(), "true") == 0) {
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+  inline float getFloat(const std::string &src, const float &viewport, const bool &round_off_deviation) {
     float ret = NAN;
     if (UNDEFINE == src
         || AUTO_UNIT == src
@@ -81,7 +95,7 @@ namespace WeexCore {
       return ret;
     }
     float original_value = getFloat(src.c_str());
-    ret = getFloat(original_value, viewport);
+    ret = getFloat(original_value, viewport, round_off_deviation);
     return ret;
   }
 
@@ -100,7 +114,7 @@ namespace WeexCore {
     return density * f * viewport / WXCoreEnvironment::getInstance()->DeviceWidth();
   }
 
-  inline static float getFloatByViewport(std::string src, const float &viewport) {
+  inline static float getFloatByViewport(std::string src, const float &viewport, const bool &round_off_deviation) {
     float ret = NAN;
     if (UNDEFINE == src
         || AUTO_UNIT == src
@@ -110,11 +124,11 @@ namespace WeexCore {
     }
     Trim(src);
     if (endWidth(src, WX)) {
-      ret = getFloat(transferWx(src, viewport), viewport);
+      ret = getFloat(transferWx(src, viewport), viewport, round_off_deviation);
     } else if (endWidth(src, PX)) {
-      ret = getFloat(src.substr(0, src.size() - PX.size()), viewport);
+      ret = getFloat(src.substr(0, src.size() - PX.size()), viewport, round_off_deviation);
     } else {
-      ret = getFloat(src, viewport);
+      ret = getFloat(src, viewport, round_off_deviation);
     }
     return ret;
   }
diff --git a/weex_core/Source/core/css/constants_name.h b/weex_core/Source/core/css/constants_name.h
index 15ec758d8c..48b8a5910d 100644
--- a/weex_core/Source/core/css/constants_name.h
+++ b/weex_core/Source/core/css/constants_name.h
@@ -42,6 +42,7 @@ namespace WeexCore {
 
   constexpr char DEFAULT_WIDTH[] = "defaultWidth";
   constexpr char WIDTH[] = "width";
+  constexpr char ROUND_OFF_DEVIATION[] = "roundOffDeviation";
   constexpr char SCROLL_DIRECTION[] = "scrollDirection";
 
   constexpr char POSITION[] = "position";
diff --git a/weex_core/Source/core/css/constants_value.h b/weex_core/Source/core/css/constants_value.h
index 0af7d00c0c..d51ebb52ef 100644
--- a/weex_core/Source/core/css/constants_value.h
+++ b/weex_core/Source/core/css/constants_value.h
@@ -59,5 +59,6 @@ namespace WeexCore {
   constexpr int VERTICAL_VALUE = 1;
 
   constexpr float kDefaultViewPortWidth = 750.0f;
+  constexpr bool kDefaultRoundOffDeviation = true;
 }
 #endif //WEEXV8_CONSTANTSVALUE_H
diff --git a/weex_core/Source/core/render/manager/render_manager.cpp b/weex_core/Source/core/render/manager/render_manager.cpp
index 49403b8969..c6a3e6c238 100644
--- a/weex_core/Source/core/render/manager/render_manager.cpp
+++ b/weex_core/Source/core/render/manager/render_manager.cpp
@@ -47,13 +47,20 @@ bool RenderManager::CreatePage(const std::string& page_id, const char *data) {
   RenderPage *page = new RenderPage(page_id);
   pages_.insert(std::pair<std::string, RenderPage *>(page_id, page));
 
-  std::map<std::string, float>::iterator iter =
+  std::map<std::string, float>::iterator iter_viewport =
       this->viewports_.find(page_id);
-  if (iter != this->viewports_.end()) {
-    this->set_viewport_width(page_id, iter->second);
+  if (iter_viewport != this->viewports_.end()) {
+    this->set_viewport_width(page_id, iter_viewport->second);
     this->viewports_.erase(page_id);
   }
 
+  std::map<std::string, bool>::iterator iter_deviation =
+      this->round_off_deviations_.find(page_id);
+  if (iter_deviation != this->round_off_deviations_.end()) {
+    this->set_round_off_deviation(page_id, iter_deviation->second);
+    this->round_off_deviations_.erase(page_id);
+  }
+
   int64_t start_time = getCurrentTime();
   RenderObject *root = Wson2RenderObject(data, page_id);
   page->ParseJsonTime(getCurrentTime() - start_time);
@@ -328,6 +335,9 @@ void RenderManager::CallMetaModule(const char *page_id, const char *method, cons
             if (strcmp(key.c_str(), WIDTH) == 0) {
               viewports_.insert(std::pair<std::string, float>(page_id, getFloat(value.c_str())));
             }
+            if (strcmp(key.c_str(), ROUND_OFF_DEVIATION) == 0) {
+              round_off_deviations_.insert(std::pair<std::string, bool>(page_id, getBool(value.c_str())));
+            }
           }
         }
       }
@@ -373,6 +383,20 @@ void RenderManager::set_viewport_width(const std::string &page_id, float viewpor
   page->set_viewport_width(viewport_width);
 }
 
+bool RenderManager::round_off_deviation(const std::string &page_id) {
+  RenderPage *page = GetPage(page_id);
+  if (page == nullptr) return kDefaultRoundOffDeviation;
+
+  return page->round_off_deviation();
+}
+
+void RenderManager::set_round_off_deviation(const std::string &page_id, bool round_off_deviation) {
+  RenderPage *page = GetPage(page_id);
+  if (page == nullptr) return;
+
+  page->set_round_off_deviation(round_off_deviation);
+}
+
 void RenderManager::Batch(const std::string &page_id) {
   RenderPage *page = this->GetPage(page_id);
   if (page == nullptr) return;
diff --git a/weex_core/Source/core/render/manager/render_manager.h b/weex_core/Source/core/render/manager/render_manager.h
index 0507886473..a46229612a 100644
--- a/weex_core/Source/core/render/manager/render_manager.h
+++ b/weex_core/Source/core/render/manager/render_manager.h
@@ -108,6 +108,10 @@ class RenderManager {
 
   void set_viewport_width(const std::string &page_id, float viewport_width);
 
+  bool round_off_deviation(const std::string &page_id);
+
+  void set_round_off_deviation(const std::string &page_id, bool round_off_deviation);
+
   static RenderManager *GetInstance() {
     if (NULL == g_pInstance) {
       g_pInstance = new RenderManager();
@@ -118,6 +122,7 @@ class RenderManager {
   static RenderManager *g_pInstance;
   std::map<std::string, RenderPage *> pages_;
   std::map<std::string, float> viewports_;
+  std::map<std::string, bool> round_off_deviations_;
 };
 }  // namespace WeexCore
 
diff --git a/weex_core/Source/core/render/node/render_object.cpp b/weex_core/Source/core/render/node/render_object.cpp
index 8a3bd109b1..78bf936b05 100644
--- a/weex_core/Source/core/render/node/render_object.cpp
+++ b/weex_core/Source/core/render/node/render_object.cpp
@@ -358,8 +358,9 @@ bool RenderObject::UpdateStyleInternal(const std::string key,
     functor(fallback);
     ret = true;
   } else {
-    float fvalue = getFloatByViewport(
-        value, RenderManager::GetInstance()->viewport_width(page_id()));
+    float fvalue = getFloatByViewport(value,
+                                      RenderManager::GetInstance()->viewport_width(page_id()),
+                                      RenderManager::GetInstance()->round_off_deviation(page_id()));
     if (!isnan(fvalue)) {
       functor(fvalue);
       ret = true;
diff --git a/weex_core/Source/core/render/page/render_page.h b/weex_core/Source/core/render/page/render_page.h
index 46cbd77618..57687cb285 100644
--- a/weex_core/Source/core/render/page/render_page.h
+++ b/weex_core/Source/core/render/page/render_page.h
@@ -26,6 +26,8 @@
 #include <utility>
 #include <vector>
 
+#include "core/css/constants_value.h"
+
 namespace WeexCore {
 
 class RenderAction;
@@ -169,8 +171,14 @@ class RenderPage {
     this->viewport_width_ = viewport_width;
   }
 
+  inline bool round_off_deviation() const { return this->round_off_deviation_; }
+
+  inline void set_round_off_deviation(float round_off_deviation) { this->round_off_deviation_ = round_off_deviation; }
+
   inline void set_before_layout_needed(bool v) { is_before_layout_needed_.store(v); }
+
   inline void set_platform_layout_needed(bool v) { is_platform_layout_needed_.store(v); }
+
   inline void set_after_layout_needed(bool v) { is_after_layout_needed_.store(v); }
 
  public:
@@ -191,6 +199,7 @@ class RenderPage {
   std::atomic_bool is_platform_layout_needed_{false};
   std::atomic_bool is_after_layout_needed_{true};
   float viewport_width_ = -1;
+  bool round_off_deviation_ = kDefaultRoundOffDeviation;
 };
 }  // namespace WeexCore
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services