1 /* 2 * Copyright (c) 2021 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_H 17 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_IMAGE_H 18 19 #include "common/rs_macros.h" 20 #include "common/rs_rect.h" 21 #include "include/core/SkCanvas.h" 22 #include "include/core/SkColorFilter.h" 23 #include "include/core/SkImage.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 enum class ImageRepeat { 28 NO_REPEAT = 0, 29 REPEAT_X, 30 REPEAT_Y, 31 REPEAT, 32 }; 33 34 enum class ImageFit { 35 FILL, 36 CONTAIN, 37 COVER, 38 FIT_WIDTH, 39 FIT_HEIGHT, 40 NONE, 41 SCALE_DOWN, 42 }; 43 44 class RSImage { 45 public: 46 RSImage() = default; 47 ~RSImage() = default; 48 49 void CanvasDrawImage(SkCanvas& canvas, const SkRect& rect, const SkPaint& paint, bool isBackground = false); 50 void SetImage(const sk_sp<SkImage> image); 51 void SetDstRect(const RectF& dstRect); 52 void SetImageFit(int fitNum); 53 void SetImageRepeat(int repeatNum); 54 void SetRadius(float radius); 55 56 private: 57 void ApplyImageFit(); 58 void ApplyCanvasClip(SkCanvas& canvas); 59 void DrawImageRepeatRect(const SkPaint& paint, SkCanvas& canvas); 60 61 sk_sp<SkImage> image_; 62 ImageFit imageFit_ = ImageFit::COVER; 63 ImageRepeat imageRepeat_ = ImageRepeat::NO_REPEAT; 64 float cornerRadius_ = 0.0; 65 RectF srcRect_; 66 RectF dstRect_; 67 RectF frameRect_; 68 }; 69 } // namespace Rosen 70 } // namespace OHOS 71 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_IMAGE_H 72