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