Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
* [android] Add deviation to meta (#1561)
Browse files Browse the repository at this point in the history
  • Loading branch information
miomin authored and YorkShen committed Sep 21, 2018
1 parent f8c851f commit fba00e2
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 13 deletions.
Binary file modified android/sdk/libs/armeabi-v7a/libweexcore.so
Binary file not shown.
Binary file modified android/sdk/libs/armeabi/libweexcore.so
Binary file not shown.
Binary file modified android/sdk/libs/x86/libweexcore.so
Binary file not shown.
30 changes: 22 additions & 8 deletions weex_core/Source/base/ViewUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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;
}

Expand All @@ -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
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions weex_core/Source/core/css/constants_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions weex_core/Source/core/css/constants_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ namespace WeexCore {
constexpr int VERTICAL_VALUE = 1;

constexpr float kDefaultViewPortWidth = 750.0f;
constexpr bool kDefaultRoundOffDeviation = true;
}
#endif //WEEXV8_CONSTANTSVALUE_H
30 changes: 27 additions & 3 deletions weex_core/Source/core/render/manager/render_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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())));
}
}
}
}
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions weex_core/Source/core/render/manager/render_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions weex_core/Source/core/render/node/render_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions weex_core/Source/core/render/page/render_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <utility>
#include <vector>

#include "core/css/constants_value.h"

namespace WeexCore {

class RenderAction;
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down

0 comments on commit fba00e2

Please sign in to comment.