Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dom/include/dom/root_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ struct ListenerOp {
}
};

enum VSyncEventNeedSource {
VSyncEventNeedByAnimation = 1,
VSyncEventNeedByFrame = 1<<1
};

class RootNode : public DomNode {
public:
using TaskRunner = footstone::runner::TaskRunner;
Expand Down Expand Up @@ -119,6 +124,10 @@ class RootNode : public DomNode {
std::vector<std::weak_ptr<DomNode>> GetAllTextNodes();

LayoutEngineType GetLayoutEngineType() { return layout_engine_type_; }

void SetVSyncEventNeedSource(VSyncEventNeedSource source) { vSyncEventNeedSourceBits_ |= source; }
void UnsetVSyncEventNeedSource(VSyncEventNeedSource source) { vSyncEventNeedSourceBits_ &= (~source); }
bool HasVSyncEventNeedSource() { return vSyncEventNeedSourceBits_ != 0; }

private:
static void MarkLayoutNodeDirty(const std::vector<std::shared_ptr<DomNode>>& nodes);
Expand Down Expand Up @@ -153,6 +162,8 @@ class RootNode : public DomNode {
bool disable_set_root_size_ { false };

LayoutEngineType layout_engine_type_ = LayoutEngineDefault;

int32_t vSyncEventNeedSourceBits_ = 0;

static footstone::utils::PersistentObjectMap<uint32_t, std::shared_ptr<RootNode>> persistent_map_;
};
Expand Down
2 changes: 2 additions & 0 deletions dom/src/dom/animation/animation_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ void AnimationManager::AddActiveAnimation(const std::shared_ptr<Animation>& anim
if (!dom_manager) {
return;
}
root_node->SetVSyncEventNeedSource(VSyncEventNeedByAnimation);
listener_id_ = hippy::dom::FetchListenerId();
auto weak_animation_manager = weak_from_this();
dom_manager->AddEventListener(root_node,
Expand Down Expand Up @@ -380,6 +381,7 @@ void AnimationManager::RemoveVSyncEventListener() {
return;
}
if (dom_manager) {
root_node->UnsetVSyncEventNeedSource(VSyncEventNeedByAnimation);
dom_manager->RemoveEventListener(root_node, root_node->GetId(), kVSyncKey, listener_id_);
dom_manager->EndBatch(root_node_);
}
Expand Down
10 changes: 9 additions & 1 deletion dom/src/dom/root_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "footstone/deserializer.h"
#include "footstone/hippy_value.h"

constexpr char kVSyncKey[] = "frameupdate";

namespace hippy {
inline namespace dom {

Expand Down Expand Up @@ -119,7 +121,13 @@ void RootNode::AddEventListener(const std::string& name, uint64_t listener_id, b

void RootNode::RemoveEventListener(const std::string& name, uint64_t listener_id) {
DomNode::RemoveEventListener(name, listener_id);
RemoveEvent(GetId(), name);
if (name == kVSyncKey) {
if (!HasVSyncEventNeedSource()) {
RemoveEvent(GetId(), name);
}
} else {
RemoveEvent(GetId(), name);
}
}

void RootNode::ReleaseResources() {}
Expand Down
2 changes: 2 additions & 0 deletions driver/js/src/modules/animation_frame_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void AnimationFrameModule::RequestAnimationFrame(hippy::napi::CallbackInfo &info
}
has_event_listener_ = true;

root_node->SetVSyncEventNeedSource(VSyncEventNeedByFrame);
listener_id_ = hippy::dom::FetchListenerId();
auto weak_this = weak_from_this();
std::weak_ptr<Scope> weak_scope = scope;
Expand Down Expand Up @@ -116,6 +117,7 @@ void AnimationFrameModule::CancelAnimationFrame(hippy::napi::CallbackInfo &info,
return;
}

root_node->UnsetVSyncEventNeedSource(VSyncEventNeedByFrame);
dom_manager->RemoveEventListener(root_node, root_node->GetId(), kVSyncKey, listener_id_);
dom_manager->EndBatch(root_node);

Expand Down
Loading