• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 RS_DRAW_WINDOW_CACHE_H
17 #define RS_DRAW_WINDOW_CACHE_H
18 
19 #include "image/image.h"
20 #include "params/rs_surface_render_params.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace DrawableV2 {
25     class RSSurfaceRenderNodeDrawable;
26 }
27 
28 /**
29  * @brief Provides ability to draw and cache window content and children
30 */
31 class RSDrawWindowCache {
32 public:
33     RSDrawWindowCache() = default;
34     ~RSDrawWindowCache();
35 
36     /**
37      * @brief Draw and cache window content/children by offscreen buffer and draw back to target canvas
38      *
39      * @param surfaceDrawable Indicates the window to draw
40      * @param canvas Indicates the target canvas to draw the window onto
41      * @param bounds Indicates the bounds of the window rect
42     */
43     void DrawAndCacheWindowContent(DrawableV2::RSSurfaceRenderNodeDrawable* surfaceDrawable,
44         RSPaintFilterCanvas& canvas, const Drawing::Rect& bounds);
45 
46     /**
47      * @brief Draw the cached window onto target canvas
48      *
49      * @param surfaceDrawable Indicates the window to draw
50      * @param canvas Indicates the target canvas to draw the window onto
51      * @param surfaceParams Indicates the render params
52      * @return true if success, otherwise false
53     */
54     bool DealWithCachedWindow(DrawableV2::RSSurfaceRenderNodeDrawable* surfaceDrawable,
55         RSPaintFilterCanvas& canvas, RSSurfaceRenderParams& surfaceParams);
56 
57     void ClearCache();
58 private:
59     bool HasCache() const;
60 
61     std::shared_ptr<Drawing::Image> image_ = nullptr;
62 };
63 } // Rosen
64 } // OHOS
65 
66 #endif // RS_DRAW_WINDOW_CACHE_H