1 /*
2 * Copyright (c) 2024 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 "render/rs_pixel_map_shader.h"
17
18 #include "render/rs_pixel_map_util.h"
19 #include "transaction/rs_marshalling_helper.h"
20
21 namespace OHOS {
22 namespace Rosen {
RSPixelMapShader(std::shared_ptr<Media::PixelMap> pixelMap,Drawing::TileMode tileX,Drawing::TileMode tileY,const Drawing::SamplingOptions & sampling,const Drawing::Matrix & matrix)23 RSPixelMapShader::RSPixelMapShader(
24 std::shared_ptr<Media::PixelMap> pixelMap, Drawing::TileMode tileX, Drawing::TileMode tileY,
25 const Drawing::SamplingOptions& sampling, const Drawing::Matrix& matrix)
26 : pixelMap_(pixelMap), tileX_(tileX), tileY_(tileY), sampling_(sampling), matrix_(matrix) {}
27
28 #ifdef ROSEN_OHOS
Marshalling(Parcel & parcel)29 bool RSPixelMapShader::Marshalling(Parcel& parcel)
30 {
31 return RSMarshallingHelper::Marshalling(parcel, pixelMap_) &&
32 RSMarshallingHelper::Marshalling(parcel, tileX_) &&
33 RSMarshallingHelper::Marshalling(parcel, tileY_) &&
34 RSMarshallingHelper::Marshalling(parcel, sampling_) &&
35 RSMarshallingHelper::Marshalling(parcel, matrix_);
36 }
37
Unmarshalling(Parcel & parcel)38 bool RSPixelMapShader::Unmarshalling(Parcel& parcel)
39 {
40 return RSMarshallingHelper::Unmarshalling(parcel, pixelMap_) &&
41 RSMarshallingHelper::Unmarshalling(parcel, tileX_) &&
42 RSMarshallingHelper::Unmarshalling(parcel, tileY_) &&
43 RSMarshallingHelper::Unmarshalling(parcel, sampling_) &&
44 RSMarshallingHelper::Unmarshalling(parcel, matrix_);
45 }
46 #endif
47
GenerateBaseObject()48 void* RSPixelMapShader::GenerateBaseObject()
49 {
50 #ifdef ROSEN_OHOS
51 if (pixelMap_) {
52 pixelMap_->ReMap();
53 }
54 #endif
55 std::shared_ptr<Drawing::Image> image = RSPixelMapUtil::ExtractDrawingImage(pixelMap_);
56 if (!image) {
57 return nullptr;
58 }
59 // Be Careful: the Object Ptr should be managed by Caller.
60 return new Drawing::ShaderEffect(
61 Drawing::ShaderEffect::ShaderEffectType::IMAGE, *image, tileX_, tileY_, sampling_, matrix_);
62 }
63 } // namespace Rosen
64 } // namespace OHOS