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_UI_SURFACE_VIEW_H
17#define GRAPHIC_LITE_UI_SURFACE_VIEW_H
18
19/**
20 * @addtogroup UI_Components
21 * @{
22 *
23 * @brief Defines UI components such as buttons, texts, images, lists, and progress bars.
24 *
25 * @since 1.0
26 * @version 1.0
27 */
28
29/**
30 * @file ui_surface_view.h
31 *
32 * @brief Declares the surface view that interacts with the multimedia to achieve camera preview and video playback.
33 *
34 * @since 1.0
35 * @version 1.0
36 */
37
38#include "components/ui_view.h"
39#if ENABLE_WINDOW
40#include "surface.h"
41
42#include <string>
43
44namespace OHOS {
45/**
46 * @brief Represents a surface view that interacts with the multimedia to achieve camera preview and video playback.
47 *
48 * @since 1.0
49 * @version 1.0
50 */
51class UISurfaceView : public UIView {
52public:
53    /**
54     * @brief A constructor used to create a <b>UISurfaceView</b> instance.
55     *
56     * @since 1.0
57     * @version 1.0
58     */
59    UISurfaceView();
60
61    /**
62     * @brief A destructor used to delete the <b>UISurfaceView</b> instance.
63     *
64     * @since 1.0
65     * @version 1.0
66     */
67    ~UISurfaceView();
68
69    /**
70     * @brief Obtains the surface, which should be used together with the camera and video modules.
71     *
72     * @return Returns the surface.
73     * @since 1.0
74     * @version 1.0
75     */
76    Surface* GetSurface() const;
77
78    /**
79     * @brief Sets the position for this view.
80     *
81     * @param x Indicates the x-coordinate to set.
82     * @param y Indicates the y-coordinate to set.
83     * @since 1.0
84     * @version 1.0
85     */
86    void SetPosition(int16_t x, int16_t y) override;
87
88    /**
89     * @brief Sets the position and size for this view.
90     *
91     * @param x Indicates the x-coordinate to set.
92     * @param y Indicates the y-coordinate to set.
93     * @param width Indicates the width to set.
94     * @param height Indicates the height to set.
95     * @since 1.0
96     * @version 1.0
97     */
98    void SetPosition(int16_t x, int16_t y, int16_t width, int16_t height) override;
99
100    /**
101     * @brief Adjusts the size of this view.
102     *
103     * @param width Indicates the new width.
104     * @param height Indicates the new height.
105     * @since 1.0
106     * @version 1.0
107     */
108    void Resize(int16_t width, int16_t height) override;
109
110    /**
111     * @brief Sets the x-coordinate for this view.
112     *
113     * @param x Indicates the x-coordinate to set.
114     * @since 1.0
115     * @version 1.0
116     */
117    void SetX(int16_t x) override;
118
119    /**
120     * @brief Sets the y-coordinate for this view.
121     *
122     * @param y Indicates the y-coordinate to set.
123     * @since 1.0
124     * @version 1.0
125     */
126    void SetY(int16_t y) override;
127
128    /**
129     * @brief Sets the width for this view.
130     *
131     * @param width Indicates the width to set.
132     * @since 1.0
133     * @version 1.0
134     */
135    void SetWidth(int16_t width) override;
136
137    /**
138     * @brief Sets the height for this view.
139     *
140     * @param height Indicates the height to set.
141     * @since 1.0
142     * @version 1.0
143     */
144    void SetHeight(int16_t height) override;
145
146    /**
147     * @brief Called before this view is drawn. This function is used to check whether the parent view of this view
148     *        needs to be redrawn so that the drawing process is optimized.
149     *
150     * @param invalidatedArea Indicates the area to draw.
151     * @return Returns <b>true</b> if the parent view needs to be redrawn; returns <b>false</b> otherwise.
152     * @since 1.0
153     * @version 1.0
154     */
155    bool OnPreDraw(Rect& invalidatedArea) const override;
156
157    /**
158     * @brief Called when this view is drawn.
159     *
160     * @param invalidatedArea Indicates the area to draw.
161     * @since 1.0
162     * @version 1.0
163     */
164    void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
165
166private:
167    void Draw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea);
168
169    Surface* surface_;
170    const std::string REGION_POSITION_X = "region_position_x";
171    const std::string REGION_POSITION_Y = "region_position_y";
172    const std::string REGION_WIDTH = "region_width";
173    const std::string REGION_HEIGHT = "region_height";
174    const uint8_t DEFAULT_QUEUE_SIZE = 2;
175};
176} // namespace OHOS
177#endif // ENABLE_WINDOW
178#endif // GRAPHIC_LITE_UI_SURFACE_VIEW_H
179