1/*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef GRAPHIC_LITE_LITE_WIN_H
17#define GRAPHIC_LITE_LITE_WIN_H
18
19#include <pthread.h>
20
21#include "gfx_utils/color.h"
22#include "gfx_utils/geometry2d.h"
23#include "isurface.h"
24#include "lite_wm_type.h"
25#include "ipc_skeleton.h"
26#include "serializer.h"
27#include "surface.h"
28
29namespace OHOS {
30class LiteWindow {
31public:
32    friend class LiteWM;
33    explicit LiteWindow(const LiteWinConfig& config);
34    virtual ~LiteWindow();
35
36    int32_t GetWindowId() const
37    {
38        return id_;
39    }
40
41    const LiteWinConfig& GetConfig() const
42    {
43        return config_;
44    }
45
46    void SetSid(const SvcIdentity& sid)
47    {
48        needUnregister_ = true;
49        sid_ = sid;
50    }
51
52    void SetIsShow(bool isShow)
53    {
54        isShow_ = isShow;
55    }
56
57    bool GetIsShow() const
58    {
59        return isShow_;
60    }
61
62    void SetPid(pid_t pid)
63    {
64        pid_ = pid;
65    }
66
67    pid_t GetPid() const
68    {
69        return pid_;
70    }
71
72    bool IsCoverMode() const
73    {
74        return config_.compositeMode == LiteWinConfig::COPY;
75    }
76
77    bool NoNeedToDraw() const
78    {
79        return config_.compositeMode == LiteWinConfig::BLEND && config_.opacity == OPA_TRANSPARENT;
80    }
81
82    void ResizeSurface(int16_t width, int16_t height);
83
84    void Update(Rect rect);
85    void UpdateBackBuf();
86    void Flush(const Rect& srcRect, const LiteSurfaceData* layerData, int16_t dx, int16_t dy);
87
88    Surface* GetSurface();
89    void MoveTo(int16_t x, int16_t y);
90    void Resize(int16_t width, int16_t height);
91private:
92    bool CreateSurface();
93    static void ReleaseSurface();
94    void FlushWithModeCopy(const Rect& srcRect, const LiteSurfaceData* layerData, int16_t dx, int16_t dy);
95    void FlushWithModeBlend(const Rect& srcRect, const LiteSurfaceData* layerData, int16_t dx, int16_t dy);
96
97    int32_t id_;
98    pid_t pid_;
99    bool isShow_;
100    LiteWinConfig config_;
101    Surface* surface_;
102    SurfaceBuffer* backBuf_;
103    pthread_mutex_t backBufMutex_;
104    SvcIdentity sid_;
105    IpcObjectStub objectStub_;
106    bool needUnregister_;
107};
108}
109#endif