• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef RENDER_SERVICE_CLIENT_CORE_RENDER_RS_IMAGE_BASE_H
17 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_IMAGE_BASE_H
18 
19 #include <cstdint>
20 #include <mutex>
21 #include "common/rs_macros.h"
22 #include "common/rs_rect.h"
23 #ifndef USE_ROSEN_DRAWING
24 #include "include/core/SkCanvas.h"
25 #else
26 #include <memory>
27 #include "draw/canvas.h"
28 #endif
29 #include "memory/rs_dfx_string.h"
30 #include "pipeline/rs_paint_filter_canvas.h"
31 #include "transaction/rs_marshalling_helper.h"
32 
33 namespace OHOS {
34 namespace Media {
35 class PixelMap;
36 }
37 namespace Rosen {
38 class RSB_EXPORT RSImageBase {
39 public:
40     RSImageBase() = default;
41     virtual ~RSImageBase();
42 
43 #ifndef USE_ROSEN_DRAWING
44     virtual void DrawImage(RSPaintFilterCanvas& canvas, const SkSamplingOptions& samplingOptions, const SkPaint& paint);
45     void SetImage(const sk_sp<SkImage> image);
46 #if defined(ROSEN_OHOS) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
47     void SetDmaImage(const sk_sp<SkImage> image);
48 #endif
49 #else
50     virtual void DrawImage(Drawing::Canvas& canvas, const Drawing::SamplingOptions& samplingOptions);
51     void SetImage(const std::shared_ptr<Drawing::Image> image);
52 #if defined(ROSEN_OHOS) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
53     void SetDmaImage(const std::shared_ptr<Drawing::Image> image);
54 #endif
55 #endif
56     void SetPixelMap(const std::shared_ptr<Media::PixelMap>& pixelMap);
57     void SetSrcRect(const RectF& dstRect);
58     void SetDstRect(const RectF& dstRect);
59     void SetImagePixelAddr(void* addr);
60     void UpdateNodeIdToPicture(NodeId nodeId);
61     void MarkRenderServiceImage();
62     std::shared_ptr<Media::PixelMap> GetPixelMap() const;
63     void DumpPicture(DfxString& info) const;
64 #ifdef ROSEN_OHOS
65     virtual bool Marshalling(Parcel& parcel) const;
66     [[nodiscard]] static RSImageBase* Unmarshalling(Parcel& parcel);
67 #endif
68 
69 #ifndef USE_ROSEN_DRAWING
70     void ConvertPixelMapToSkImage(bool parallelUpload = false);
71 #else
72     void ConvertPixelMapToDrawingImage(bool parallelUpload = false);
73 #endif
74 
75 protected:
76     void GenUniqueId(uint32_t id);
77 #ifndef USE_ROSEN_DRAWING
78     static bool UnmarshallingSkImageAndPixelMap(Parcel& parcel, uint64_t uniqueId, bool& useSkImage,
79         sk_sp<SkImage>& img, std::shared_ptr<Media::PixelMap>& pixelMap, void*& imagepixelAddr);
80 #else
81     static bool UnmarshallingDrawingImageAndPixelMap(Parcel& parcel, uint64_t uniqueId, bool& useDrawingImage,
82         std::shared_ptr<Drawing::Image>& img, std::shared_ptr<Media::PixelMap>& pixelMap, void*& imagepixelAddr);
83 #endif
84     static void IncreaseCacheRefCount(uint64_t uniqueId,
85             bool useSkImage = true, std::shared_ptr<Media::PixelMap> pixelMap = nullptr);
86 
87     mutable std::mutex mutex_;
88 #ifndef USE_ROSEN_DRAWING
89     sk_sp<SkImage> image_;
90 #else
91     std::shared_ptr<Drawing::Image> image_;
92 #endif
93     void* imagePixelAddr_ = nullptr;
94     std::shared_ptr<Media::PixelMap> pixelMap_;
95 
96     RectF srcRect_;
97     RectF dstRect_;
98 #ifndef USE_ROSEN_DRAWING
99     SkRect src_;
100     SkRect dst_;
101     SkRect lastRect_;
102 #else
103     Drawing::Rect src_;
104     Drawing::Rect dst_;
105     Drawing::Rect lastRect_;
106 #endif
107     bool isDrawn_ = false;
108     uint64_t uniqueId_ = 0;
109     bool renderServiceImage_ = false;
110 };
111 } // namespace Rosen
112 } // namespace OHOS
113 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_IMAGE_BASE_H
114