• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "transaction/rs_render_service_client.h"
17 
18 #include "backend/rs_surface_ohos_gl.h"
19 #include "backend/rs_surface_ohos_raster.h"
20 #include "command/rs_command.h"
21 #include "ipc_callbacks/screen_change_callback_stub.h"
22 #include "ipc_callbacks/surface_capture_callback_stub.h"
23 #include "ipc_callbacks/buffer_available_callback_stub.h"
24 #include "ipc_callbacks/rs_occlusion_change_callback_stub.h"
25 #include "ipc_callbacks/rs_render_mode_change_callback_stub.h"
26 #include "platform/common/rs_log.h"
27 #include "rs_render_service_connect_hub.h"
28 #include "rs_surface_ohos.h"
29 
30 namespace OHOS {
31 namespace Rosen {
CreateRenderServiceClient()32 std::shared_ptr<RSIRenderClient> RSIRenderClient::CreateRenderServiceClient()
33 {
34     static std::shared_ptr<RSIRenderClient> client = std::make_shared<RSRenderServiceClient>();
35     return client;
36 }
37 
CommitTransaction(std::unique_ptr<RSTransactionData> & transactionData)38 void RSRenderServiceClient::CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData)
39 {
40     auto renderService = RSRenderServiceConnectHub::GetRenderService();
41     if (renderService != nullptr) {
42         renderService->CommitTransaction(transactionData);
43     }
44 }
45 
ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask> & task)46 void RSRenderServiceClient::ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task)
47 {
48     auto renderService = RSRenderServiceConnectHub::GetRenderService();
49     if (renderService != nullptr) {
50         renderService->ExecuteSynchronousTask(task);
51     }
52 }
53 
54 class CustomRenderModeChangeCallback : public RSRenderModeChangeCallbackStub {
55 public:
CustomRenderModeChangeCallback(const RenderModeChangeCallback & callback)56     explicit CustomRenderModeChangeCallback(const RenderModeChangeCallback& callback) : cb_(callback) {}
~CustomRenderModeChangeCallback()57     ~CustomRenderModeChangeCallback() override {};
58 
OnRenderModeChanged(bool isUniRender)59     void OnRenderModeChanged(bool isUniRender) override
60     {
61         if (cb_ != nullptr) {
62             cb_(isUniRender);
63         }
64     }
65 
66 private:
67     RenderModeChangeCallback cb_;
68 };
69 
SetRenderModeChangeCallback(const RenderModeChangeCallback & callback)70 int32_t RSRenderServiceClient::SetRenderModeChangeCallback(const RenderModeChangeCallback& callback)
71 {
72     auto renderService = RSRenderServiceConnectHub::GetRenderService();
73     if (renderService == nullptr) {
74         return RENDER_SERVICE_NULL;
75     }
76 
77     renderModeChangeCb_ = new CustomRenderModeChangeCallback(callback);
78     return renderService->SetRenderModeChangeCallback(renderModeChangeCb_);
79 }
80 
UpdateRenderMode(bool isUniRender)81 void RSRenderServiceClient::UpdateRenderMode(bool isUniRender)
82 {
83     auto renderService = RSRenderServiceConnectHub::GetRenderService();
84     if (renderService != nullptr) {
85         renderService->UpdateRenderMode(isUniRender);
86     }
87 }
88 
GetUniRenderEnabled()89 bool RSRenderServiceClient::GetUniRenderEnabled()
90 {
91     auto renderService = RSRenderServiceConnectHub::GetRenderService();
92     if (renderService == nullptr) {
93         return false;
94     }
95     return renderService->GetUniRenderEnabled();
96 }
97 
QueryIfRTNeedRender()98 bool RSRenderServiceClient::QueryIfRTNeedRender()
99 {
100     auto renderService = RSRenderServiceConnectHub::GetRenderService();
101     if (renderService == nullptr) {
102         return false;
103     }
104     return renderService->QueryIfRTNeedRender();
105 }
106 
CreateNode(const RSSurfaceRenderNodeConfig & config)107 bool RSRenderServiceClient::CreateNode(const RSSurfaceRenderNodeConfig& config)
108 {
109     auto renderService = RSRenderServiceConnectHub::GetRenderService();
110     if (renderService == nullptr) {
111         return false;
112     }
113     return renderService->CreateNode(config);
114 }
115 
CreateNodeAndSurface(const RSSurfaceRenderNodeConfig & config)116 std::shared_ptr<RSSurface> RSRenderServiceClient::CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config)
117 {
118     auto renderService = RSRenderServiceConnectHub::GetRenderService();
119     if (renderService == nullptr) {
120         return nullptr;
121     }
122     sptr<Surface> surface = renderService->CreateNodeAndSurface(config);
123     return CreateRSSurface(surface);
124 }
125 
CreateRSSurface(const sptr<Surface> & surface)126 std::shared_ptr<RSSurface> RSRenderServiceClient::CreateRSSurface(const sptr<Surface> &surface)
127 {
128 #ifdef ACE_ENABLE_GL
129     // GPU render
130     std::shared_ptr<RSSurface> producer = std::make_shared<RSSurfaceOhosGl>(surface);
131 #else
132     // CPU render
133     std::shared_ptr<RSSurface> producer = std::make_shared<RSSurfaceOhosRaster>(surface);
134 #endif
135     return producer;
136 }
137 
CreateVSyncReceiver(const std::string & name,const std::shared_ptr<OHOS::AppExecFwk::EventHandler> & looper)138 std::shared_ptr<VSyncReceiver> RSRenderServiceClient::CreateVSyncReceiver(
139     const std::string& name,
140     const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper)
141 {
142     auto renderService = RSRenderServiceConnectHub::GetRenderService();
143     if (renderService == nullptr) {
144         return nullptr;
145     }
146     sptr<IVSyncConnection> conn = renderService->CreateVSyncConnection(name);
147     return std::make_shared<VSyncReceiver>(conn, looper, name);
148 }
149 
TriggerSurfaceCaptureCallback(NodeId id,Media::PixelMap * pixelmap)150 void RSRenderServiceClient::TriggerSurfaceCaptureCallback(NodeId id, Media::PixelMap* pixelmap)
151 {
152     ROSEN_LOGI("RSRenderServiceClient::Into TriggerSurfaceCaptureCallback nodeId:[%" PRIu64 "]", id);
153     std::shared_ptr<Media::PixelMap> surfaceCapture(pixelmap);
154     std::shared_ptr<SurfaceCaptureCallback> callback = nullptr;
155     {
156         std::lock_guard<std::mutex> lock(mutex_);
157         auto iter = surfaceCaptureCbMap_.find(id);
158         if (iter != surfaceCaptureCbMap_.end()) {
159             callback = iter->second;
160             surfaceCaptureCbMap_.erase(iter);
161         }
162     }
163     if (callback == nullptr) {
164         ROSEN_LOGE("RSRenderServiceClient::TriggerSurfaceCaptureCallback: callback is nullptr!");
165         return;
166     }
167     callback->OnSurfaceCapture(surfaceCapture);
168 }
169 
170 class SurfaceCaptureCallbackDirector : public RSSurfaceCaptureCallbackStub
171 {
172 public:
SurfaceCaptureCallbackDirector(RSRenderServiceClient * client)173     explicit SurfaceCaptureCallbackDirector(RSRenderServiceClient* client) : client_(client) {}
~SurfaceCaptureCallbackDirector()174     ~SurfaceCaptureCallbackDirector() override {};
OnSurfaceCapture(NodeId id,Media::PixelMap * pixelmap)175     void OnSurfaceCapture(NodeId id, Media::PixelMap* pixelmap) override
176     {
177         client_->TriggerSurfaceCaptureCallback(id, pixelmap);
178     };
179 
180 private:
181     RSRenderServiceClient* client_;
182 };
183 
TakeSurfaceCapture(NodeId id,std::shared_ptr<SurfaceCaptureCallback> callback,float scaleX,float scaleY)184 bool RSRenderServiceClient::TakeSurfaceCapture(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback,
185     float scaleX, float scaleY)
186 {
187     auto renderService = RSRenderServiceConnectHub::GetRenderService();
188     if (renderService == nullptr) {
189         ROSEN_LOGE("RSRenderServiceClient::TakeSurfaceCapture renderService == nullptr!");
190         return false;
191     }
192     if (callback == nullptr) {
193         ROSEN_LOGE("RSRenderServiceClient::TakeSurfaceCapture callback == nullptr!");
194         return false;
195     }
196     {
197         std::lock_guard<std::mutex> lock(mutex_);
198         if (surfaceCaptureCbMap_.count(id) != 0) {
199             ROSEN_LOGW("RSRenderServiceClient::TakeSurfaceCapture surfaceCaptureCbMap_.count(id) != 0");
200             return false;
201         }
202         surfaceCaptureCbMap_.emplace(id, callback);
203     }
204 
205     if (surfaceCaptureCbDirector_ == nullptr) {
206         surfaceCaptureCbDirector_ = new SurfaceCaptureCallbackDirector(this);
207     }
208     renderService->TakeSurfaceCapture(id, surfaceCaptureCbDirector_, scaleX, scaleY);
209     return true;
210 }
211 
SetFocusAppInfo(int32_t pid,int32_t uid,const std::string & bundleName,const std::string & abilityName)212 int32_t RSRenderServiceClient::SetFocusAppInfo(
213     int32_t pid, int32_t uid, const std::string &bundleName, const std::string &abilityName)
214 {
215     auto renderService = RSRenderServiceConnectHub::GetRenderService();
216     if (renderService == nullptr) {
217         return RENDER_SERVICE_NULL;
218     }
219 
220     return renderService->SetFocusAppInfo(pid, uid, bundleName, abilityName);
221 }
222 
GetDefaultScreenId()223 ScreenId RSRenderServiceClient::GetDefaultScreenId()
224 {
225     auto renderService = RSRenderServiceConnectHub::GetRenderService();
226     if (renderService == nullptr) {
227         return INVALID_SCREEN_ID;
228     }
229 
230     return renderService->GetDefaultScreenId();
231 }
232 
GetAllScreenIds()233 std::vector<ScreenId> RSRenderServiceClient::GetAllScreenIds()
234 {
235     auto renderService = RSRenderServiceConnectHub::GetRenderService();
236     if (renderService == nullptr) {
237         return std::vector<ScreenId>();
238     }
239 
240     return renderService->GetAllScreenIds();
241 }
242 
CreateVirtualScreen(const std::string & name,uint32_t width,uint32_t height,sptr<Surface> surface,ScreenId mirrorId,int32_t flags)243 ScreenId RSRenderServiceClient::CreateVirtualScreen(
244     const std::string &name,
245     uint32_t width,
246     uint32_t height,
247     sptr<Surface> surface,
248     ScreenId mirrorId,
249     int32_t flags)
250 {
251     auto renderService = RSRenderServiceConnectHub::GetRenderService();
252     if (renderService == nullptr) {
253         return INVALID_SCREEN_ID;
254     }
255 
256     return renderService->CreateVirtualScreen(name, width, height, surface, mirrorId, flags);
257 }
258 
SetVirtualScreenSurface(ScreenId id,sptr<Surface> surface)259 int32_t RSRenderServiceClient::SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface)
260 {
261     auto renderService = RSRenderServiceConnectHub::GetRenderService();
262     if (renderService == nullptr) {
263         return RENDER_SERVICE_NULL;
264     }
265 
266     return renderService->SetVirtualScreenSurface(id, surface);
267 }
268 
RemoveVirtualScreen(ScreenId id)269 void RSRenderServiceClient::RemoveVirtualScreen(ScreenId id)
270 {
271     auto renderService = RSRenderServiceConnectHub::GetRenderService();
272     if (renderService == nullptr) {
273         return;
274     }
275 
276     renderService->RemoveVirtualScreen(id);
277 }
278 
279 class CustomScreenChangeCallback : public RSScreenChangeCallbackStub
280 {
281 public:
CustomScreenChangeCallback(const ScreenChangeCallback & callback)282     explicit CustomScreenChangeCallback(const ScreenChangeCallback &callback) : cb_(callback) {}
~CustomScreenChangeCallback()283     ~CustomScreenChangeCallback() override {};
284 
OnScreenChanged(ScreenId id,ScreenEvent event)285     void OnScreenChanged(ScreenId id, ScreenEvent event) override
286     {
287         if (cb_ != nullptr) {
288             cb_(id, event);
289         }
290     }
291 
292 private:
293     ScreenChangeCallback cb_;
294 };
295 
SetScreenChangeCallback(const ScreenChangeCallback & callback)296 int32_t RSRenderServiceClient::SetScreenChangeCallback(const ScreenChangeCallback &callback)
297 {
298     auto renderService = RSRenderServiceConnectHub::GetRenderService();
299     if (renderService == nullptr) {
300         return RENDER_SERVICE_NULL;
301     }
302 
303     screenChangeCb_ = new CustomScreenChangeCallback(callback);
304     return renderService->SetScreenChangeCallback(screenChangeCb_);
305 }
306 
SetScreenActiveMode(ScreenId id,uint32_t modeId)307 void RSRenderServiceClient::SetScreenActiveMode(ScreenId id, uint32_t modeId)
308 {
309     auto renderService = RSRenderServiceConnectHub::GetRenderService();
310     if (renderService == nullptr) {
311         return;
312     }
313 
314     renderService->SetScreenActiveMode(id, modeId);
315 }
316 
SetVirtualScreenResolution(ScreenId id,uint32_t width,uint32_t height)317 int32_t RSRenderServiceClient::SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height)
318 {
319     auto renderService = RSRenderServiceConnectHub::GetRenderService();
320     if (renderService == nullptr) {
321         ROSEN_LOGE("RSRenderServiceClient::SetVirtualScreenResolution renderService == nullptr!");
322         return RENDER_SERVICE_NULL;
323     }
324 
325     return renderService->SetVirtualScreenResolution(id, width, height);
326 }
327 
GetVirtualScreenResolution(ScreenId id)328 RSVirtualScreenResolution RSRenderServiceClient::GetVirtualScreenResolution(ScreenId id)
329 {
330     auto renderService = RSRenderServiceConnectHub::GetRenderService();
331     if (renderService == nullptr) {
332         return RSVirtualScreenResolution {}; // return empty RSVirtualScreenResolution.
333     }
334 
335     return renderService->GetVirtualScreenResolution(id);
336 }
337 
SetScreenPowerStatus(ScreenId id,ScreenPowerStatus status)338 void RSRenderServiceClient::SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status)
339 {
340     auto renderService = RSRenderServiceConnectHub::GetRenderService();
341     if (renderService == nullptr) {
342         return;
343     }
344 
345     renderService->SetScreenPowerStatus(id, status);
346 }
347 
GetScreenActiveMode(ScreenId id)348 RSScreenModeInfo RSRenderServiceClient::GetScreenActiveMode(ScreenId id)
349 {
350     auto renderService = RSRenderServiceConnectHub::GetRenderService();
351     if (renderService == nullptr) {
352         return RSScreenModeInfo {}; // return empty RSScreenModeInfo.
353     }
354 
355     return renderService->GetScreenActiveMode(id);
356 }
357 
GetScreenSupportedModes(ScreenId id)358 std::vector<RSScreenModeInfo> RSRenderServiceClient::GetScreenSupportedModes(ScreenId id)
359 {
360     auto renderService = RSRenderServiceConnectHub::GetRenderService();
361     if (renderService == nullptr) {
362         return {};
363     }
364 
365     return renderService->GetScreenSupportedModes(id);
366 }
367 
GetScreenCapability(ScreenId id)368 RSScreenCapability RSRenderServiceClient::GetScreenCapability(ScreenId id)
369 {
370     auto renderService = RSRenderServiceConnectHub::GetRenderService();
371     if (renderService == nullptr) {
372         return RSScreenCapability {};
373     }
374 
375     return renderService->GetScreenCapability(id);
376 }
377 
GetScreenPowerStatus(ScreenId id)378 ScreenPowerStatus RSRenderServiceClient::GetScreenPowerStatus(ScreenId id)
379 {
380     auto renderService = RSRenderServiceConnectHub::GetRenderService();
381     if (renderService == nullptr) {
382         return ScreenPowerStatus::INVALID_POWER_STATUS;
383     }
384 
385     return renderService->GetScreenPowerStatus(id);
386 }
387 
GetScreenData(ScreenId id)388 RSScreenData RSRenderServiceClient::GetScreenData(ScreenId id)
389 {
390     auto renderService = RSRenderServiceConnectHub::GetRenderService();
391     if (renderService == nullptr) {
392         return RSScreenData {};
393     }
394 
395     return renderService->GetScreenData(id);
396 }
397 
GetScreenBacklight(ScreenId id)398 int32_t RSRenderServiceClient::GetScreenBacklight(ScreenId id)
399 {
400     auto renderService = RSRenderServiceConnectHub::GetRenderService();
401     if (renderService == nullptr) {
402         return INVALID_BACKLIGHT_VALUE;
403     }
404 
405     return renderService->GetScreenBacklight(id);
406 }
407 
SetScreenBacklight(ScreenId id,uint32_t level)408 void RSRenderServiceClient::SetScreenBacklight(ScreenId id, uint32_t level)
409 {
410     auto renderService = RSRenderServiceConnectHub::GetRenderService();
411     if (renderService == nullptr) {
412         return;
413     }
414 
415     renderService->SetScreenBacklight(id, level);
416 }
417 
418 class CustomBufferAvailableCallback : public RSBufferAvailableCallbackStub
419 {
420 public:
CustomBufferAvailableCallback(const BufferAvailableCallback & callback)421     explicit CustomBufferAvailableCallback(const BufferAvailableCallback &callback) : cb_(callback) {}
~CustomBufferAvailableCallback()422     ~CustomBufferAvailableCallback() override {};
423 
OnBufferAvailable()424     void OnBufferAvailable() override
425     {
426         if (cb_ != nullptr) {
427             cb_();
428         }
429     }
430 
431 private:
432     BufferAvailableCallback cb_;
433 };
434 
RegisterBufferAvailableListener(NodeId id,const BufferAvailableCallback & callback,bool isFromRenderThread)435 bool RSRenderServiceClient::RegisterBufferAvailableListener(
436     NodeId id, const BufferAvailableCallback &callback, bool isFromRenderThread)
437 {
438     auto renderService = RSRenderServiceConnectHub::GetRenderService();
439     if (renderService == nullptr) {
440         return false;
441     }
442 
443     auto iter = isFromRenderThread ? bufferAvailableCbRTMap_.find(id) : bufferAvailableCbUIMap_.find(id);
444     if (isFromRenderThread && iter != bufferAvailableCbRTMap_.end()) {
445         ROSEN_LOGW("RSRenderServiceClient::RegisterBufferAvailableListener "
446                    "Node %" PRIu64 " already, bufferAvailableCbRTMap_", iter->first);
447     }
448 
449     if (!isFromRenderThread && iter != bufferAvailableCbUIMap_.end()) {
450         ROSEN_LOGW("RSRenderServiceClient::RegisterBufferAvailableListener "
451                    "Node %" PRIu64 " already, bufferAvailableCbUIMap_", iter->first);
452     }
453 
454     sptr<RSIBufferAvailableCallback> bufferAvailableCb = new CustomBufferAvailableCallback(callback);
455     renderService->RegisterBufferAvailableListener(id, bufferAvailableCb, isFromRenderThread);
456     if (isFromRenderThread) {
457         bufferAvailableCbRTMap_.emplace(id, bufferAvailableCb);
458     } else {
459         bufferAvailableCbUIMap_.emplace(id, bufferAvailableCb);
460     }
461     return true;
462 }
463 
UnregisterBufferAvailableListener(NodeId id)464 bool RSRenderServiceClient::UnregisterBufferAvailableListener(NodeId id)
465 {
466     auto iter = bufferAvailableCbRTMap_.find(id);
467     if (iter != bufferAvailableCbRTMap_.end()) {
468         bufferAvailableCbRTMap_.erase(iter);
469     } else {
470         ROSEN_LOGD("RSRenderServiceClient::UnregisterBufferAvailableListener "
471                    "Node %" PRIu64 " has not registered RT callback",
472             id);
473     }
474     iter = bufferAvailableCbUIMap_.find(id);
475     if (iter != bufferAvailableCbUIMap_.end()) {
476         bufferAvailableCbUIMap_.erase(iter);
477     } else {
478         ROSEN_LOGD("RSRenderServiceClient::UnregisterBufferAvailableListener "
479                    "Node %" PRIu64 " has not registered UI callback",
480             id);
481     }
482     return true;
483 }
484 
GetScreenSupportedColorGamuts(ScreenId id,std::vector<ScreenColorGamut> & mode)485 int32_t RSRenderServiceClient::GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode)
486 {
487     auto renderService = RSRenderServiceConnectHub::GetRenderService();
488     if (renderService == nullptr) {
489         return RENDER_SERVICE_NULL;
490     }
491     return renderService->GetScreenSupportedColorGamuts(id, mode);
492 }
493 
GetScreenSupportedMetaDataKeys(ScreenId id,std::vector<ScreenHDRMetadataKey> & keys)494 int32_t RSRenderServiceClient::GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys)
495 {
496     auto renderService = RSRenderServiceConnectHub::GetRenderService();
497     if (renderService == nullptr) {
498         ROSEN_LOGE("RSRenderServiceClient::RequestRotation renderService == nullptr!");
499         return RENDER_SERVICE_NULL;
500     }
501     return renderService->GetScreenSupportedMetaDataKeys(id, keys);
502 }
503 
GetScreenColorGamut(ScreenId id,ScreenColorGamut & mode)504 int32_t RSRenderServiceClient::GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode)
505 {
506     auto renderService = RSRenderServiceConnectHub::GetRenderService();
507     if (renderService == nullptr) {
508         return RENDER_SERVICE_NULL;
509     }
510     return renderService->GetScreenColorGamut(id, mode);
511 }
512 
SetScreenColorGamut(ScreenId id,int32_t modeIdx)513 int32_t RSRenderServiceClient::SetScreenColorGamut(ScreenId id, int32_t modeIdx)
514 {
515     auto renderService = RSRenderServiceConnectHub::GetRenderService();
516     if (renderService == nullptr) {
517         return RENDER_SERVICE_NULL;
518     }
519     return renderService->SetScreenColorGamut(id, modeIdx);
520 }
521 
SetScreenGamutMap(ScreenId id,ScreenGamutMap mode)522 int32_t RSRenderServiceClient::SetScreenGamutMap(ScreenId id, ScreenGamutMap mode)
523 {
524     auto renderService = RSRenderServiceConnectHub::GetRenderService();
525     if (renderService == nullptr) {
526         return RENDER_SERVICE_NULL;
527     }
528     return renderService->SetScreenGamutMap(id, mode);
529 }
530 
GetScreenGamutMap(ScreenId id,ScreenGamutMap & mode)531 int32_t RSRenderServiceClient::GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode)
532 {
533     auto renderService = RSRenderServiceConnectHub::GetRenderService();
534     if (renderService == nullptr) {
535         return RENDER_SERVICE_NULL;
536     }
537     return renderService->GetScreenGamutMap(id, mode);
538 }
539 
GetScreenHDRCapability(ScreenId id,RSScreenHDRCapability & screenHdrCapability)540 int32_t RSRenderServiceClient::GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability)
541 {
542     auto renderService = RSRenderServiceConnectHub::GetRenderService();
543     if (renderService == nullptr) {
544         ROSEN_LOGE("RSRenderServiceClient::GetScreenHDRCapability renderService == nullptr!");
545         return RENDER_SERVICE_NULL;
546     }
547     return renderService->GetScreenHDRCapability(id, screenHdrCapability);
548 }
549 
GetScreenType(ScreenId id,RSScreenType & screenType)550 int32_t RSRenderServiceClient::GetScreenType(ScreenId id, RSScreenType& screenType)
551 {
552     auto renderService = RSRenderServiceConnectHub::GetRenderService();
553     if (renderService == nullptr) {
554         ROSEN_LOGE("RSRenderServiceClient::GetScreenType renderService == nullptr!");
555         return RENDER_SERVICE_NULL;
556     }
557     return renderService->GetScreenType(id, screenType);
558 }
559 
SetScreenSkipFrameInterval(ScreenId id,uint32_t skipFrameInterval)560 int32_t RSRenderServiceClient::SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval)
561 {
562     auto renderService = RSRenderServiceConnectHub::GetRenderService();
563     if (renderService == nullptr) {
564         return RENDER_SERVICE_NULL;
565     }
566     return renderService->SetScreenSkipFrameInterval(id, skipFrameInterval);
567 }
568 
569 class CustomOcclusionChangeCallback : public RSOcclusionChangeCallbackStub
570 {
571 public:
CustomOcclusionChangeCallback(const OcclusionChangeCallback & callback)572     explicit CustomOcclusionChangeCallback(const OcclusionChangeCallback &callback) : cb_(callback) {}
~CustomOcclusionChangeCallback()573     ~CustomOcclusionChangeCallback() override {};
574 
OnOcclusionVisibleChanged(std::shared_ptr<RSOcclusionData> occlusionData)575     void OnOcclusionVisibleChanged(std::shared_ptr<RSOcclusionData> occlusionData) override
576     {
577         if (cb_ != nullptr) {
578             cb_(occlusionData);
579         }
580     }
581 
582 private:
583     OcclusionChangeCallback cb_;
584 };
585 
RegisterOcclusionChangeCallback(const OcclusionChangeCallback & callback)586 int32_t RSRenderServiceClient::RegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback)
587 {
588     auto renderService = RSRenderServiceConnectHub::GetRenderService();
589     if (renderService == nullptr) {
590         ROSEN_LOGE("RSRenderServiceClient::RegisterOcclusionChangeCallback renderService == nullptr!");
591         return RENDER_SERVICE_NULL;
592     }
593     sptr<CustomOcclusionChangeCallback> cb = new CustomOcclusionChangeCallback(callback);
594     return renderService->RegisterOcclusionChangeCallback(cb);
595 }
596 
UnRegisterOcclusionChangeCallback(const OcclusionChangeCallback & callback)597 int32_t RSRenderServiceClient::UnRegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback)
598 {
599     auto renderService = RSRenderServiceConnectHub::GetRenderService();
600     if (renderService == nullptr) {
601         ROSEN_LOGE("RSRenderServiceClient::UnRegisterOcclusionChangeCallback renderService == nullptr!");
602         return RENDER_SERVICE_NULL;
603     }
604     sptr<CustomOcclusionChangeCallback> cb = new CustomOcclusionChangeCallback(callback);
605     return renderService->UnRegisterOcclusionChangeCallback(cb);
606 }
607 
SetAppWindowNum(uint32_t num)608 void RSRenderServiceClient::SetAppWindowNum(uint32_t num)
609 {
610     auto renderService = RSRenderServiceConnectHub::GetRenderService();
611     if (renderService != nullptr) {
612         renderService->SetAppWindowNum(num);
613     }
614 }
615 } // namespace Rosen
616 } // namespace OHOS
617