| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#pragma once |
| 18 |
|
| 19 |
#include <private/hwui/WebViewFunctor.h> |
| 20 |
#ifdef __ANDROID__ |
| 21 |
#include <renderthread/RenderProxy.h> |
| 22 |
#endif |
| 23 |
|
| 24 |
#include <utils/LightRefBase.h> |
| 25 |
#include <utils/Log.h> |
| 26 |
#include <utils/StrongPointer.h> |
| 27 |
#include <mutex> |
| 28 |
#include <vector> |
| 29 |
|
| 30 |
namespace android::uirenderer { |
| 31 |
|
| 32 |
class WebViewFunctorManager; |
| 33 |
|
| 34 |
class WebViewFunctor { |
| 35 |
public: |
| 36 |
WebViewFunctor(void* data, const WebViewFunctorCallbacks& callbacks, RenderMode functorMode); |
| 37 |
~WebViewFunctor(); |
| 38 |
|
| 39 |
class Handle : public LightRefBase<Handle> { |
| 40 |
public: |
| 41 |
~Handle() { |
| 42 |
#ifdef __ANDROID__ |
| 43 |
renderthread::RenderProxy::destroyFunctor(id()); |
| 44 |
#endif |
| 45 |
} |
| 46 |
|
| 47 |
int id() const { return mReference.id(); } |
| 48 |
|
| 49 |
void sync(const WebViewSyncData& syncData) const { mReference.sync(syncData); } |
| 50 |
|
| 51 |
void drawGl(const DrawGlInfo& drawInfo) const { mReference.drawGl(drawInfo); } |
| 52 |
|
| 53 |
void initVk(const VkFunctorInitParams& params) { mReference.initVk(params); } |
| 54 |
|
| 55 |
void drawVk(const VkFunctorDrawParams& params) { mReference.drawVk(params); } |
| 56 |
|
| 57 |
void postDrawVk() { mReference.postDrawVk(); } |
| 58 |
|
| 59 |
void removeOverlays() { mReference.removeOverlays(); } |
| 60 |
|
| 61 |
void onRemovedFromTree() { mReference.onRemovedFromTree(); } |
| 62 |
|
| 63 |
private: |
| 64 |
friend class WebViewFunctor; |
| 65 |
|
| 66 |
Handle(WebViewFunctor& ref) : mReference(ref) {} |
| 67 |
|
| 68 |
WebViewFunctor& mReference; |
| 69 |
}; |
| 70 |
|
| 71 |
int id() const { return mFunctor; } |
| 72 |
void sync(const WebViewSyncData& syncData) const; |
| 73 |
void drawGl(const DrawGlInfo& drawInfo); |
| 74 |
void initVk(const VkFunctorInitParams& params); |
| 75 |
void drawVk(const VkFunctorDrawParams& params); |
| 76 |
void postDrawVk(); |
| 77 |
void destroyContext(); |
| 78 |
void removeOverlays(); |
| 79 |
void onRemovedFromTree(); |
| 80 |
|
| 81 |
ASurfaceControl* getSurfaceControl(); |
| 82 |
void mergeTransaction(ASurfaceTransaction* transaction); |
| 83 |
|
| 84 |
sp<Handle> createHandle() { |
| 85 |
LOG_ALWAYS_FATAL_IF(mCreatedHandle); |
| 86 |
mCreatedHandle = true; |
| 87 |
return sp<Handle>{new Handle(*this)}; |
| 88 |
} |
| 89 |
|
| 90 |
private: |
| 91 |
bool prepareRootSurfaceControl(); |
| 92 |
void reparentSurfaceControl(ASurfaceControl* parent); |
| 93 |
|
| 94 |
private: |
| 95 |
WebViewFunctorCallbacks mCallbacks; |
| 96 |
void* const mData; |
| 97 |
int mFunctor; |
| 98 |
RenderMode mMode; |
| 99 |
bool mHasContext = false; |
| 100 |
bool mCreatedHandle = false; |
| 101 |
int32_t mParentSurfaceControlGenerationId = 0; |
| 102 |
ASurfaceControl* mSurfaceControl = nullptr; |
| 103 |
}; |
| 104 |
|
| 105 |
class WebViewFunctorManager { |
| 106 |
public: |
| 107 |
static WebViewFunctorManager& instance(); |
| 108 |
|
| 109 |
int createFunctor(void* data, const WebViewFunctorCallbacks& callbacks, RenderMode functorMode); |
| 110 |
void releaseFunctor(int functor); |
| 111 |
void onContextDestroyed(); |
| 112 |
void destroyFunctor(int functor); |
| 113 |
|
| 114 |
sp<WebViewFunctor::Handle> handleFor(int functor); |
| 115 |
|
| 116 |
private: |
| 117 |
WebViewFunctorManager() = default; |
| 118 |
~WebViewFunctorManager() = default; |
| 119 |
|
| 120 |
std::mutex mLock; |
| 121 |
std::vector<std::unique_ptr<WebViewFunctor>> mFunctors; |
| 122 |
std::vector<sp<WebViewFunctor::Handle>> mActiveFunctors; |
| 123 |
}; |
| 124 |
|
| 125 |
} |