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_BASE_RENDER_RS_PIXEL_MAP_UTIL_H
17 #define RENDER_SERVICE_BASE_RENDER_RS_PIXEL_MAP_UTIL_H
18 
19 #include <memory>
20 
21 #include "common/rs_common_def.h"
22 #include "pixel_map.h"
23 #include "pipeline/rs_paint_filter_canvas.h"
24 #include "include/core/SkRRect.h"
25 
26 #include "draw/canvas.h"
27 #include "image/image.h"
28 #include "image/gpu_context.h"
29 
30 namespace OHOS {
31 namespace Rosen {
32 class RSB_EXPORT RSPixelMapUtil {
33 public:
34     // The generated SkImage already holds the shared_ptr of the source PixelMap,
35     // and the PixelMap should not hold SkImage to avoid circular references.
36     static std::shared_ptr<Drawing::ColorSpace> GetPixelmapColorSpace(
37         const std::shared_ptr<Media::PixelMap>& pixelMap);
38     static std::shared_ptr<Drawing::Image> ExtractDrawingImage(std::shared_ptr<Media::PixelMap> pixelMap);
39     static void TransformDataSetForAstc(std::shared_ptr<Media::PixelMap> pixelMap,
40                                         Drawing::Rect& src, Drawing::Rect& dst, Drawing::Canvas& canvas);
41     static void DrawPixelMap(Drawing::Canvas& canvas, Media::PixelMap& pixelMap,
42                              const Drawing::scalar px, const Drawing::scalar py);
43     static bool IsYUVFormat(std::shared_ptr<Media::PixelMap> pixelMap);
44     static bool IsSupportZeroCopy(std::shared_ptr<Media::PixelMap> pixelMap, const Drawing::SamplingOptions& sampling);
45     static std::shared_ptr<Drawing::Image> ConvertYUVPixelMapToDrawingImage(
46         std::shared_ptr<Drawing::GPUContext> gpuContext, std::shared_ptr<Media::PixelMap> pixelMap);
47 };
48 } // namespace Rosen
49 } // namespace OHOS
50 #endif // RENDER_SERVICE_BASE_RENDER_RS_PIXEL_MAP_UTIL_H
51