!1190 提供请求Vsync的接口给ACE

Merge pull request !1190 from liuqi/lq_0714_dev
This commit is contained in:
openharmony_ci
2022-08-03 08:17:03 +00:00
committed by Gitee
14 changed files with 109 additions and 123 deletions
+2
View File
@@ -349,6 +349,7 @@ public:
virtual void SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer) = 0;
virtual void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) = 0;
virtual void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& inputEvent) = 0;
virtual void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) = 0;
virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) = 0;
/**
* @brief register window lifecycle listener.
@@ -400,6 +401,7 @@ public:
virtual uint32_t GetRequestModeSupportInfo() const = 0;
virtual WMError SetTouchHotAreas(const std::vector<Rect>& rects) = 0;
virtual void GetRequestedTouchHotAreas(std::vector<Rect>& rects) const = 0;
virtual bool IsMainHandlerAvailable() const = 0;
/**
* @brief disable main window decoration. It must be callled before loadContent.
+3
View File
@@ -50,6 +50,7 @@ public:
void SetBrightness(float brightness);
void SetRequestedOrientation(Orientation orientation);
void SetCallingWindow(uint32_t windowId);
void SetMainHandlerAvailable(bool isMainHandlerAvailable);
Rect GetWindowRect() const;
WindowType GetWindowType() const;
@@ -66,6 +67,7 @@ public:
float GetBrightness() const;
Orientation GetRequestedOrientation() const;
uint32_t GetCallingWindow() const;
bool GetMainHandlerAvailable() const;
private:
Rect windowRect_ { 0, 0, 0, 0 };
@@ -81,6 +83,7 @@ private:
WindowTag windowTag_;
bool keepScreenOn_ = false;
bool turnScreenOn_ = false;
bool isMainHandlerAvailable_ = true;
float brightness_ = UNDEFINED_BRIGHTNESS;
uint32_t callingWindow_ = INVALID_WINDOW_ID;
std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
-5
View File
@@ -364,11 +364,6 @@ struct SystemConfig {
bool isStretchable_ = false;
};
enum class CallbackType {
CALLBACK_INPUT = 0,
CALLBACK_FRAME = 1,
};
using OnCallback = std::function<void(int64_t)>;
struct VsyncCallback {
OnCallback onCallback;
+3
View File
@@ -36,9 +36,12 @@ public:
private:
sptr<WindowInputChannel> GetInputChannel(uint32_t windowId);
std::mutex mtx_;
std::unordered_map<uint32_t, sptr<WindowInputChannel>> windowInputChannels_;
std::shared_ptr<MMI::IInputEventConsumer> inputListener_ = nullptr;
std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
const std::string INPUT_AND_VSYNC_THREAD = "input_and_vsync_thread";
};
class InputEventListener : public MMI::IInputEventConsumer {
+16 -12
View File
@@ -35,34 +35,38 @@ class VsyncStation {
WM_DECLARE_SINGLE_INSTANCE_BASE(VsyncStation);
public:
~VsyncStation() = default;
void RequestVsync(CallbackType type, const std::shared_ptr<VsyncCallback>& vsyncCallback);
void RemoveCallback(CallbackType type, const std::shared_ptr<VsyncCallback>& vsyncCallback);
void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback);
void RemoveCallback();
void SetIsMainHandlerAvailable(bool available)
{
isMainHandlerAvailable_ = available;
}
void SetVsyncEventHandler(const std::shared_ptr<AppExecFwk::EventHandler>& eventHandler)
{
vsyncHandler_ = eventHandler;
}
private:
VsyncStation() = default;
static void OnVsync(int64_t nanoTimestamp, void* client);
void VsyncCallbackInner(int64_t nanoTimestamp);
void OnVsyncTimeOut();
AppExecFwk::EventHandler::Callback vsyncTimeoutCallback_ = std::bind(&VsyncStation::OnVsyncTimeOut, this);
const std::string VSYNC_THREAD_ID = "vsync_thread";
std::shared_ptr<AppExecFwk::EventHandler> vsyncHandler_ = nullptr;
std::mutex mtx_;
bool hasRequestedVsync_ = false;
bool isMainHandlerAvailable_ = false;
uint32_t vsyncCount_ = 0;
std::map<CallbackType, std::unordered_set<std::shared_ptr<VsyncCallback>>> vsyncCallbacks_ = {
{CallbackType::CALLBACK_INPUT, {}},
{CallbackType::CALLBACK_FRAME, {}},
};
bool hasRequestedVsync_ = false;
bool hasInitVsyncReceiver_ = false;
bool isMainHandlerAvailable_ = true;
const std::string VSYNC_THREAD_ID = "vsync_thread";
std::shared_ptr<OHOS::Rosen::VSyncReceiver> receiver_ = nullptr;
std::unordered_set<std::shared_ptr<VsyncCallback>> vsyncCallbacks_;
VSyncReceiver::FrameCallback frameCallback_ = {
.userData_ = this,
.callback_ = OnVsync,
};
std::shared_ptr<OHOS::Rosen::VSyncReceiver> receiver_ = nullptr;
std::shared_ptr<AppExecFwk::EventHandler> vsyncHandler_ = nullptr;
AppExecFwk::EventHandler::Callback vsyncTimeoutCallback_ = std::bind(&VsyncStation::OnVsyncTimeOut, this);
};
} // namespace Rosen
} // namespace OHOS
+3
View File
@@ -117,6 +117,7 @@ public:
virtual uint32_t GetWindowId() const override;
virtual uint32_t GetWindowFlags() const override;
uint32_t GetRequestModeSupportInfo() const override;
bool IsMainHandlerAvailable() const override;
inline NotifyNativeWinDestroyFunc GetNativeDestroyCallback()
{
return notifyNativefunc_;
@@ -214,6 +215,7 @@ public:
void UpdateModeSupportInfo(uint32_t modeSupportInfo);
virtual void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) override;
virtual void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& inputEvent) override;
virtual void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override;
void UpdateFocusStatus(bool focused);
virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
void UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type);
@@ -436,6 +438,7 @@ private:
bool isOriginRectSet_ = false;
bool needRemoveWindowInputChannel_ = false;
bool isListenerHandlerRunning_ = false;
bool isMainHandlerAvailable_ = true;
};
} // namespace Rosen
} // namespace OHOS
-3
View File
@@ -31,13 +31,10 @@ public:
void HandleKeyEvent(std::shared_ptr<MMI::KeyEvent>& keyEvent);
void Destroy();
private:
void OnVsync(int64_t timeStamp);
bool IsKeyboardEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const;
std::shared_ptr<MMI::PointerEvent> moveEvent_ = nullptr;
std::mutex mtx_;
sptr<Window> window_;
bool isAvailable_;
std::shared_ptr<VsyncCallback> callback_ = std::make_shared<VsyncCallback>(VsyncCallback());
static const int32_t MAX_INPUT_NUM = 100;
};
}
+23 -3
View File
@@ -14,7 +14,11 @@
*/
#include "input_transfer_station.h"
#include <window_manager_hilog.h>
#include <thread>
#include <event_handler.h>
#include "vsync_station.h"
#include "window_manager_hilog.h"
namespace OHOS {
namespace Rosen {
@@ -77,9 +81,25 @@ void InputTransferStation::AddInputWindow(const sptr<Window>& window)
std::lock_guard<std::mutex> lock(mtx_);
windowInputChannels_.insert(std::make_pair(windowId, inputChannel));
if (inputListener_ == nullptr) {
WLOGFI("Init input listener");
WLOGFI("Init input listener, IsMainHandlerAvailable: %{public}u", window->IsMainHandlerAvailable());
std::shared_ptr<MMI::IInputEventConsumer> listener = std::make_shared<InputEventListener>(InputEventListener());
MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener);
auto mainEventRunner = AppExecFwk::EventRunner::GetMainEventRunner();
if (mainEventRunner != nullptr && window->IsMainHandlerAvailable()) {
WLOGFI("MainEventRunner is available");
eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(mainEventRunner);
MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener, eventHandler_);
} else {
WLOGFI("MainEventRunner is not available");
eventHandler_ = AppExecFwk::EventHandler::Current();
auto curThreadId = std::this_thread::get_id();
if (!eventHandler_ || (mainEventRunner->GetThreadId() == *(reinterpret_cast<uint64_t*>(&curThreadId)))) {
eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(
AppExecFwk::EventRunner::Create(INPUT_AND_VSYNC_THREAD));
}
MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener, eventHandler_);
VsyncStation::GetInstance().SetIsMainHandlerAvailable(false);
VsyncStation::GetInstance().SetVsyncEventHandler(eventHandler_);
}
inputListener_ = listener;
}
}
+21 -30
View File
@@ -14,6 +14,7 @@
*/
#include "vsync_station.h"
#include "transaction/rs_interfaces.h"
#include "window_manager_hilog.h"
@@ -26,31 +27,30 @@ namespace {
}
WM_IMPLEMENT_SINGLE_INSTANCE(VsyncStation)
void VsyncStation::RequestVsync(CallbackType type, const std::shared_ptr<VsyncCallback>& vsyncCallback)
void VsyncStation::RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback)
{
{
std::lock_guard<std::mutex> lock(mtx_);
auto iter = vsyncCallbacks_.find(type);
if (iter == vsyncCallbacks_.end()) {
WLOGFE("wrong callback type.");
return;
}
iter->second.insert(vsyncCallback);
vsyncCallbacks_.insert(vsyncCallback);
if (vsyncHandler_ == nullptr) {
if (!hasInitVsyncReceiver_ || !vsyncHandler_) {
auto mainEventRunner = AppExecFwk::EventRunner::GetMainEventRunner();
if (mainEventRunner != nullptr && isMainHandlerAvailable_) {
WLOGFI("MainEventRunner is available");
vsyncHandler_ = std::make_shared<AppExecFwk::EventHandler>(mainEventRunner);
} else {
WLOGFE("MainEventRunner is not available, create a new EventRunner for vsyncHandler_.");
vsyncHandler_ = std::make_shared<AppExecFwk::EventHandler>(
AppExecFwk::EventRunner::Create(VSYNC_THREAD_ID));
WLOGFI("MainEventRunner is not available");
if (!vsyncHandler_) {
vsyncHandler_ = std::make_shared<AppExecFwk::EventHandler>(
AppExecFwk::EventRunner::Create(VSYNC_THREAD_ID));
}
}
auto& rsClient = OHOS::Rosen::RSInterfaces::GetInstance();
while (receiver_ == nullptr) {
receiver_ = rsClient.CreateVSyncReceiver("WM_" + std::to_string(::getpid()), vsyncHandler_);
}
receiver_->Init();
hasInitVsyncReceiver_ = true;
}
if (hasRequestedVsync_) {
return;
@@ -58,7 +58,7 @@ void VsyncStation::RequestVsync(CallbackType type, const std::shared_ptr<VsyncCa
hasRequestedVsync_ = true;
vsyncCount_++;
if (vsyncCount_ & 0x01) { // write log every 2 vsync
WLOGFI("Request next vsync.");
WLOGFD("Request next vsync.");
}
vsyncHandler_->RemoveTask(VSYNC_TIME_OUT_TASK);
vsyncHandler_->PostTask(vsyncTimeoutCallback_, VSYNC_TIME_OUT_TASK, VSYNC_TIME_OUT_MILLISECONDS);
@@ -66,37 +66,28 @@ void VsyncStation::RequestVsync(CallbackType type, const std::shared_ptr<VsyncCa
receiver_->RequestNextVSync(frameCallback_);
}
void VsyncStation::RemoveCallback(CallbackType type, const std::shared_ptr<VsyncCallback>& vsyncCallback)
void VsyncStation::RemoveCallback()
{
WLOGFI("Remove callback, type: %{public}u", type);
std::lock_guard<std::mutex> lock(mtx_);
auto iter = vsyncCallbacks_.find(type);
if (iter == vsyncCallbacks_.end()) {
WLOGFE("wrong callback type.");
return;
}
iter->second.erase(vsyncCallback);
WLOGFI("[WM] Remove Vsync callback");
vsyncCallbacks_.clear();
}
void VsyncStation::VsyncCallbackInner(int64_t timestamp)
{
std::map<CallbackType, std::unordered_set<std::shared_ptr<VsyncCallback>>> vsyncCallbacks;
std::unordered_set<std::shared_ptr<VsyncCallback>> vsyncCallbacks;
{
std::lock_guard<std::mutex> lock(mtx_);
hasRequestedVsync_ = false;
vsyncCallbacks = vsyncCallbacks_;
for (auto& vsyncCallbacksSet: vsyncCallbacks_) {
vsyncCallbacksSet.second.clear();
}
vsyncCallbacks_.clear();
vsyncHandler_->RemoveTask(VSYNC_TIME_OUT_TASK);
if (vsyncCount_ & 0x01) { // write log every 2 vsync
WLOGFI("On vsync callback.");
WLOGFD("[WM] On vsync callback.");
}
}
for (auto& vsyncCallbacksSet: vsyncCallbacks) {
for (const auto& callback: vsyncCallbacksSet.second) {
callback->onCallback(timestamp);
}
for (const auto& callback: vsyncCallbacks) {
callback->onCallback(timestamp);
}
}
@@ -112,8 +103,8 @@ void VsyncStation::OnVsync(int64_t timestamp, void* client)
void VsyncStation::OnVsyncTimeOut()
{
WLOGFE("Vsync time out");
std::lock_guard<std::mutex> lock(mtx_);
WLOGFI("[WM] Vsync time out");
hasRequestedVsync_ = false;
}
}
+17 -1
View File
@@ -70,6 +70,7 @@ WindowImpl::WindowImpl(const sptr<WindowOption>& option)
property_->SetHitOffset(option->GetHitOffset());
property_->SetRequestedOrientation(option->GetRequestedOrientation());
windowTag_ = option->GetWindowTag();
isMainHandlerAvailable_ = option->GetMainHandlerAvailable();
property_->SetTurnScreenOn(option->IsTurnScreenOn());
property_->SetKeepScreenOn(option->IsKeepScreenOn());
property_->SetBrightness(option->GetBrightness());
@@ -300,6 +301,11 @@ uint32_t WindowImpl::GetModeSupportInfo() const
return property_->GetModeSupportInfo();
}
bool WindowImpl::IsMainHandlerAvailable() const
{
return isMainHandlerAvailable_;
}
SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) const
{
auto curProperties = property_->GetSystemBarProperty();
@@ -2280,11 +2286,21 @@ void WindowImpl::ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& p
WLOGFI("Transfer pointer event to uiContent");
(void)uiContent_->ProcessPointerEvent(pointerEvent);
} else {
WLOGW("pointerEvent is not consumed, windowId: %{public}u", GetWindowId());
WLOGE("pointerEvent is not consumed, windowId: %{public}u", GetWindowId());
pointerEvent->MarkProcessed();
}
}
void WindowImpl::RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (state_ == WindowState::STATE_DESTROYED) {
WLOGFE("[WM] Receive Vsync Request failed, window is destroyed");
return;
}
VsyncStation::GetInstance().RequestVsync(vsyncCallback);
}
void WindowImpl::UpdateFocusStatus(bool focused)
{
WLOGFI("window focus status: %{public}d, id: %{public}u", focused, property_->GetWindowId());
+3 -46
View File
@@ -24,7 +24,6 @@ namespace {
}
WindowInputChannel::WindowInputChannel(const sptr<Window>& window): window_(window), isAvailable_(true)
{
callback_->onCallback = std::bind(&WindowInputChannel::OnVsync, this, std::placeholders::_1);
}
WindowInputChannel::~WindowInputChannel()
@@ -66,6 +65,8 @@ void WindowInputChannel::HandlePointerEvent(std::shared_ptr<MMI::PointerEvent>&
WLOGFE("pointerEvent is nullptr");
return;
}
WLOGFI("Receive pointer event, windowId: %{public}u, action: %{public}d",
window_->GetWindowId(), pointerEvent->GetPointerAction());
if ((window_->GetType() == WindowType::WINDOW_TYPE_DIALOG) &&
(pointerEvent->GetAgentWindowId() != pointerEvent->GetTargetWindowId())) {
if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_DOWN ||
@@ -75,46 +76,6 @@ void WindowInputChannel::HandlePointerEvent(std::shared_ptr<MMI::PointerEvent>&
pointerEvent->MarkProcessed();
return;
}
if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_MOVE) {
std::shared_ptr<MMI::PointerEvent> pointerEventTemp;
{
std::lock_guard<std::mutex> lock(mtx_);
pointerEventTemp = moveEvent_;
moveEvent_ = pointerEvent;
if (isAvailable_) {
VsyncStation::GetInstance().RequestVsync(CallbackType::CALLBACK_INPUT, callback_);
} else {
WLOGFE("WindowInputChannel is not available");
pointerEvent->MarkProcessed();
moveEvent_ = nullptr;
}
}
WLOGFI("Receive move event, windowId: %{public}u, action: %{public}d",
window_->GetWindowId(), pointerEvent->GetPointerAction());
if (pointerEventTemp != nullptr) {
pointerEventTemp->MarkProcessed();
}
} else {
WLOGFI("Dispatch non-move event, windowId: %{public}u, action: %{public}d",
window_->GetWindowId(), pointerEvent->GetPointerAction());
window_->ConsumePointerEvent(pointerEvent);
}
}
void WindowInputChannel::OnVsync(int64_t timeStamp)
{
std::shared_ptr<MMI::PointerEvent> pointerEvent;
{
std::lock_guard<std::mutex> lock(mtx_);
pointerEvent = moveEvent_;
moveEvent_ = nullptr;
}
if (pointerEvent == nullptr) {
WLOGFE("moveEvent_ is nullptr");
return;
}
WLOGFI("Dispatch move event, windowId: %{public}u, action: %{public}d",
window_->GetWindowId(), pointerEvent->GetPointerAction());
window_->ConsumePointerEvent(pointerEvent);
}
@@ -123,11 +84,7 @@ void WindowInputChannel::Destroy()
std::lock_guard<std::mutex> lock(mtx_);
WLOGFI("Destroy WindowInputChannel, windowId:%{public}u", window_->GetWindowId());
isAvailable_ = false;
VsyncStation::GetInstance().RemoveCallback(CallbackType::CALLBACK_INPUT, callback_);
if (moveEvent_ != nullptr) {
moveEvent_->MarkProcessed();
moveEvent_ = nullptr;
}
VsyncStation::GetInstance().RemoveCallback();
}
bool WindowInputChannel::IsKeyboardEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const
+10
View File
@@ -150,6 +150,16 @@ WindowTag WindowOption::GetWindowTag() const
return windowTag_;
}
void WindowOption::SetMainHandlerAvailable(bool isMainHandlerAvailable)
{
isMainHandlerAvailable_ = isMainHandlerAvailable;
}
bool WindowOption::GetMainHandlerAvailable() const
{
return isMainHandlerAvailable_;
}
const PointInfo& WindowOption::GetHitOffset() const
{
return hitOffset_;
-1
View File
@@ -88,7 +88,6 @@ private:
void OnReceiveVsync(int64_t timeStamp);
void ResetMoveOrDragState();
std::mutex mtx_;
sptr<WindowProperty> windowProperty_;
sptr<MoveDragProperty> moveDragProperty_;
uint32_t activeWindowId_ = INVALID_WINDOW_ID;
+8 -22
View File
@@ -185,6 +185,7 @@ bool MoveDragController::Init()
inputListener_ = std::make_shared<InputEventListener>(InputEventListener());
MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(inputListener_, inputEventHandler_);
VsyncStation::GetInstance().SetIsMainHandlerAvailable(false);
VsyncStation::GetInstance().SetVsyncEventHandler(inputEventHandler_);
return true;
}
@@ -205,7 +206,6 @@ void MoveDragController::HandleReadyToMoveOrDrag(uint32_t windowId, sptr<WindowP
void MoveDragController::HandleEndUpMovingOrDragging(uint32_t windowId)
{
std::lock_guard<std::mutex> lock(mtx_);
if (activeWindowId_ != windowId) {
WLOGFE("end up moving or dragging failed, windowId: %{public}u", windowId);
return;
@@ -221,7 +221,7 @@ void MoveDragController::HandleWindowRemovedOrDestroyed(uint32_t windowId)
if (!(GetMoveDragProperty()->startMoveFlag_ || GetMoveDragProperty()->startDragFlag_)) {
return;
}
VsyncStation::GetInstance().RemoveCallback(CallbackType::CALLBACK_INPUT, vsyncCallback_);
VsyncStation::GetInstance().RemoveCallback();
ResetMoveOrDragState();
}
@@ -232,16 +232,8 @@ void MoveDragController::ConsumePointerEvent(const std::shared_ptr<MMI::PointerE
return;
}
if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_MOVE) {
std::shared_ptr<MMI::PointerEvent> tempPointerEvent;
{
std::lock_guard<std::mutex> lock(mtx_);
tempPointerEvent = moveEvent_;
moveEvent_ = pointerEvent;
VsyncStation::GetInstance().RequestVsync(CallbackType::CALLBACK_INPUT, vsyncCallback_);
}
if (tempPointerEvent != nullptr) {
tempPointerEvent->MarkProcessed();
}
moveEvent_ = pointerEvent;
VsyncStation::GetInstance().RequestVsync(vsyncCallback_);
} else {
WLOGFI("[WMS] Dispatch non-move event, action: %{public}d", pointerEvent->GetPointerAction());
HandlePointerEvent(pointerEvent);
@@ -251,19 +243,13 @@ void MoveDragController::ConsumePointerEvent(const std::shared_ptr<MMI::PointerE
void MoveDragController::OnReceiveVsync(int64_t timeStamp)
{
std::shared_ptr<MMI::PointerEvent> pointerEvent;
{
std::lock_guard<std::mutex> lock(mtx_);
pointerEvent = moveEvent_;
moveEvent_ = nullptr;
}
if (pointerEvent == nullptr) {
if (moveEvent_ == nullptr) {
WLOGFE("moveEvent is nullptr");
return;
}
WLOGFD("[OnReceiveVsync] receive move event, action: %{public}d", pointerEvent->GetPointerAction());
HandlePointerEvent(pointerEvent);
pointerEvent->MarkProcessed();
WLOGFD("[OnReceiveVsync] receive move event, action: %{public}d", moveEvent_->GetPointerAction());
HandlePointerEvent(moveEvent_);
moveEvent_->MarkProcessed();
}
Rect MoveDragController::GetHotZoneRect()