1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd.. All rights reserved. 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 CORE_CANVAS_H 17 #define CORE_CANVAS_H 18 19 #include <memory> 20 21 #include "drawing/engine_adapter/impl_interface/core_canvas_impl.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 namespace Drawing { 26 enum class SrcRectConstraint { 27 STRICT_SRC_RECT_CONSTRAINT, 28 FAST_SRC_RECT_CONSTRAINT, 29 }; 30 class CoreCanvas { 31 public: 32 CoreCanvas(); 33 explicit CoreCanvas(void* rawCanvas); ~CoreCanvas()34 virtual ~CoreCanvas() {} 35 void Bind(const Bitmap& bitmap); 36 37 // shapes 38 void DrawPoint(const Point& point); 39 void DrawLine(const Point& startPt, const Point& endPt); 40 void DrawRect(const Rect& rect); 41 void DrawRoundRect(const RoundRect& roundRect); 42 void DrawNestedRoundRect(const RoundRect& outer, const RoundRect& inner); 43 void DrawArc(const Rect& oval, scalar startAngle, scalar sweepAngle); 44 void DrawPie(const Rect& oval, scalar startAngle, scalar sweepAngle); 45 void DrawOval(const Rect& oval); 46 void DrawCircle(const Point& centerPt, scalar radius); 47 void DrawPath(const Path& path); 48 void DrawBackground(const Brush& brush); 49 void DrawShadow(const Path& path, const Point3& planeParams, const Point3& devLightPos, scalar lightRadius, 50 Color ambientColor, Color spotColor, ShadowFlags flag); 51 52 // image 53 void DrawBitmap(const Bitmap& bitmap, const scalar px, const scalar py); 54 void DrawBitmap(Media::PixelMap& pixelMap, const scalar px, const scalar py); 55 void DrawImage(const Image& image, const scalar px, const scalar py, const SamplingOptions& sampling); 56 void DrawImageRect(const Image& image, const Rect& src, const Rect& dst, const SamplingOptions& sampling, 57 SrcRectConstraint constraint = SrcRectConstraint::STRICT_SRC_RECT_CONSTRAINT); 58 void DrawImageRect(const Image& image, const Rect& dst, const SamplingOptions& sampling); 59 void DrawPicture(const Picture& picture); 60 61 // clip 62 void ClipRect(const Rect& rect, ClipOp op); 63 void ClipRoundRect(const RoundRect& roundRect, ClipOp op); 64 void ClipPath(const Path& path, ClipOp op); 65 66 // transform 67 void SetMatrix(const Matrix& matrix); 68 void ResetMatrix(); 69 void ConcatMatrix(const Matrix& matrix); 70 void Translate(scalar dx, scalar dy); 71 void Scale(scalar sx, scalar sy); 72 void Rotate(scalar deg); 73 void Rotate(scalar deg, scalar sx, scalar sy); 74 void Shear(scalar sx, scalar sy); 75 76 // state 77 void Flush(); 78 void Clear(ColorQuad color); 79 void Save(); 80 void SaveLayer(const Rect& rect, const Brush& brush); 81 void Restore(); 82 83 // paint 84 CoreCanvas& AttachPen(const Pen& pen); 85 CoreCanvas& AttachBrush(const Brush& brush); 86 CoreCanvas& DetachPen(); 87 CoreCanvas& DetachBrush(); 88 89 template<typename T> GetImpl()90 const std::shared_ptr<T> GetImpl() const 91 { 92 return impl_->DowncastingTo<T>(); 93 } 94 std::shared_ptr<CoreCanvasImpl> GetCanvasData() const; 95 96 private: 97 std::shared_ptr<CoreCanvasImpl> impl_; 98 }; 99 } // namespace Drawing 100 } // namespace Rosen 101 } // namespace OHOS 102 #endif