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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_SKIA_CANVAS_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_SKIA_CANVAS_H 18 19 #include "core/components_ng/render/canvas.h" 20 21 class SkCanvas; 22 23 namespace OHOS::Ace::NG { 24 25 // Canvas is interface for drawing content. 26 class SkiaCanvas : public Canvas { DECLARE_ACE_TYPE(NG::SkiaCanvas,NG::Canvas)27 DECLARE_ACE_TYPE(NG::SkiaCanvas, NG::Canvas) 28 29 public: 30 explicit SkiaCanvas(SkCanvas* canvas) : rawCanvas_(canvas) {} 31 ~SkiaCanvas() override = default; 32 33 // save and restore interfaces 34 void Save() override; 35 void Restore() override; 36 37 // transform interfaces 38 void Translate(float dx, float dy) override; 39 void Scale(float sx, float sy) override; 40 void Rotate(float rad) override; 41 void Skew(float sx, float sy) override; 42 void SetMatrix(const Matrix3& matrix) override; 43 void ConcatMatrix(const Matrix3& matrix) override; 44 45 // clip interfaces 46 void ClipRect(const RectF& rect, ClipQuality quality) override; 47 void ClipRRect(const RRect& rRect, ClipQuality quality) override; 48 void ClipWithPath(const ClipPath& path, ClipQuality quality) override; 49 50 // drawing interfaces 51 void ClearColor(const Color& color) override; 52 void DrawColor(const Color& color) override; 53 void DrawLine(const PointF& start, const PointF& end, const RefPtr<Paint>& paint) override; 54 void DrawRect(const RectF& rect, const RefPtr<Paint>& paint) override; 55 void DrawRRect(const RRect& rect, const RefPtr<Paint>& paint) override; 56 void DrawCircle(float centerX, float centerY, float radius, const RefPtr<Paint>& paint) override; 57 58 void DrawImage(const RefPtr<CanvasImage>& image, const RectF& srcRect, const RectF& dstRect, 59 const RefPtr<Paint>& paint) override; 60 RawCanvas()61 SkCanvas* RawCanvas() 62 { 63 return rawCanvas_; 64 } 65 66 private: 67 SkCanvas* rawCanvas_ = nullptr; 68 }; 69 70 } // namespace OHOS::Ace::NG 71 72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_SKIA_CANVAS_H 73