Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
38 changes: 18 additions & 20 deletions shell/platform/tizen/tizen_vsync_waiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ struct Message {

} // namespace

TizenVsyncWaiter::TizenVsyncWaiter(FlutterTizenEngine* engine) {
tdm_client_ = std::make_shared<TdmClient>(engine);

TizenVsyncWaiter::TizenVsyncWaiter(FlutterTizenEngine* engine)
: engine_(engine) {
vblank_thread_ = ecore_thread_feedback_run(RunVblankLoop, nullptr, nullptr,
nullptr, this, EINA_TRUE);
}

TizenVsyncWaiter::~TizenVsyncWaiter() {
tdm_client_.reset();

if (tdm_client_) {
tdm_client_->OnEngineStop();
}
SendMessage(kMessageQuit, 0);

if (vblank_thread_) {
ecore_thread_cancel(vblank_thread_);
vblank_thread_ = nullptr;
Expand Down Expand Up @@ -68,8 +67,9 @@ void TizenVsyncWaiter::SendMessage(int event, intptr_t baton) {
void TizenVsyncWaiter::RunVblankLoop(void* data, Ecore_Thread* thread) {
auto* self = reinterpret_cast<TizenVsyncWaiter*>(data);

std::weak_ptr<TdmClient> tdm_client = self->tdm_client_;
if (!tdm_client.lock()->IsValid()) {
TdmClient tdm_client(self->engine_);
self->SetTdmClient(&tdm_client);
if (!tdm_client.IsValid()) {
FT_LOG(Error) << "Invalid tdm_client.";
ecore_thread_cancel(thread);
return;
Expand All @@ -94,10 +94,7 @@ void TizenVsyncWaiter::RunVblankLoop(void* data, Ecore_Thread* thread) {
intptr_t baton = message->baton;
eina_thread_queue_wait_done(vblank_thread_queue, ref);

if (tdm_client.expired()) {
break;
}
tdm_client.lock()->AwaitVblank(baton);
tdm_client.AwaitVblank(baton);
}

if (vblank_thread_queue) {
Expand Down Expand Up @@ -130,10 +127,6 @@ TdmClient::TdmClient(FlutterTizenEngine* engine) {
}

TdmClient::~TdmClient() {
{
std::lock_guard<std::mutex> lock(engine_mutex_);
engine_ = nullptr;
}
if (vblank_) {
tdm_client_vblank_destroy(vblank_);
vblank_ = nullptr;
Expand All @@ -145,6 +138,15 @@ TdmClient::~TdmClient() {
}
}

bool TdmClient::IsValid() {
return vblank_ && client_;
}

void TdmClient::OnEngineStop() {
std::lock_guard<std::mutex> lock(engine_mutex_);
engine_ = nullptr;
}

void TdmClient::AwaitVblank(intptr_t baton) {
baton_ = baton;
tdm_error ret = tdm_client_vblank_wait(vblank_, 1, VblankCallback, this);
Expand All @@ -155,10 +157,6 @@ void TdmClient::AwaitVblank(intptr_t baton) {
tdm_client_handle_events(client_);
}

bool TdmClient::IsValid() {
return vblank_ && client_;
}

void TdmClient::VblankCallback(tdm_client_vblank* vblank,
tdm_error error,
unsigned int sequence,
Expand Down
7 changes: 5 additions & 2 deletions shell/platform/tizen/tizen_vsync_waiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <Ecore.h>
#include <tdm_client.h>

#include <memory>
#include <mutex>

#include "flutter/shell/platform/embedder/embedder.h"
Expand All @@ -23,6 +22,7 @@ class TdmClient {
virtual ~TdmClient();

bool IsValid();
void OnEngineStop();
void AwaitVblank(intptr_t baton);

private:
Expand Down Expand Up @@ -53,9 +53,12 @@ class TizenVsyncWaiter {
private:
void SendMessage(int event, intptr_t baton);

void SetTdmClient(TdmClient* tdm_client) { tdm_client_ = tdm_client; }

static void RunVblankLoop(void* data, Ecore_Thread* thread);

std::shared_ptr<TdmClient> tdm_client_;
FlutterTizenEngine* engine_ = nullptr;
TdmClient* tdm_client_ = nullptr;
Ecore_Thread* vblank_thread_ = nullptr;
Eina_Thread_Queue* vblank_thread_queue_ = nullptr;
};
Expand Down