/* * Copyright (C) 2024 Amlogic Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef BINDER_SERVER_H #define BINDER_SERVER_H #include #include #include "MesonVideoCompositor.h" using namespace android; typedef struct pairDisplayLayer { int32_t displayId; int32_t layerId; } pairDisplayLayert; class BinderServer : public BBinder { public: BinderServer(); void run(std::shared_ptr server); void setMesonCompositor(std::shared_ptr& c); private: class compositorClient { public: compositorClient(std::shared_ptr cp) : mCp(cp) { } ~compositorClient() { if (mCp.get()) { for (auto it = mInfos.begin(); it != mInfos.end(); it++) mCp->destroyLayer(it->second.displayId, it->second.layerId); } } void addDisplay(int32_t displayId, int32_t layerId) { std::string key = std::to_string(10 * layerId + displayId); pairDisplayLayert info = { .displayId = displayId, .layerId = layerId }; mInfos.emplace(key, info); } void removeDisplay(int32_t displayId, int32_t layerId) { std::string key = std::to_string(10 * layerId + displayId); mInfos.erase(key); } private: std::shared_ptr mCp; std::map mInfos; }; class ServiceDeathRecipient; typedef std::pair, sp> clientInfo; class ServerCallback { public: ServerCallback() { } int registerCallback(const Parcel& data, Parcel* reply); int createLayer(const Parcel& data, Parcel* reply); int destroyLayer(const Parcel& data, Parcel* reply); int setTunnelId(const Parcel& data, Parcel* reply); int setLayerIndex(const Parcel& data, Parcel* reply); int setLayerZorder(const Parcel& data, Parcel* reply); int setSourceCrop(const Parcel& data, Parcel* reply); int setDisplayFrame(const Parcel& data, Parcel* reply); int getDelayLatency(const Parcel& data, Parcel* reply); int setToMainPlane(const Parcel& data, Parcel* reply); int getUiSize(const Parcel& data, Parcel* reply); void setMesonCompositor(std::shared_ptr& c); void removeClient(int clientId); private: std::shared_ptr mMesonCompositor; std::map mClients; std::map> mBinders; }; class ServiceDeathRecipient : public IBinder::DeathRecipient { public: ServiceDeathRecipient(ServerCallback *callbck, int id) : mCb(callbck), mClientId(id) { } virtual void binderDied(const wp& who); private: ServerCallback *mCb; int mClientId; }; virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0); typedef int (ServerCallback::*func)(const Parcel&, Parcel*); private: std::shared_ptr mSCallback; std::map mServerFunc; }; #endif