From 9df1a35604a3afdf4f6d94be6c6242bf8834b31e Mon Sep 17 00:00:00 2001 From: "zhangjie345@huawei.com" Date: Thu, 27 Jan 2022 10:51:33 +0800 Subject: [PATCH] lib2d_graphic csec Signed-off-by: zhangjie345@huawei.com Change-Id: Ie27386e0b017f60f58433ee6f55d2b2d56a9e5b6 --- rosen/modules/2d_graphics/include/image/bitmap.h | 10 +++++----- rosen/modules/2d_graphics/include/utils/matrix.h | 2 +- .../2d_graphics/src/engine_adapter/impl_factory.cpp | 1 - .../src/engine_adapter/impl_interface/bitmap_impl.h | 8 ++++---- .../engine_adapter/impl_interface/color_filter_impl.h | 2 +- .../src/engine_adapter/impl_interface/matrix_impl.h | 4 ++-- .../src/engine_adapter/skia_adapter/skia_bitmap.cpp | 8 ++++---- .../src/engine_adapter/skia_adapter/skia_bitmap.h | 8 ++++---- .../src/engine_adapter/skia_adapter/skia_canvas.cpp | 2 +- .../src/engine_adapter/skia_adapter/skia_canvas.h | 2 +- .../engine_adapter/skia_adapter/skia_color_filter.cpp | 2 +- .../engine_adapter/skia_adapter/skia_color_filter.h | 2 +- .../engine_adapter/skia_adapter/skia_color_space.cpp | 2 +- .../src/engine_adapter/skia_adapter/skia_matrix.cpp | 4 ++-- .../src/engine_adapter/skia_adapter/skia_matrix.h | 4 ++-- .../src/engine_adapter/skia_adapter/skia_paint.cpp | 10 +++++----- .../src/engine_adapter/skia_adapter/skia_paint.h | 10 +++++----- rosen/modules/2d_graphics/src/image/bitmap.cpp | 10 +++++----- rosen/modules/2d_graphics/src/utils/matrix.cpp | 2 +- 19 files changed, 46 insertions(+), 47 deletions(-) diff --git a/rosen/modules/2d_graphics/include/image/bitmap.h b/rosen/modules/2d_graphics/include/image/bitmap.h index fbd2f456f5..5dd13ebbae 100644 --- a/rosen/modules/2d_graphics/include/image/bitmap.h +++ b/rosen/modules/2d_graphics/include/image/bitmap.h @@ -35,12 +35,12 @@ public: int GetHeight(); void* GetPixels(); void SetPixels(void* pixel); - void CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height); - void ClearWithColor(const ColorQuad& color); - bool IsValid(); - ColorQuad GetColor(int x, int y); + void CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height) const; + void ClearWithColor(const ColorQuad& color) const; + bool IsValid() const; + ColorQuad GetColor(int x, int y) const; void Free(); - BitmapFormat GetFormat(); + BitmapFormat GetFormat() const; template const std::shared_ptr GetImpl() const { diff --git a/rosen/modules/2d_graphics/include/utils/matrix.h b/rosen/modules/2d_graphics/include/utils/matrix.h index 04faed45fa..2bf3584f12 100644 --- a/rosen/modules/2d_graphics/include/utils/matrix.h +++ b/rosen/modules/2d_graphics/include/utils/matrix.h @@ -35,7 +35,7 @@ public: bool operator==(const Matrix& other); void SetMatrix(scalar scaleX, scalar skewX, scalar transX, scalar skewY, scalar scaleY, scalar transY, scalar persp0, scalar persp1, scalar persp2); - scalar Get(int index); + scalar Get(int index) const; template const std::shared_ptr GetImpl() const { diff --git a/rosen/modules/2d_graphics/src/engine_adapter/impl_factory.cpp b/rosen/modules/2d_graphics/src/engine_adapter/impl_factory.cpp index cc78c85353..3ecad1ef1b 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/impl_factory.cpp +++ b/rosen/modules/2d_graphics/src/engine_adapter/impl_factory.cpp @@ -20,7 +20,6 @@ namespace OHOS { namespace Rosen { namespace Drawing { - using EngineImplFactory = SkiaImplFactory; std::unique_ptr ImplFactory::CreateCoreCanvasImpl() diff --git a/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/bitmap_impl.h b/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/bitmap_impl.h index 2d40256dc2..b1e28adff1 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/bitmap_impl.h +++ b/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/bitmap_impl.h @@ -39,11 +39,11 @@ public: virtual int GetHeight() = 0; virtual void* GetPixels() = 0; virtual void SetPixels(void* pixel) = 0; - virtual void CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height) = 0; - virtual void ClearWithColor(const ColorQuad& color) = 0; - virtual ColorQuad GetColor(int x, int y) = 0; + virtual void CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height) const = 0; + virtual void ClearWithColor(const ColorQuad& color) const = 0; + virtual ColorQuad GetColor(int x, int y) const = 0; virtual void Free() = 0; - virtual bool IsValid() = 0; + virtual bool IsValid() const = 0; }; } // namespace Drawing } // namespace Rosen diff --git a/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/color_filter_impl.h b/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/color_filter_impl.h index 9c0c017125..64d9131050 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/color_filter_impl.h +++ b/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/color_filter_impl.h @@ -37,7 +37,7 @@ public: } virtual void InitWithBlendMode(ColorQuad c, BlendMode mode) = 0; - virtual void InitWithColorMatrix(ColorMatrix& m) = 0; + virtual void InitWithColorMatrix(const ColorMatrix& m) = 0; virtual void InitWithLinearToSrgbGamma() = 0; virtual void InitWithSrgbGammaToLinear() = 0; virtual void InitWithCompose(const ColorFilter& f1, const ColorFilter& f2) = 0; diff --git a/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/matrix_impl.h b/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/matrix_impl.h index 9b440da669..cbeebba3aa 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/matrix_impl.h +++ b/rosen/modules/2d_graphics/src/engine_adapter/impl_interface/matrix_impl.h @@ -38,10 +38,10 @@ public: virtual void Translate(scalar dx, scalar dy) = 0; virtual void Scale(scalar sx, scalar sy, scalar px, scalar py) = 0; virtual void Multiply(const Matrix& a, const Matrix& b) = 0; - virtual bool Equals(const Matrix& a, const Matrix& b) = 0; + virtual bool Equals(const Matrix& a, const Matrix& b) const = 0; virtual void SetMatrix(scalar scaleX, scalar skewX, scalar transX, scalar skewY, scalar scaleY, scalar transY, scalar persp0, scalar persp1, scalar persp2) = 0; - virtual scalar Get(int index) = 0; + virtual scalar Get(int index) const = 0; }; } // namespace Drawing } // namespace Rosen diff --git a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_bitmap.cpp b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_bitmap.cpp index de407dc92b..37b991815f 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_bitmap.cpp +++ b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_bitmap.cpp @@ -99,7 +99,7 @@ const SkBitmap& SkiaBitmap::ExportSkiaBitmap() const return skiaBitmap_; } -void SkiaBitmap::CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height) +void SkiaBitmap::CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height) const { int w = dst.GetWidth(); int h = dst.GetHeight(); @@ -114,13 +114,13 @@ void SkiaBitmap::CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int skiaBitmap_.readPixels(imageInfo, dstPixels, dstRowBytes, srcX, srcY); } -void SkiaBitmap::ClearWithColor(const ColorQuad& color) +void SkiaBitmap::ClearWithColor(const ColorQuad& color) const { SkColor skColor = static_cast(color); skiaBitmap_.eraseColor(skColor); } -ColorQuad SkiaBitmap::GetColor(int x, int y) +ColorQuad SkiaBitmap::GetColor(int x, int y) const { SkColor color; color = skiaBitmap_.getColor(x, y); @@ -132,7 +132,7 @@ void SkiaBitmap::Free() skiaBitmap_.reset(); } -bool SkiaBitmap::IsValid() +bool SkiaBitmap::IsValid() const { return skiaBitmap_.drawsNothing(); } diff --git a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_bitmap.h b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_bitmap.h index 24d238b0ac..aa8f681556 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_bitmap.h +++ b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_bitmap.h @@ -39,11 +39,11 @@ public: void* GetPixels() override; void SetPixels(void* pixels) override; const SkBitmap& ExportSkiaBitmap() const; - void CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height) override; - void ClearWithColor(const ColorQuad& color) override; - ColorQuad GetColor(int x, int y) override; + void CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height) const override; + void ClearWithColor(const ColorQuad& color) const override; + ColorQuad GetColor(int x, int y) const override; void Free() override; - bool IsValid() override; + bool IsValid() const override; private: SkBitmap skiaBitmap_; diff --git a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_canvas.cpp b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_canvas.cpp index 1a9c9a68a5..717d4b0f7d 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_canvas.cpp +++ b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_canvas.cpp @@ -442,7 +442,7 @@ void SkiaCanvas::DetachBrush() skiaPaint_.DisableFill(); } -void SkiaCanvas::RoundRectCastToSkRRect(const RoundRect& roundRect, SkRRect& skRRect) +void SkiaCanvas::RoundRectCastToSkRRect(const RoundRect& roundRect, SkRRect& skRRect) const { Rect rect = roundRect.GetRect(); SkRect outer = SkRect::MakeLTRB(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom()); diff --git a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_canvas.h b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_canvas.h index a9a47139c3..5f2b0f555f 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_canvas.h +++ b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_canvas.h @@ -103,7 +103,7 @@ public: const std::shared_ptr ExportSkiaCanvas() const; private: - void RoundRectCastToSkRRect(const RoundRect& roundRect, SkRRect& skRRect); + void RoundRectCastToSkRRect(const RoundRect& roundRect, SkRRect& skRRect) const; std::shared_ptr skiaCanvas_; SkiaPaint skiaPaint_; }; diff --git a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_filter.cpp b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_filter.cpp index 50222c968f..49f6228674 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_filter.cpp +++ b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_filter.cpp @@ -27,7 +27,7 @@ void SkiaColorFilter::InitWithBlendMode(ColorQuad c, BlendMode mode) filter_ = SkColorFilters::Blend(static_cast(c), static_cast(mode)); } -void SkiaColorFilter::InitWithColorMatrix(ColorMatrix& m) +void SkiaColorFilter::InitWithColorMatrix(const ColorMatrix& m) { scalar dst[20]; m.GetArray(dst); diff --git a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_filter.h b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_filter.h index ecfe15cb88..aa424bd19e 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_filter.h +++ b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_filter.h @@ -34,7 +34,7 @@ public: } void InitWithBlendMode(ColorQuad c, BlendMode mode) override; - void InitWithColorMatrix(ColorMatrix& m) override; + void InitWithColorMatrix(const ColorMatrix& m) override; void InitWithLinearToSrgbGamma() override; void InitWithSrgbGammaToLinear() override; void InitWithCompose(const ColorFilter& f1, const ColorFilter& f2) override; diff --git a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_space.cpp b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_space.cpp index 866c2f969c..b71798bd5a 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_space.cpp +++ b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_color_space.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace Rosen { namespace Drawing { -SkiaColorSpace::SkiaColorSpace() noexcept : colorSpace_() {} +SkiaColorSpace::SkiaColorSpace() noexcept : colorSpace_(nullptr) {} void SkiaColorSpace::InitWithSRGB() { diff --git a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_matrix.cpp b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_matrix.cpp index de075042d3..f036413b7f 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_matrix.cpp +++ b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_matrix.cpp @@ -51,7 +51,7 @@ void SkiaMatrix::Multiply(const Matrix& a, const Matrix& b) } } -bool SkiaMatrix::Equals(const Matrix& a, const Matrix& b) +bool SkiaMatrix::Equals(const Matrix& a, const Matrix& b) const { auto m1 = a.GetImpl(); auto m2 = b.GetImpl(); @@ -67,7 +67,7 @@ void SkiaMatrix::SetMatrix(scalar scaleX, scalar skewX, scalar transX, scalar sk skMatrix_.setAll(scaleX, skewX, transX, skewY, scaleY, transY, persp0, persp1, persp2); } -scalar SkiaMatrix::Get(int index) +scalar SkiaMatrix::Get(int index) const { return skMatrix_.get(index); } diff --git a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_matrix.h b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_matrix.h index f23aa54082..10baaf56bd 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_matrix.h +++ b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_matrix.h @@ -40,10 +40,10 @@ public: void Scale(scalar sx, scalar sy, scalar px, scalar py) override; const SkMatrix& ExportSkiaMatrix() const; void Multiply(const Matrix& a, const Matrix& b) override; - bool Equals(const Matrix& a, const Matrix& b) override; + bool Equals(const Matrix& a, const Matrix& b) const override; void SetMatrix(scalar scaleX, scalar skewX, scalar transX, scalar skewY, scalar scaleY, scalar transY, scalar persp0, scalar persp1, scalar persp2) override; - scalar Get(int index) override; + scalar Get(int index) const override; private: SkMatrix skMatrix_; diff --git a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_paint.cpp b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_paint.cpp index 5f5cf4e475..7b962cdb39 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_paint.cpp +++ b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_paint.cpp @@ -44,7 +44,7 @@ void SkiaPaint::ApplyPenToStroke(const Pen& pen) PenToSkPaint(pen, stroke_->paint); } -void SkiaPaint::BrushToSkPaint(const Brush& brush, SkPaint& paint) +void SkiaPaint::BrushToSkPaint(const Brush& brush, SkPaint& paint) const { paint.setColor(brush.GetColor().CastToColorQuad()); @@ -72,7 +72,7 @@ void SkiaPaint::BrushToSkPaint(const Brush& brush, SkPaint& paint) paint.setStyle(SkPaint::kFill_Style); } -void SkiaPaint::PenToSkPaint(const Pen& pen, SkPaint& paint) +void SkiaPaint::PenToSkPaint(const Pen& pen, SkPaint& paint) const { paint.setColor(pen.GetColor().CastToColorQuad()); @@ -149,7 +149,7 @@ void SkiaPaint::DisableFill() fill_->isEnabled = false; } -std::vector> SkiaPaint::GetSortedPaints() +std::vector> SkiaPaint::GetSortedPaints() const { std::vector> paints; if (IsStrokeFirst() && stroke_->isEnabled && fill_->isEnabled) { @@ -172,12 +172,12 @@ void SkiaPaint::SetStrokeFirst(bool isStrokeFirst) isStrokeFirst_ = isStrokeFirst; } -bool SkiaPaint::IsStrokeFirst() +bool SkiaPaint::IsStrokeFirst() const { return isStrokeFirst_; } -void SkiaPaint::ApplyFilter(SkPaint& paint, const Filter& filter) +void SkiaPaint::ApplyFilter(SkPaint& paint, const Filter& filter) const { #if !defined(USE_CANVASKIT0310_SKIA) switch (filter.GetFilterQuality()) { diff --git a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_paint.h b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_paint.h index 0ceb5c5ce9..b4ca22877d 100644 --- a/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_paint.h +++ b/rosen/modules/2d_graphics/src/engine_adapter/skia_adapter/skia_paint.h @@ -40,18 +40,18 @@ public: void ApplyBrushToFill(const Brush& brush); void ApplyPenToStroke(const Pen& pen); - void BrushToSkPaint(const Brush& brush, SkPaint& paint); - void PenToSkPaint(const Pen& pen, SkPaint& paint); + void BrushToSkPaint(const Brush& brush, SkPaint& paint) const; + void PenToSkPaint(const Pen& pen, SkPaint& paint) const; void DisableStroke(); void DisableFill(); - std::vector> GetSortedPaints(); + std::vector> GetSortedPaints() const; void SetStrokeFirst(bool isStrokeFirst); - bool IsStrokeFirst(); + bool IsStrokeFirst() const; private: - void ApplyFilter(SkPaint& paint, const Filter& filter); + void ApplyFilter(SkPaint& paint, const Filter& filter) const; std::shared_ptr stroke_; std::shared_ptr fill_; diff --git a/rosen/modules/2d_graphics/src/image/bitmap.cpp b/rosen/modules/2d_graphics/src/image/bitmap.cpp index 2c344f2330..2e46dffcb8 100644 --- a/rosen/modules/2d_graphics/src/image/bitmap.cpp +++ b/rosen/modules/2d_graphics/src/image/bitmap.cpp @@ -59,22 +59,22 @@ void* Bitmap::GetPixels() return pixels_; } -void Bitmap::CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height) +void Bitmap::CopyPixels(Bitmap& dst, int srcLeft, int srcTop, int width, int height) const { bmpImplPtr->CopyPixels(dst, srcLeft, srcTop, width, height); } -void Bitmap::ClearWithColor(const ColorQuad& color) +void Bitmap::ClearWithColor(const ColorQuad& color) const { bmpImplPtr->ClearWithColor(color); } -bool Bitmap::IsValid() +bool Bitmap::IsValid() const { return bmpImplPtr->IsValid(); } -ColorQuad Bitmap::GetColor(int x, int y) +ColorQuad Bitmap::GetColor(int x, int y) const { return bmpImplPtr->GetColor(x, y); } @@ -84,7 +84,7 @@ void Bitmap::Free() bmpImplPtr->Free(); } -BitmapFormat Bitmap::GetFormat() +BitmapFormat Bitmap::GetFormat() const { return format_; } diff --git a/rosen/modules/2d_graphics/src/utils/matrix.cpp b/rosen/modules/2d_graphics/src/utils/matrix.cpp index f908e90202..fd9c281f1e 100644 --- a/rosen/modules/2d_graphics/src/utils/matrix.cpp +++ b/rosen/modules/2d_graphics/src/utils/matrix.cpp @@ -56,7 +56,7 @@ void Matrix::SetMatrix(scalar scaleX, scalar skewX, scalar transX, scalar skewY, matrixImplPtr->SetMatrix(scaleX, skewX, transX, skewY, scaleY, transY, persp0, persp1, persp2); } -scalar Matrix::Get(int index) +scalar Matrix::Get(int index) const { return matrixImplPtr->Get(index); }