1 /* 2 * Copyright (c) 2021 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 ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CLIENT_H 17 #define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CLIENT_H 18 19 #include <functional> 20 #include <map> 21 #include <memory> 22 #include <mutex> 23 #include <refbase.h> 24 #include <surface.h> 25 26 #include "ipc_callbacks/buffer_available_callback.h" 27 #include "ipc_callbacks/iapplication_render_thread.h" 28 #include "ipc_callbacks/screen_change_callback.h" 29 #include "ipc_callbacks/surface_capture_callback.h" 30 #include "platform/drawing/rs_surface.h" 31 #include "rs_irender_client.h" 32 #include "screen_manager/rs_screen_capability.h" 33 #include "screen_manager/rs_screen_data.h" 34 #include "screen_manager/rs_screen_mode_info.h" 35 #include "screen_manager/screen_types.h" 36 #include "vsync_receiver.h" 37 38 namespace OHOS { 39 namespace Rosen { 40 // normal callback functor for client users. 41 using ScreenChangeCallback = std::function<void(ScreenId, ScreenEvent)>; 42 using BufferAvailableCallback = std::function<void(bool)>; 43 class SurfaceCaptureCallback { 44 public: SurfaceCaptureCallback()45 SurfaceCaptureCallback() {} ~SurfaceCaptureCallback()46 virtual ~SurfaceCaptureCallback() {} 47 virtual void OnSurfaceCapture(std::shared_ptr<Media::PixelMap> pixelmap) = 0; 48 }; 49 50 class RSRenderServiceClient : public RSIRenderClient { 51 public: 52 RSRenderServiceClient() = default; 53 virtual ~RSRenderServiceClient() = default; 54 55 RSRenderServiceClient(const RSRenderServiceClient&) = delete; 56 void operator=(const RSRenderServiceClient&) = delete; 57 58 void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override; 59 void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override; 60 61 std::shared_ptr<RSSurface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config); 62 63 std::shared_ptr<VSyncReceiver> CreateVSyncReceiver( 64 const std::string& name, 65 const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr); 66 67 bool TakeSurfaceCapture(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX, float scaleY); 68 69 ScreenId GetDefaultScreenId(); 70 71 ScreenId CreateVirtualScreen(const std::string& name, uint32_t width, uint32_t height, sptr<Surface> surface, 72 ScreenId mirrorId, int32_t flags); 73 74 int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface); 75 76 void RemoveVirtualScreen(ScreenId id); 77 78 int32_t SetScreenChangeCallback(const ScreenChangeCallback& callback); 79 80 void SetScreenActiveMode(ScreenId id, uint32_t modeId); 81 82 void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status); 83 84 RSScreenModeInfo GetScreenActiveMode(ScreenId id); 85 86 std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id); 87 88 RSScreenCapability GetScreenCapability(ScreenId id); 89 90 ScreenPowerStatus GetScreenPowerStatus(ScreenId id); 91 92 RSScreenData GetScreenData(ScreenId id); 93 94 int32_t GetScreenBacklight(ScreenId id); 95 96 void SetScreenBacklight(ScreenId id, uint32_t level); 97 98 bool RegisterBufferAvailableListener(NodeId id, const BufferAvailableCallback &callback); 99 100 int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode); 101 102 int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode); 103 104 int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx); 105 106 int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode); 107 108 int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode); 109 110 bool RequestRotation(ScreenId id, ScreenRotation rotation); 111 112 ScreenRotation GetRotation(ScreenId id); 113 114 private: 115 void TriggerSurfaceCaptureCallback(NodeId id, Media::PixelMap* pixelmap); 116 std::mutex mutex_; 117 std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbMap_; 118 sptr<RSIScreenChangeCallback> screenChangeCb_; 119 sptr<RSISurfaceCaptureCallback> surfaceCaptureCbDirector_; 120 std::map<NodeId, std::shared_ptr<SurfaceCaptureCallback>> surfaceCaptureCbMap_; 121 122 friend class SurfaceCaptureCallbackDirector; 123 }; 124 } // namespace Rosen 125 } // namespace OHOS 126 127 #endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CLIENT_H 128