blob: 635d863c82abde9125472b217a68e952bcf6e73a [file] [log] [blame]
John Reck283bb462018-12-13 16:40:14 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <private/hwui/WebViewFunctor.h>
20#include <renderthread/RenderProxy.h>
John Reck283bb462018-12-13 16:40:14 -080021#include <utils/LightRefBase.h>
John Reck844516c2021-01-13 10:59:10 -050022#include <utils/Log.h>
23#include <utils/StrongPointer.h>
Jerome Gaillard8ab756d2024-04-02 17:38:20 +010024
John Reck283bb462018-12-13 16:40:14 -080025#include <mutex>
26#include <vector>
27
28namespace android::uirenderer {
29
30class WebViewFunctorManager;
31
32class WebViewFunctor {
33public:
Bo Liud6668e72018-12-14 19:37:41 -080034 WebViewFunctor(void* data, const WebViewFunctorCallbacks& callbacks, RenderMode functorMode);
John Reck283bb462018-12-13 16:40:14 -080035 ~WebViewFunctor();
36
37 class Handle : public LightRefBase<Handle> {
38 public:
Jerome Gaillard8ab756d2024-04-02 17:38:20 +010039 ~Handle() { renderthread::RenderProxy::destroyFunctor(id()); }
John Reck283bb462018-12-13 16:40:14 -080040
41 int id() const { return mReference.id(); }
42
43 void sync(const WebViewSyncData& syncData) const { mReference.sync(syncData); }
44
45 void drawGl(const DrawGlInfo& drawInfo) const { mReference.drawGl(drawInfo); }
46
Bo Liu7b8c1eb2019-01-08 20:17:55 -080047 void initVk(const VkFunctorInitParams& params) { mReference.initVk(params); }
48
49 void drawVk(const VkFunctorDrawParams& params) { mReference.drawVk(params); }
50
51 void postDrawVk() { mReference.postDrawVk(); }
52
Vasiliy Telezhnikov6b237642020-11-12 18:14:58 -050053 void removeOverlays() { mReference.removeOverlays(); }
54
Huihong Luoec68b7c2021-06-25 21:54:16 -070055 void onRemovedFromTree() { mReference.onRemovedFromTree(); }
56
Igor Kraskevich2cec1582024-03-13 11:23:40 +000057 const std::vector<int32_t>& getRenderingThreads() const {
58 return mReference.getRenderingThreads();
59 }
60
John Reck283bb462018-12-13 16:40:14 -080061 private:
62 friend class WebViewFunctor;
63
64 Handle(WebViewFunctor& ref) : mReference(ref) {}
65
66 WebViewFunctor& mReference;
67 };
68
69 int id() const { return mFunctor; }
70 void sync(const WebViewSyncData& syncData) const;
71 void drawGl(const DrawGlInfo& drawInfo);
Bo Liu7b8c1eb2019-01-08 20:17:55 -080072 void initVk(const VkFunctorInitParams& params);
73 void drawVk(const VkFunctorDrawParams& params);
74 void postDrawVk();
John Reck283bb462018-12-13 16:40:14 -080075 void destroyContext();
Vasiliy Telezhnikov6b237642020-11-12 18:14:58 -050076 void removeOverlays();
Huihong Luoec68b7c2021-06-25 21:54:16 -070077 void onRemovedFromTree();
Vasiliy Telezhnikov6b237642020-11-12 18:14:58 -050078
79 ASurfaceControl* getSurfaceControl();
80 void mergeTransaction(ASurfaceTransaction* transaction);
John Reck283bb462018-12-13 16:40:14 -080081
Igor Kraskevich63ebd832024-03-12 11:51:35 +000082 void reportRenderingThreads(const int32_t* thread_ids, size_t size);
Igor Kraskevich2cec1582024-03-13 11:23:40 +000083 const std::vector<int32_t>& getRenderingThreads() const { return mRenderingThreads; }
Igor Kraskevich63ebd832024-03-12 11:51:35 +000084
John Reck283bb462018-12-13 16:40:14 -080085 sp<Handle> createHandle() {
86 LOG_ALWAYS_FATAL_IF(mCreatedHandle);
87 mCreatedHandle = true;
88 return sp<Handle>{new Handle(*this)};
89 }
90
91private:
Vasiliy Telezhnikov372a21b2021-11-17 13:50:56 -050092 bool prepareRootSurfaceControl();
Huihong Luo540fdf82021-06-25 13:59:39 -070093 void reparentSurfaceControl(ASurfaceControl* parent);
94
95private:
John Reck283bb462018-12-13 16:40:14 -080096 WebViewFunctorCallbacks mCallbacks;
Bo Liud6668e72018-12-14 19:37:41 -080097 void* const mData;
John Reck283bb462018-12-13 16:40:14 -080098 int mFunctor;
99 RenderMode mMode;
100 bool mHasContext = false;
101 bool mCreatedHandle = false;
Huihong Luo540fdf82021-06-25 13:59:39 -0700102 int32_t mParentSurfaceControlGenerationId = 0;
Huihong Luo054b8d32021-02-24 18:48:12 -0800103 ASurfaceControl* mSurfaceControl = nullptr;
Igor Kraskevich2cec1582024-03-13 11:23:40 +0000104 std::vector<int32_t> mRenderingThreads;
John Reck283bb462018-12-13 16:40:14 -0800105};
106
107class WebViewFunctorManager {
108public:
109 static WebViewFunctorManager& instance();
110
Bo Liud6668e72018-12-14 19:37:41 -0800111 int createFunctor(void* data, const WebViewFunctorCallbacks& callbacks, RenderMode functorMode);
John Reck283bb462018-12-13 16:40:14 -0800112 void releaseFunctor(int functor);
113 void onContextDestroyed();
114 void destroyFunctor(int functor);
Igor Kraskevich63ebd832024-03-12 11:51:35 +0000115 void reportRenderingThreads(int functor, const int32_t* thread_ids, size_t size);
Igor Kraskevich2cec1582024-03-13 11:23:40 +0000116 std::vector<int32_t> getRenderingThreadsForActiveFunctors();
John Reck283bb462018-12-13 16:40:14 -0800117
118 sp<WebViewFunctor::Handle> handleFor(int functor);
119
120private:
121 WebViewFunctorManager() = default;
122 ~WebViewFunctorManager() = default;
123
124 std::mutex mLock;
125 std::vector<std::unique_ptr<WebViewFunctor>> mFunctors;
126 std::vector<sp<WebViewFunctor::Handle>> mActiveFunctors;
127};
128
129} // namespace android::uirenderer