• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 SURFACE_CAPTURE_FUTURE_H
17 #define SURFACE_CAPTURE_FUTURE_H
18 
19 #include "future.h"
20 #include "pixel_map.h"
21 #include "transaction/rs_render_service_client.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 class SurfaceCaptureFuture : public SurfaceCaptureCallback, public Future<std::shared_ptr<Media::PixelMap>> {
26     constexpr static HiviewDFX::HiLogLabel TAG = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SurfaceFuture"};
27 public:
28     SurfaceCaptureFuture() = default;
~SurfaceCaptureFuture()29     ~SurfaceCaptureFuture() {};
OnSurfaceCapture(std::shared_ptr<Media::PixelMap> pixelmap)30     void OnSurfaceCapture(std::shared_ptr<Media::PixelMap> pixelmap) override
31     {
32         hdrPixelMap_ = nullptr;
33         FutureCall(pixelmap);
34     }
OnSurfaceCaptureHDR(std::shared_ptr<Media::PixelMap> pixelmap,std::shared_ptr<Media::PixelMap> hdrPixelmap)35     void OnSurfaceCaptureHDR(std::shared_ptr<Media::PixelMap> pixelmap,
36         std::shared_ptr<Media::PixelMap> hdrPixelmap) override
37     {
38         std::unique_lock <std::mutex> lock(mutex_);
39         if (!flag_) {
40             pixelMap_ = pixelmap;
41             hdrPixelMap_ = hdrPixelmap;
42             flag_ = true;
43         }
44         conditionVariable_.notify_one();
45     }
46 
GetHDRResult(long timeOut)47     std::vector<std::shared_ptr<Media::PixelMap>> GetHDRResult(long timeOut)
48     {
49         std::unique_lock <std::mutex> lock(mutex_);
50         if (!conditionVariable_.wait_for(lock, std::chrono::milliseconds(timeOut), [this] { return IsReady(); })) {
51             OHOS::HiviewDFX::HiLog::Error(TAG, "wait for %{public}ld, timeout.", timeOut);
52         }
53         return { pixelMap_, hdrPixelMap_ };
54     }
55 
56 protected:
Call(std::shared_ptr<Media::PixelMap> pixelmap)57     void Call(std::shared_ptr<Media::PixelMap> pixelmap) override
58     {
59         if (!flag_) {
60             pixelMap_ = pixelmap;
61             flag_ = true;
62         }
63     }
IsReady()64     bool IsReady() override
65     {
66         return flag_;
67     }
FetchResult()68     std::shared_ptr<Media::PixelMap> FetchResult() override
69     {
70         return pixelMap_ == nullptr ? hdrPixelMap_ : pixelMap_;
71     }
72 private:
73     bool flag_ = false;
74     std::shared_ptr<Media::PixelMap> pixelMap_ = nullptr;
75     std::shared_ptr<Media::PixelMap> hdrPixelMap_ = nullptr;
76 };
77 } // Rosen
78 } // OHOS
79 #endif  // SURFACE_CAPTURE_FUTURE_H