mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-12-18 20:48:19 +00:00
!494 修改hello_composer使用的vsync接口
Merge pull request !494 from BruceXuXu/hello_composer
This commit is contained in:
commit
0b7b911407
@ -76,10 +76,11 @@ VsyncError VSyncConnection::SetVSyncRate(int32_t rate)
|
||||
|
||||
VSyncDistributor::VSyncDistributor(sptr<VSyncController> controller, std::string name)
|
||||
: controller_(controller), mutex_(), con_(), connections_(),
|
||||
vsyncEnabled_(false), name_(name), vsyncThreadRunning_(false)
|
||||
vsyncEnabled_(false), name_(name)
|
||||
{
|
||||
event_.timestamp = 0;
|
||||
event_.vsyncCount = 0;
|
||||
vsyncThreadRunning_ = true;
|
||||
threadLoop_ = std::thread(std::bind(&VSyncDistributor::ThreadMain, this));
|
||||
}
|
||||
|
||||
@ -122,7 +123,6 @@ VsyncError VSyncDistributor::RemoveConnection(const sptr<VSyncConnection>& conne
|
||||
|
||||
void VSyncDistributor::ThreadMain()
|
||||
{
|
||||
vsyncThreadRunning_ = true;
|
||||
int64_t timestamp;
|
||||
int64_t vsyncCount;
|
||||
while (vsyncThreadRunning_ == true) {
|
||||
@ -216,11 +216,11 @@ void VSyncDistributor::OnVSyncEvent(int64_t now)
|
||||
|
||||
VsyncError VSyncDistributor::RequestNextVSync(const sptr<VSyncConnection>& connection)
|
||||
{
|
||||
ScopedBytrace func(connection->GetName() + "_RequestNextVSync");
|
||||
if (connection == nullptr) {
|
||||
VLOGE("connection is nullptr");
|
||||
return VSYNC_ERROR_NULLPTR;
|
||||
}
|
||||
ScopedBytrace func(connection->GetName() + "_RequestNextVSync");
|
||||
std::lock_guard<std::mutex> locker(mutex_);
|
||||
auto it = find(connections_.begin(), connections_.end(), connection);
|
||||
if (it == connections_.end()) {
|
||||
|
@ -45,8 +45,9 @@ void VSyncGenerator::DeleteInstance() noexcept
|
||||
}
|
||||
|
||||
VSyncGenerator::VSyncGenerator()
|
||||
: period_(0), phase_(0), refrenceTime_(0), wakeupDelay_(0), vsyncThreadRunning_(false)
|
||||
: period_(0), phase_(0), refrenceTime_(0), wakeupDelay_(0)
|
||||
{
|
||||
vsyncThreadRunning_ = true;
|
||||
thread_ = std::thread(std::bind(&VSyncGenerator::ThreadLoop, this));
|
||||
}
|
||||
|
||||
@ -61,7 +62,6 @@ VSyncGenerator::~VSyncGenerator()
|
||||
|
||||
void VSyncGenerator::ThreadLoop()
|
||||
{
|
||||
vsyncThreadRunning_ = true;
|
||||
int64_t occurTimestamp = GetSysTimeNs();
|
||||
while (vsyncThreadRunning_ == true) {
|
||||
std::vector<Listener> listeners;
|
||||
|
@ -29,8 +29,8 @@ config("hello_composer_public_config") {
|
||||
"//foundation/graphic/standard/rosen/modules/composer/hdi_backend/include",
|
||||
"//drivers/peripheral/display/interfaces/include",
|
||||
"//foundation/graphic/standard/rosen/include/common",
|
||||
"//foundation/graphic/standard/interfaces/innerkits/vsync_module",
|
||||
"//foundation/graphic/standard/rosen/modules/composer/vsync/include",
|
||||
"//foundation/graphic/standard/interfaces/innerkits/composer",
|
||||
]
|
||||
}
|
||||
|
||||
@ -50,7 +50,6 @@ ohos_executable("hello_composer") {
|
||||
deps = [
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||
"//foundation/graphic/standard:libsurface",
|
||||
"//foundation/graphic/standard:libvsync_client",
|
||||
"//foundation/graphic/standard/rosen/modules/composer:libcomposer",
|
||||
"//foundation/graphic/standard/utils:libgraphic_utils",
|
||||
"//foundation/graphic/standard/utils:sync_fence",
|
||||
|
@ -14,7 +14,10 @@
|
||||
*/
|
||||
|
||||
#include "hello_composer.h"
|
||||
|
||||
#include <vsync_generator.h>
|
||||
#include <vsync_controller.h>
|
||||
#include <vsync_distributor.h>
|
||||
#include <vsync_receiver.h>
|
||||
#include <securec.h>
|
||||
#include <sync_fence.h>
|
||||
|
||||
@ -28,10 +31,18 @@ namespace {
|
||||
#define LOGE(fmt, ...) ::OHOS::HiviewDFX::HiLog::Error( \
|
||||
::OHOS::HiviewDFX::HiLogLabel {LOG_CORE, 0, "HelloComposer"}, \
|
||||
"%{public}s: " fmt, __func__, ##__VA_ARGS__)
|
||||
|
||||
sptr<VSyncReceiver> g_receiver = nullptr;
|
||||
}
|
||||
|
||||
void HelloComposer::Run(std::vector<std::string> &runArgs)
|
||||
{
|
||||
auto generator = CreateVSyncGenerator();
|
||||
sptr<VSyncController> vsyncController = new VSyncController(generator, 0);
|
||||
sptr<VSyncDistributor> vsyncDistributor = new VSyncDistributor(vsyncController, "HelloComposer");
|
||||
sptr<VSyncConnection> vsyncConnection = new VSyncConnection(vsyncDistributor, "HelloComposer");
|
||||
vsyncDistributor->AddConnection(vsyncConnection);
|
||||
|
||||
LOGI("start to run hello composer");
|
||||
backend_ = OHOS::Rosen::HdiBackend::GetInstance();
|
||||
if (backend_ == nullptr) {
|
||||
@ -63,9 +74,10 @@ void HelloComposer::Run(std::vector<std::string> &runArgs)
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
std::shared_ptr<OHOS::AppExecFwk::EventRunner> runner = OHOS::AppExecFwk::EventRunner::Create(false);
|
||||
mainThreadHandler_ = std::make_shared<OHOS::AppExecFwk::EventHandler>(runner);
|
||||
g_receiver = new VSyncReceiver(vsyncConnection, mainThreadHandler_);
|
||||
g_receiver->Init();
|
||||
mainThreadHandler_->PostTask(std::bind(&HelloComposer::RequestSync, this));
|
||||
runner->Run();
|
||||
}
|
||||
@ -157,18 +169,13 @@ void HelloComposer::InitLayers(uint32_t screenId)
|
||||
|
||||
void HelloComposer::Sync(int64_t, void *data)
|
||||
{
|
||||
struct OHOS::FrameCallback cb = {
|
||||
.frequency_ = freq_,
|
||||
.timestamp_ = 0,
|
||||
.userdata_ = data,
|
||||
.callback_ = std::bind(&HelloComposer::Sync, this, SYNC_FUNC_ARG),
|
||||
VSyncReceiver::FrameCallback fcb = {
|
||||
.userData_ = data,
|
||||
.callback_ = std::bind(&HelloComposer::Sync, this, ::std::placeholders::_1, ::std::placeholders::_2),
|
||||
};
|
||||
|
||||
OHOS::VsyncError ret = OHOS::VsyncHelper::Current()->RequestFrameCallback(cb);
|
||||
if (ret) {
|
||||
LOGE("RequestFrameCallback inner %{public}d\n", ret);
|
||||
if (g_receiver != nullptr) {
|
||||
g_receiver->RequestNextVSync(fcb);
|
||||
}
|
||||
|
||||
if (!ready_) {
|
||||
return;
|
||||
}
|
||||
|
@ -16,9 +16,9 @@
|
||||
#ifndef HELLO_COMPOSER_H
|
||||
#define HELLO_COMPOSER_H
|
||||
|
||||
#include <vsync_helper.h>
|
||||
#include <display_type.h>
|
||||
#include <surface.h>
|
||||
#include <event_handler.h>
|
||||
#include "hdi_backend.h"
|
||||
#include "hdi_layer_info.h"
|
||||
#include "hdi_output.h"
|
||||
|
Loading…
Reference in New Issue
Block a user