• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_ADAPTER_ROSEN_RENDER_SURFACE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_ADAPTER_ROSEN_RENDER_SURFACE_H
18 
19 #if !defined(LINUX_PLATFORM) && !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
20 #include "surface.h"
21 #include "surface_delegate.h"
22 #include "window.h"
23 #endif
24 
25 #include "base/memory/referenced.h"
26 #include "base/utils/noncopyable.h"
27 #include "core/components_ng/render/ext_surface_callback_interface.h"
28 #include "core/components_ng/render/render_surface.h"
29 
30 namespace OHOS::Ace::NG {
31 class RosenRenderSurface : public RenderSurface {
32     DECLARE_ACE_TYPE(RosenRenderSurface, NG::RenderSurface)
33 public:
34     RosenRenderSurface() = default;
35     ~RosenRenderSurface() override;
36 
37     void InitSurface() override;
38 
39     void UpdateXComponentConfig() override;
40 
41     void* GetNativeWindow() override;
42 
43     void SetRenderContext(const RefPtr<RenderContext>& renderContext) override;
44 
45     void ConfigSurface(uint32_t surfaceWidth, uint32_t surfaceHeight) override;
46 
47     bool IsSurfaceValid() const override;
48 
49     void CreateNativeWindow() override;
50 
51     void AdjustNativeWindowSize(uint32_t width, uint32_t height) override;
52 
53     std::string GetUniqueId() const override;
54 
55 #if !defined(LINUX_PLATFORM) && !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
GetSurface()56     OHOS::sptr<OHOS::Surface> GetSurface() const
57     {
58         return producerSurface_;
59     }
60 #endif
61 
62     void SetExtSurfaceBounds(int32_t left, int32_t top, int32_t width, int32_t height) override;
63 
64     void SetExtSurfaceCallback(const RefPtr<ExtSurfaceCallbackInterface>& extSurfaceCallback) override;
65 
66 private:
67 #if !defined(LINUX_PLATFORM) && !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
68     OHOS::sptr<OHOS::Surface> producerSurface_ = nullptr;
69     struct NativeWindow* nativeWindow_ = nullptr;
70 #endif
71     WeakPtr<NG::RenderContext> renderContext_ = nullptr;
72     RefPtr<ExtSurfaceCallbackInterface> extSurfaceCallbackInterface_ = nullptr;
73 #if !defined(LINUX_PLATFORM) && !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
74     sptr<OHOS::SurfaceDelegate> surfaceDelegate_;
75 #endif
76 
77     ACE_DISALLOW_COPY_AND_MOVE(RosenRenderSurface);
78 };
79 
80 #ifdef OHOS_PLATFORM
81 class ExtSurfaceCallback : public OHOS::SurfaceDelegate::ISurfaceCallback {
82 public:
ExtSurfaceCallback(const WeakPtr<ExtSurfaceCallbackInterface> & interface)83     explicit ExtSurfaceCallback(const WeakPtr<ExtSurfaceCallbackInterface>& interface) : weakInterface_(interface) {}
84 
85     ~ExtSurfaceCallback() override = default;
86 
87     void OnSurfaceCreated(const sptr<Surface>& surface) override;
88 
89     void OnSurfaceChanged(const sptr<Surface>& surface, int32_t width, int32_t height) override;
90 
91     void OnSurfaceDestroyed() override;
92 
93 private:
94     WeakPtr<ExtSurfaceCallbackInterface> weakInterface_;
95 };
96 #endif
97 } // namespace OHOS::Ace::NG
98 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_ADAPTER_ROSEN_RENDER_SURFACE_H
99