render_manager.h 2.6 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GRAPHIC_LITE_RENDER_MANAGER_H
#define GRAPHIC_LITE_RENDER_MANAGER_H

#include "common/task_manager.h"
P
pssea 已提交
20 21
#include "components/root_view.h"
#include "components/ui_view.h"
Z
zhangguyuan 已提交
22 23 24
#include "gfx_utils/geometry2d.h"
#include "gfx_utils/list.h"
#include "gfx_utils/sys_info.h"
P
pssea 已提交
25

M
mamingshuai 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38
#if ENABLE_WINDOW
#include "window/window.h"
#endif

namespace OHOS {
static constexpr float MAX_FPS = 90.f;

static constexpr int16_t SAMPLE_NUMBER = 100;

static constexpr uint16_t MILLISECONDS_PER_SECOND = 1000;

class RenderManager : public Task {
public:
Z
zhdengc 已提交
39
    static RenderManager& GetInstance();
M
mamingshuai 已提交
40

41
    void Init() override;
M
mamingshuai 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

#if ENABLE_WINDOW
    Window* GetWindowById(int32_t id)
    {
        auto node = winList_.Begin();
        while (node != winList_.End()) {
            if (node->data_->GetWindowId() == id) {
                return node->data_;
            }
            node = node->next_;
        }
        return nullptr;
    }
#endif

57
    void Callback() override;
M
mamingshuai 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

    float GetFPS() const
    {
        return fps_;
    }

    void RegisterFPSChangedListener(SysInfo::OnFPSChangedListener* onFPSChangedListener)
    {
        onFPSChangedListener_ = onFPSChangedListener;
        needResetFPS_ = true;
    }

#if ENABLE_WINDOW
    void AddToDisplay(Window* window);

    void RemoveFromDisplay(Window* window);
#endif
P
pssea 已提交
75 76
    static void RenderRect(const Rect& rect, RootView* rootView);
    void RefreshScreen();
M
mamingshuai 已提交
77

78
private:
M
mamingshuai 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    RenderManager();

    ~RenderManager();

#if ENABLE_FPS_SUPPORT
    void UpdateFPS();

    void UpdateFPSByFixedTimeMethod();

    void UpdateFPSByAverageSamplingMethod();

    void UpdateFPSByPreciseSamplingMethod();

    void OnFPSChanged(float newFPS)
    {
        if (onFPSChangedListener_) {
            onFPSChangedListener_->OnFPSChanged(newFPS);
        }
    }
#endif

    float fps_;

    bool needResetFPS_;

    SysInfo::OnFPSChangedListener* onFPSChangedListener_;

#if ENABLE_WINDOW
    List<Window*> winList_;
#endif
};
} // namespace OHOS
#endif // GRAPHIC_LITE_RENDER_MANAGER_H