• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 DRAWING_SURFACE_H
17 #define DRAWING_SURFACE_H
18 
19 #include "impl_interface/surface_impl.h"
20 
21 #include "draw/canvas.h"
22 #include "image/bitmap.h"
23 #include "image/image.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace Drawing {
28 
29 #ifdef ACE_ENABLE_GPU
30 struct FrameBuffer {
31     int width;
32     int height;
33     int FBOID;
34     int Format;
35     std::shared_ptr<GPUContext> gpuContext;
36     std::shared_ptr<ColorSpace> colorSpace;
37 };
38 #endif
39 
40 class Surface {
41 public:
42     Surface();
~Surface()43     ~Surface() {}
44 
45     /*
46      * @brief         Bind raster Surface.
47      * @param bitmap  Raster pixel array.
48      */
49     bool Bind(const Bitmap& bitmap);
50 
51 #ifdef ACE_ENABLE_GPU
52     /*
53      * @brief         Bind GPU texture Surface.
54      * @param image   In GPU memory as a GPU texture.
55      */
56     bool Bind(const Image& image);
57 
58     /*
59      * @brief       Bind
60      * @param info  FrameBuffer object info.
61      */
62     bool Bind(const FrameBuffer& frameBuffer);
63 #endif
64 
65     /*
66      * @brief   Gets Canvas that draws into Surface.
67      */
68     std::shared_ptr<Canvas> GetCanvas();
69 
70     /*
71      * @brief   Gets Image capturing Surface contents.
72      */
73     std::shared_ptr<Image> GetImageSnapshot() const;
74 
75     /*
76      * @brief         Gets Image capturing Surface contents.
77      * @param bounds  Bounds.
78      *                If bounds extends beyond the Surface, it will be trimmed to just the intersection of it
79      *                and the Surface.
80      *                If bounds does not intersect the surface, then this returns nullptr.
81      *                If bounds == the surface, then this is the same as calling the no-parameter variant.
82      */
83     std::shared_ptr<Image> GetImageSnapshot(const RectI& bounds) const;
84 
85 private:
86     std::shared_ptr<SurfaceImpl> impl_;
87     std::shared_ptr<Canvas> cachedCanvas_;
88 };
89 } // namespace Drawing
90 } // namespace Rosen
91 } // namespace OHOS
92 #endif
93